diff --git a/README.md b/README.md index d5f2476..57d1861 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Carthage ----------------- Add this line to your `Cartfile`: ``` -github "socketio/socket.io-client-swift" ~> 2.4.0 # Or latest version +github "socketio/socket.io-client-swift" ~> 2.4.3 # Or latest version ``` Run `carthage update`. @@ -80,7 +80,7 @@ source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' use_frameworks! -pod 'Socket.IO-Client-Swift', '~> 2.4.0' # Or latest version +pod 'Socket.IO-Client-Swift', '~> 2.4.3' # Or latest version ``` Install pods: diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index 5ff6cbe..ed772a2 100644 --- a/Socket.IO-Client-Swift.podspec +++ b/Socket.IO-Client-Swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Socket.IO-Client-Swift" - s.version = "2.4.0" + s.version = "2.4.3" 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.4.0' } + s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v2.4.3' } s.source_files = "SocketIOClientSwift/**/*.swift" s.requires_arc = true # s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files diff --git a/SocketIOClientSwift/SocketEngine.swift b/SocketIOClientSwift/SocketEngine.swift index dd3b3a9..4e0a5bf 100644 --- a/SocketIOClientSwift/SocketEngine.swift +++ b/SocketIOClientSwift/SocketEngine.swift @@ -387,25 +387,33 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient { private func handleOpen(openData: String) { let mesData = openData.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)! - do { let json = try NSJSONSerialization.JSONObjectWithData(mesData, options: NSJSONReadingOptions.AllowFragments) as? NSDictionary if let sid = json?["sid"] as? String { + let upgradeWs: Bool + self.sid = sid connected = true - - if !forcePolling && !forceWebsockets { - createWebsocket(andConnect: true) + + if let upgrades = json?["upgrades"] as? [String] { + upgradeWs = upgrades.filter {$0 == "websocket"}.count != 0 + } else { + upgradeWs = false } if let pingInterval = json?["pingInterval"] as? Double, pingTimeout = json?["pingTimeout"] as? Double { self.pingInterval = pingInterval / 1000.0 self.pingTimeout = pingTimeout / 1000.0 } + + if !forcePolling && !forceWebsockets && upgradeWs { + createWebsocket(andConnect: true) + } } } catch { SocketLogger.err("Error parsing open packet", client: self) + return } startPingTimer()