diff --git a/README.md b/README.md index 94d0a3c..9114c86 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Carthage ----------------- Add this line to your `Cartfile`: ``` -github "socketio/socket.io-client-swift" ~> 6.1.2 # Or latest version +github "socketio/socket.io-client-swift" ~> 6.1.4 # Or latest version ``` Run `carthage update --platform ios,macosx`. @@ -102,7 +102,7 @@ source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' use_frameworks! -pod 'Socket.IO-Client-Swift', '~> 6.1.2' # Or latest version +pod 'Socket.IO-Client-Swift', '~> 6.1.4' # Or latest version ``` Install pods: @@ -130,7 +130,7 @@ CocoaSeeds Add this line to your `Seedfile`: ``` -github "socketio/socket.io-client-swift", "v6.1.2", :files => "Source/*.swift" # Or latest version +github "socketio/socket.io-client-swift", "v6.1.4", :files => "Source/*.swift" # Or latest version ``` Run `seed install`. diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index ddf7a2d..a694ffa 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 = "SocketIOClientSwift" - s.version = "6.1.2" + s.version = "6.1.4" s.summary = "Socket.IO-client for iOS and OS X" s.description = <<-DESC Socket.IO-client for iOS and OS X. @@ -14,7 +14,7 @@ Pod::Spec.new do |s| s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.10' s.tvos.deployment_target = '9.0' - s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v6.1.2' } + s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v6.1.4' } s.source_files = "Source/**/*.swift" s.requires_arc = true # s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files diff --git a/Source/SocketEngine.swift b/Source/SocketEngine.swift index f0f7b68..5410a0d 100644 --- a/Source/SocketEngine.swift +++ b/Source/SocketEngine.swift @@ -34,11 +34,11 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe (urlPolling, urlWebSocket) = createURLs() } } - + public var postWait = [String]() public var waitingForPoll = false public var waitingForPost = false - + public private(set) var closed = false public private(set) var connected = false public private(set) var cookies: [HTTPCookie]? @@ -59,19 +59,19 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe public private(set) var ws: WebSocket? public weak var client: SocketEngineClient? - + private weak var sessionDelegate: URLSessionDelegate? private let logType = "SocketEngine" private let url: URL - + private var pingInterval: Double? private var pingTimeout = 0.0 { didSet { pongsMissedMax = Int(pingTimeout / (pingInterval ?? 25)) } } - + private var pongsMissed = 0 private var pongsMissedMax = 0 private var probeWait = ProbeWaitQueue() @@ -83,7 +83,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe public init(client: SocketEngineClient, url: URL, options: Set) { self.client = client self.url = url - + for option in options { switch option { case let .connectParams(params): @@ -114,30 +114,30 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe continue } } - + super.init() - + (urlPolling, urlWebSocket) = createURLs() } - + public convenience init(client: SocketEngineClient, url: URL, options: NSDictionary?) { self.init(client: client, url: url, options: options?.toSocketOptionsSet() ?? []) } - + deinit { DefaultSocketLogger.Logger.log("Engine is being released", type: logType) closed = true stopPolling() } - + private func checkAndHandleEngineError(_ msg: String) { guard let stringData = msg.data(using: String.Encoding.utf8, allowLossyConversion: false) else { return } - + do { if let dict = try JSONSerialization.jsonObject(with: stringData, options: .mutableContainers) as? NSDictionary { guard let error = dict["message"] as? String else { return } - + /* 0: Unknown transport 1: Unknown sid @@ -147,7 +147,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe didError(reason: error) } } catch { - didError(reason: "Got unknown error from server \(msg)") + client?.engineDidError(reason: "Got unknown error from server \(msg)") } } @@ -155,59 +155,60 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe if message.hasPrefix("b4") { // binary in base64 string let noPrefix = message[message.characters.index(message.startIndex, offsetBy: 2)..(uncheckedBounds: (1, data.count - 1)))) } public func parseEngineMessage(_ message: String, fromPolling: Bool) { DefaultSocketLogger.Logger.log("Got message: %@", type: logType, args: message) - + let reader = SocketStringReader(message: message) let fixedString: String @@ -425,7 +424,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe if !checkIfMessageIsBase64Binary(message) { checkAndHandleEngineError(message) } - + return } @@ -451,7 +450,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe DefaultSocketLogger.Logger.log("Got unknown packet type", type: logType) } } - + // Puts the engine back in its default state private func resetEngine() { closed = false @@ -473,22 +472,22 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe if !connected { return } - + //Server is not responding if pongsMissed > pongsMissedMax { client?.engineDidClose(reason: "Ping timeout") return } - + if let pingInterval = pingInterval { pongsMissed += 1 write("", withType: .ping, withData: []) - + let time = DispatchTime.now() + Double(Int64(pingInterval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) DispatchQueue.main.after(when: time) {[weak self] in self?.sendPing() } } } - + // Moves from long-polling to websockets private func upgradeTransport() { if ws?.isConnected ?? false { @@ -504,7 +503,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe public func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data]) { emitQueue.async { guard self.connected else { return } - + if self.websocket { DefaultSocketLogger.Logger.log("Writing ws: %@ has data: %@", type: self.logType, args: msg, data.count != 0) @@ -518,7 +517,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe } } } - + // Delegate methods public func websocketDidConnect(_ socket: WebSocket) { if !forceWebsockets { @@ -530,19 +529,19 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe polling = false } } - + public func websocketDidDisconnect(_ socket: WebSocket, error: NSError?) { probing = false - + if closed { client?.engineDidClose(reason: "Disconnect") return } - + if websocket { connected = false websocket = false - + if let reason = error?.localizedDescription { didError(reason: reason) } else {