Skip to content

Commit 17426c1

Browse files
committed
fix #152
1 parent 46cea36 commit 17426c1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

SocketIOClientSwift/SocketEngine.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,17 +414,25 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
414414
if let json = NSJSONSerialization.JSONObjectWithData(mesData,
415415
options: NSJSONReadingOptions.AllowFragments,
416416
error: &err) as? NSDictionary, sid = json["sid"] as? String {
417+
let upgradeWs: Bool
418+
417419
self.sid = sid
418420
_connected = true
419421

420-
if !forcePolling && !forceWebsockets {
421-
createWebsocket(andConnect: true)
422+
if let upgrades = json["upgrades"] as? [String] {
423+
upgradeWs = upgrades.filter {$0 == "websocket"}.count != 0
424+
} else {
425+
upgradeWs = false
422426
}
423427

424428
if let pingInterval = json["pingInterval"] as? Double, pingTimeout = json["pingTimeout"] as? Double {
425429
self.pingInterval = pingInterval / 1000.0
426430
self.pingTimeout = pingTimeout / 1000.0
427431
}
432+
433+
if !forcePolling && !forceWebsockets && upgradeWs {
434+
createWebsocket(andConnect: true)
435+
}
428436
} else {
429437
client?.didError("Engine failed to handshake")
430438
return

0 commit comments

Comments
 (0)