Compare commits

...
10 Commits
Author SHA1 Message Date
Erik 846897157c bump version 2015-07-01 07:07:32 -04:00
Erik a49f8f19cf add extraHeaders option fixes. nuclearace/Socket.IO-Client-Swift#64 2015-07-01 07:05:06 -04:00
Erik 531a9784da make it clear as to what language 2015-06-29 18:13:45 -04:00
Erik c34a660cae update readme 2015-06-29 18:12:46 -04:00
Erik 9484bc9614 update readme 2015-06-29 18:11:33 -04:00
Erik d8f65c2804 bump version 2015-06-24 06:52:24 -04:00
Erik ca3f3e810d fix socketio/socket.io-client-swift#97 2015-06-24 06:51:47 -04:00
Erik 63021eb995 bump version 2015-06-23 21:52:05 -04:00
Erik d8e3408565 set connecting 2015-06-23 18:57:37 -04:00
Erik f17575b35c use computed variable for sid 2015-06-16 05:14:32 -04:00
4 changed files with 40 additions and 14 deletions

No files matched your search

+8 -1
View File
@@ -78,12 +78,18 @@ Install pods:
$ pod install
```
Import in your swift file:
Import the module:
Swift:
```swift
import Socket_IO_Client_Swift
```
Objective-C:
```Objective-C
#import <Socket_IO_Client_Swift/Socket_IO_Client_Swift-Swift.h>
```
##API
Constructors
-----------
@@ -104,6 +110,7 @@ Options
- `log: Bool` If `true` socket will log debug messages. Default is false.
- `sessionDelegate: NSURLSessionDelegate` Sets an NSURLSessionDelegate for the underlying engine. Useful if you need to handle self-signed certs. Default is nil.
- `path: String` - If the server uses a custom path. ex: `"/swift"`. Default is `""`
- `extraHeaders: [String: String]?` - Adds custom headers to the initial request. Default is nil.
Methods
-------
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Socket.IO-Client-Swift"
s.version = "2.3.4"
s.version = "2.3.7"
s.summary = "Socket.IO-client for iOS and OS X"
s.description = <<-DESC
Socket.IO-client for iOS and OS X.
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.author = { "Erik" => "nuclear.ace@gmail.com" }
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10'
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v2.3.4' }
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v2.3.7' }
s.source_files = "SocketIOClientSwift/**/*.swift"
s.requires_arc = true
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files
+28 -8
View File
@@ -37,14 +37,15 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
private var closed = false
private var _connected = false
private var extraHeaders:[String: String]?
private var fastUpgrade = false
private var forcePolling = false
private var forceWebsockets = false
private var pingInterval:Int?
private var pingInterval:Double?
private var pingTimer:NSTimer?
private var pingTimeout = 0 {
private var pingTimeout = 0.0 {
didSet {
pongsMissedMax = pingTimeout / (pingInterval ?? 25)
pongsMissedMax = Int(pingTimeout / (pingInterval ?? 25))
}
}
private var pongsMissed = 0
@@ -109,6 +110,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
cookies = opts?["cookies"] as? [NSHTTPCookie]
log = opts?["log"] as? Bool ?? false
socketPath = opts?["path"] as? String ?? ""
extraHeaders = opts?["extraHeaders"] as? [String: String]
}
deinit {
@@ -194,6 +196,13 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
private func createWebsocket(andConnect connect:Bool) {
ws = WebSocket(url: NSURL(string: urlWebSocket! + "&sid=\(sid)")!,
cookies: cookies)
if extraHeaders != nil {
for (headerName, value) in extraHeaders! {
ws?.headers[headerName] = value
}
}
ws?.queue = handleQueue
ws?.delegate = self
@@ -229,6 +238,12 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
req.allHTTPHeaderFields = headers
}
if extraHeaders != nil {
for (headerName, value) in extraHeaders! {
req.setValue(value, forHTTPHeaderField: headerName)
}
}
doRequest(req)
}
@@ -404,9 +419,9 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
createWebsocket(andConnect: true)
}
if let pingInterval = json["pingInterval"] as? Int, pingTimeout = json["pingTimeout"] as? Int {
self.pingInterval = pingInterval / 1000
self.pingTimeout = pingTimeout / 1000
if let pingInterval = json["pingInterval"] as? Double, pingTimeout = json["pingTimeout"] as? Double {
self.pingInterval = pingInterval / 1000.0
self.pingTimeout = pingTimeout / 1000.0
}
} else {
client?.didError("Engine failed to handshake")
@@ -477,6 +492,12 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
reqPolling.allHTTPHeaderFields = headers
}
if extraHeaders != nil {
for (headerName, value) in extraHeaders! {
reqPolling.setValue(value, forHTTPHeaderField: headerName)
}
}
doRequest(reqPolling)
}
@@ -650,8 +671,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
pingTimer?.invalidate()
dispatch_async(dispatch_get_main_queue()) {[weak self] in
if let this = self {
this.pingTimer = NSTimer.scheduledTimerWithTimeInterval(NSTimeInterval(this.pingInterval!),
target: this,
this.pingTimer = NSTimer.scheduledTimerWithTimeInterval(this.pingInterval!, target: this,
selector: Selector("sendPing"), userInfo: nil, repeats: true)
}
}
+2 -3
View File
@@ -33,7 +33,6 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
private var handlers = ContiguousArray<SocketEventHandler>()
private var connectParams:[String: AnyObject]?
private var _secure = false
private var _sid:String?
private var _reconnecting = false
private var reconnectTimer:NSTimer?
@@ -70,7 +69,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
return _secure
}
public var sid:String? {
return _sid
return engine?.sid
}
/**
@@ -174,6 +173,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
return
}
_connecting = true
addEngine()
engine?.open(opts: connectParams)
@@ -224,7 +224,6 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
currentReconnectAttempt = 0
reconnectTimer?.invalidate()
reconnectTimer = nil
_sid = engine?.sid
// Don't handle as internal because something crazy could happen where
// we disconnect before it's handled