Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
846897157c | ||
|
|
a49f8f19cf | ||
|
|
531a9784da | ||
|
|
c34a660cae | ||
|
|
9484bc9614 | ||
|
|
d8f65c2804 | ||
|
|
ca3f3e810d | ||
|
|
63021eb995 | ||
|
|
d8e3408565 | ||
|
|
f17575b35c |
No files matched your search
@@ -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
|
||||
-------
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user