diff --git a/.travis.yml b/.travis.yml index 91243b7..2f38790 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: objective-c xcode_project: Socket.IO-Client-Swift.xcodeproj # path to your xcodeproj folder xcode_scheme: SocketIO-Mac -osx_image: xcode9.2 +osx_image: xcode10 branches: only: - master diff --git a/CHANGELOG.md b/CHANGELOG.md index 782da41..6e5d99b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v13.3.1 + +- Fixes various bugs. [#857](https://github.com/socketio/socket.io-client-swift/issues/857), [#1078](https://github.com/socketio/socket.io-client-swift/issues/1078) + # v13.3.0 - Copy cookies from polling to WebSockets ([#1057](https://github.com/socketio/socket.io-client-swift/issues/1057), [#1058](https://github.com/socketio/socket.io-client-swift/issues/1058)) diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index 24a9545..4367b39 100644 --- a/Socket.IO-Client-Swift.podspec +++ b/Socket.IO-Client-Swift.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Socket.IO-Client-Swift" s.module_name = "SocketIO" - s.version = "13.3.0" + s.version = "13.3.1" s.summary = "Socket.IO-client for iOS and OS X" s.description = <<-DESC Socket.IO-client for iOS and OS X. @@ -18,7 +18,7 @@ Pod::Spec.new do |s| s.requires_arc = true s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", - :tag => 'v13.3.0', + :tag => 'v13.3.1', :submodules => true } s.pod_target_xcconfig = { diff --git a/Source/SocketIO/Engine/SocketEngine.swift b/Source/SocketIO/Engine/SocketEngine.swift index 738bf30..2ded52a 100644 --- a/Source/SocketIO/Engine/SocketEngine.swift +++ b/Source/SocketIO/Engine/SocketEngine.swift @@ -281,7 +281,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So private func createWebSocketAndConnect() { var req = URLRequest(url: urlWebSocketWithSid) - addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies) + addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies(for: urlPollingWithSid)) ws = WebSocket(request: req) ws?.callbackQueue = engineQueue @@ -546,7 +546,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So pongsMissed += 1 write("", withType: .ping, withData: []) - engineQueue.asyncAfter(deadline: DispatchTime.now() + .milliseconds(pingInterval)) {[weak self, id = self.sid] in + engineQueue.asyncAfter(deadline: .now() + .milliseconds(pingInterval)) {[weak self, id = self.sid] in // Make sure not to ping old connections guard let this = self, this.sid == id else { return } diff --git a/Source/SocketIO/Engine/SocketEnginePollable.swift b/Source/SocketIO/Engine/SocketEnginePollable.swift index faec93a..0e46c3f 100644 --- a/Source/SocketIO/Engine/SocketEnginePollable.swift +++ b/Source/SocketIO/Engine/SocketEnginePollable.swift @@ -122,9 +122,12 @@ extension SocketEnginePollable { doRequest(for: req) {[weak self] data, res, err in guard let this = self, this.polling else { return } - - if err != nil || data == nil { - DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling") + guard let data = data, let res = res as? HTTPURLResponse, res.statusCode == 200 else { + if let err = err { + DefaultSocketLogger.Logger.error(err.localizedDescription, type: "SocketEnginePolling") + } else { + DefaultSocketLogger.Logger.error("Error during long poll request", type: "SocketEnginePolling") + } if this.polling { this.didError(reason: err?.localizedDescription ?? "Error") @@ -135,7 +138,7 @@ extension SocketEnginePollable { DefaultSocketLogger.Logger.log("Got polling response", type: "SocketEnginePolling") - if let str = String(data: data!, encoding: .utf8) { + if let str = String(data: data, encoding: .utf8) { this.parsePollingMessage(str) } @@ -163,11 +166,14 @@ extension SocketEnginePollable { DefaultSocketLogger.Logger.log("POSTing", type: "SocketEnginePolling") - doRequest(for: req) {[weak self] data, res, err in + doRequest(for: req) {[weak self] _, res, err in guard let this = self else { return } - - if err != nil { - DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling") + guard let res = res as? HTTPURLResponse, res.statusCode == 200 else { + if let err = err { + DefaultSocketLogger.Logger.error(err.localizedDescription, type: "SocketEnginePolling") + } else { + DefaultSocketLogger.Logger.error("Error flushing waiting posts", type: "SocketEnginePolling") + } if this.polling { this.didError(reason: err?.localizedDescription ?? "Error") diff --git a/Source/SocketIO/Manager/SocketManager.swift b/Source/SocketIO/Manager/SocketManager.swift index 126aec1..d4407f4 100644 --- a/Source/SocketIO/Manager/SocketManager.swift +++ b/Source/SocketIO/Manager/SocketManager.swift @@ -137,10 +137,6 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa self._config = config self.socketURL = socketURL - if socketURL.absoluteString.hasPrefix("https://") { - self._config.insert(.secure(true)) - } - super.init() setConfigs(_config) @@ -489,12 +485,17 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa DefaultSocketLogger.Logger.log = log case let .logger(logger): DefaultSocketLogger.Logger = logger - default: + case _: continue } } _config = config + + if socketURL.absoluteString.hasPrefix("https://") { + _config.insert(.secure(true)) + } + _config.insert(.path("/socket.io/"), replacing: false) // If `ConfigSettable` & `SocketEngineSpec`, update its configs. diff --git a/Source/SocketIO/Parse/SocketParsable.swift b/Source/SocketIO/Parse/SocketParsable.swift index 1c8b963..d181df4 100644 --- a/Source/SocketIO/Parse/SocketParsable.swift +++ b/Source/SocketIO/Parse/SocketParsable.swift @@ -109,14 +109,11 @@ public extension SocketParsable where Self: SocketManagerSpec & SocketDataBuffer if type == .error { reader.advance(by: -1) } else { - while reader.hasNext { - if let int = Int(reader.read(count: 1)) { - idString += String(int) - } else { - reader.advance(by: -2) - break - } + while let int = Int(reader.read(count: 1)) { + idString += String(int) } + + reader.advance(by: -2) } var dataArray = String(message.utf16[message.utf16.index(reader.currentIndex, offsetBy: 1)...])! diff --git a/Tests/TestSocketIO/SocketMangerTest.swift b/Tests/TestSocketIO/SocketMangerTest.swift index 22da481..37e5dba 100644 --- a/Tests/TestSocketIO/SocketMangerTest.swift +++ b/Tests/TestSocketIO/SocketMangerTest.swift @@ -18,6 +18,16 @@ class SocketMangerTest : XCTestCase { XCTAssertEqual(manager.status, .notConnected) } + func testSettingConfig() { + let manager = SocketManager(socketURL: URL(string: "https://example.com/")!) + + XCTAssertEqual(manager.config.first!, .secure(true)) + + manager.config = [] + + XCTAssertEqual(manager.config.first!, .secure(true)) + } + func testManagerCallsConnect() { setUpSockets()