This commit is contained in:
Erik 2015-08-31 09:22:56 -04:00
parent 46cea36df7
commit 17426c1432

View File

@ -414,17 +414,25 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
if let json = NSJSONSerialization.JSONObjectWithData(mesData, if let json = NSJSONSerialization.JSONObjectWithData(mesData,
options: NSJSONReadingOptions.AllowFragments, options: NSJSONReadingOptions.AllowFragments,
error: &err) as? NSDictionary, sid = json["sid"] as? String { error: &err) as? NSDictionary, sid = json["sid"] as? String {
let upgradeWs: Bool
self.sid = sid self.sid = sid
_connected = true _connected = true
if !forcePolling && !forceWebsockets { if let upgrades = json["upgrades"] as? [String] {
createWebsocket(andConnect: true) upgradeWs = upgrades.filter {$0 == "websocket"}.count != 0
} else {
upgradeWs = false
} }
if let pingInterval = json["pingInterval"] as? Double, pingTimeout = json["pingTimeout"] as? Double { if let pingInterval = json["pingInterval"] as? Double, pingTimeout = json["pingTimeout"] as? Double {
self.pingInterval = pingInterval / 1000.0 self.pingInterval = pingInterval / 1000.0
self.pingTimeout = pingTimeout / 1000.0 self.pingTimeout = pingTimeout / 1000.0
} }
if !forcePolling && !forceWebsockets && upgradeWs {
createWebsocket(andConnect: true)
}
} else { } else {
client?.didError("Engine failed to handshake") client?.didError("Engine failed to handshake")
return return