From bd5c852fb6fa08028bbaefcdada0104b70c8dea4 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Wed, 5 Oct 2016 08:56:22 -0400 Subject: [PATCH 01/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 945c876..13161b2 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{ [socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) { double cur = [[data objectAtIndex:0] floatValue]; - [socket emitWithAck:@"canUpdate" withItems:@[@(cur)]](0, ^(NSArray* data) { + [socket emitWithAck:@"canUpdate" with:@[@(cur)]](0, ^(NSArray* data) { [socket emit:@"update" withItems:@[@{@"amount": @(cur + 2.50)}]]; }); From 3e3ba601653fe5c46f13c5fa35d5eb6cf546f3c1 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Wed, 12 Oct 2016 11:55:44 -0400 Subject: [PATCH 02/11] bump websocket version --- Source/SSLSecurity.swift | 10 ++++------ Source/WebSocket.swift | 22 +++++++++++++++------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Source/SSLSecurity.swift b/Source/SSLSecurity.swift index 00343fb..c2091a5 100644 --- a/Source/SSLSecurity.swift +++ b/Source/SSLSecurity.swift @@ -4,7 +4,7 @@ // Starscream // // Created by Dalton Cherry on 5/16/15. -// Copyright (c) 2014-2015 Dalton Cherry. +// Copyright (c) 2014-2016 Dalton Cherry. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import Foundation import Security -public class SSLCert : NSObject { +open class SSLCert { var certData: Data? var key: SecKey? @@ -50,7 +50,7 @@ public class SSLCert : NSObject { } } -public class SSLSecurity : NSObject { +open class SSLSecurity { public var validatedDN = true //should the domain name be validated? var isReady = false //is the key processing done? @@ -82,7 +82,7 @@ public class SSLSecurity : NSObject { /** Designated init - - parameter keys: is the certificates or public keys to use + - parameter certs: is the certificates or public keys to use - parameter usePublicKeys: is to specific if the publicKeys or certificates should be used for SSL pinning validation - returns: a representation security object to be used with @@ -90,8 +90,6 @@ public class SSLSecurity : NSObject { public init(certs: [SSLCert], usePublicKeys: Bool) { self.usePublicKeys = usePublicKeys - super.init() - if self.usePublicKeys { DispatchQueue.global(qos: .default).async { let pubKeys = certs.reduce([SecKey]()) { (pubKeys: [SecKey], cert: SSLCert) -> [SecKey] in diff --git a/Source/WebSocket.swift b/Source/WebSocket.swift index 95982ae..67420eb 100644 --- a/Source/WebSocket.swift +++ b/Source/WebSocket.swift @@ -3,7 +3,7 @@ // Websocket.swift // // Created by Dalton Cherry on 7/16/14. -// Copyright (c) 2014-2015 Dalton Cherry. +// Copyright (c) 2014-2016 Dalton Cherry. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ public protocol WebSocketPongDelegate: class { func websocketDidReceivePong(socket: WebSocket, data: Data?) } -public class WebSocket : NSObject, StreamDelegate { +open class WebSocket : NSObject, StreamDelegate { enum OpCode : UInt8 { case continueFrame = 0x0 @@ -190,15 +190,19 @@ public class WebSocket : NSObject, StreamDelegate { /** Disconnect from the server. I send a Close control frame to the server, then expect the server to respond with a Close control frame and close the socket from its end. I notify my delegate once the socket has been closed. + If you supply a non-nil `forceTimeout`, I wait at most that long (in seconds) for the server to close the socket. After the timeout expires, I close the socket and notify my delegate. + If you supply a zero (or negative) `forceTimeout`, I immediately close the socket (without sending a Close control frame) and notify my delegate. + - Parameter forceTimeout: Maximum time to wait for the server to close the socket. - Parameter closeCode: The code to send on disconnect. The default is the normal close code for cleanly disconnecting a webSocket. */ public func disconnect(forceTimeout: TimeInterval? = nil, closeCode: UInt16 = CloseCode.normal.rawValue) { switch forceTimeout { case .some(let seconds) where seconds > 0: - callbackQueue.asyncAfter(deadline: DispatchTime.now() + Double(Int64(seconds * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)) { [weak self] in + let milliseconds = Int(seconds * 1_000) + callbackQueue.asyncAfter(deadline: .now() + .milliseconds(milliseconds)) { [weak self] in self?.disconnectStream(nil) } fallthrough @@ -212,8 +216,10 @@ public class WebSocket : NSObject, StreamDelegate { /** Write a string to the websocket. This sends it as a text frame. + If you supply a non-nil completion block, I will perform it when the write completes. - - parameter str: The string to write. + + - parameter string: The string to write. - parameter completion: The (optional) completion handler. */ public func write(string: String, completion: (() -> ())? = nil) { @@ -223,7 +229,9 @@ public class WebSocket : NSObject, StreamDelegate { /** Write binary data to the websocket. This sends it as a binary frame. + If you supply a non-nil completion block, I will perform it when the write completes. + - parameter data: The data to write. - parameter completion: The (optional) completion handler. */ @@ -358,7 +366,7 @@ public class WebSocket : NSObject, StreamDelegate { self.mutex.unlock() let bytes = UnsafeRawPointer((data as NSData).bytes).assumingMemoryBound(to: UInt8.self) - var out = timeout * 1000000 // wait 5 seconds before giving up + var out = timeout * 1_000_000 // wait 5 seconds before giving up writeQueue.addOperation { [weak self] in while !outStream.hasSpaceAvailable { usleep(100) // wait until the socket is ready @@ -380,9 +388,9 @@ public class WebSocket : NSObject, StreamDelegate { */ public func stream(_ aStream: Stream, handle eventCode: Stream.Event) { if let sec = security, !certValidated && [.hasBytesAvailable, .hasSpaceAvailable].contains(eventCode) { - let trust = aStream.property(forKey: kCFStreamPropertySSLPeerTrust as Stream.PropertyKey) as AnyObject + let trust = aStream.property(forKey: kCFStreamPropertySSLPeerTrust as Stream.PropertyKey) as! SecTrust let domain = aStream.property(forKey: kCFStreamSSLPeerName as Stream.PropertyKey) as? String - if sec.isValid(trust as! SecTrust, domain: domain) { + if sec.isValid(trust, domain: domain) { certValidated = true } else { let error = errorWithDetail("Invalid SSL certificate", code: 1) From 0143dc25bfe1231e97e6ed01c40697b7f4f4bf31 Mon Sep 17 00:00:00 2001 From: Jin Sun Date: Tue, 18 Oct 2016 17:29:01 +0800 Subject: [PATCH 03/11] fix Use Legacy Swift issue --- Socket.IO-Client-Swift.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index 726d3ac..f44e315 100644 --- a/Socket.IO-Client-Swift.podspec +++ b/Socket.IO-Client-Swift.podspec @@ -17,5 +17,6 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v8.0.2' } s.source_files = "Source/**/*.swift" s.requires_arc = true + s.pod_target_xcconfig = {'SWIFT_VERSION' => '3.0'} # s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files end From 8042053331f706d0469d295d4a181c2f7f785791 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Thu, 27 Oct 2016 06:37:39 -0400 Subject: [PATCH 04/11] bump websocket version --- README.md | 6 +- Socket.IO-Client-Swift.podspec | 4 +- Source/SSLSecurity.swift | 7 ++- Source/WebSocket.swift | 111 +++++++++++++++------------------ 4 files changed, 60 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 32ff901..cc0e076 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Carthage ----------------- Add this line to your `Cartfile`: ``` -github "socketio/socket.io-client-swift" ~> 8.0.2 # Or latest version +github "socketio/socket.io-client-swift" ~> 8.0.3 # Or latest version ``` Run `carthage update --platform ios,macosx`. @@ -108,7 +108,7 @@ Create `Podfile` and add `pod 'Socket.IO-Client-Swift'`: use_frameworks! target 'YourApp' do - pod 'Socket.IO-Client-Swift', '~> 8.0.2' # Or latest version + pod 'Socket.IO-Client-Swift', '~> 8.0.3' # Or latest version end ``` @@ -137,7 +137,7 @@ CocoaSeeds Add this line to your `Seedfile`: ``` -github "socketio/socket.io-client-swift", "v8.0.2", :files => "Source/*.swift" # Or latest version +github "socketio/socket.io-client-swift", "v8.0.3", :files => "Source/*.swift" # Or latest version ``` Run `seed install`. diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index 726d3ac..01faaa6 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 = "8.0.2" + s.version = "8.0.3" 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 => 'v8.0.2' } + s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v8.0.3' } 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/SSLSecurity.swift b/Source/SSLSecurity.swift index c2091a5..d2a2b78 100644 --- a/Source/SSLSecurity.swift +++ b/Source/SSLSecurity.swift @@ -19,10 +19,13 @@ // limitations under the License. // ////////////////////////////////////////////////////////////////////////////////////////////////// - import Foundation import Security +public protocol SSLTrustValidator { + func isValid(_ trust: SecTrust, domain: String?) -> Bool +} + open class SSLCert { var certData: Data? var key: SecKey? @@ -50,7 +53,7 @@ open class SSLCert { } } -open class SSLSecurity { +open class SSLSecurity : SSLTrustValidator { public var validatedDN = true //should the domain name be validated? var isReady = false //is the key processing done? diff --git a/Source/WebSocket.swift b/Source/WebSocket.swift index 67420eb..108592d 100644 --- a/Source/WebSocket.swift +++ b/Source/WebSocket.swift @@ -18,7 +18,6 @@ // limitations under the License. // ////////////////////////////////////////////////////////////////////////////////////////////////// - import Foundation import CoreFoundation import Security @@ -77,7 +76,6 @@ open class WebSocket : NSObject, StreamDelegate { var optionalProtocols: [String]? // MARK: - Constants - let headerWSUpgradeName = "Upgrade" let headerWSUpgradeValue = "websocket" let headerWSHostName = "Host" @@ -108,7 +106,6 @@ open class WebSocket : NSObject, StreamDelegate { } // MARK: - Delegates - /// Responds to callback about new messages coming in over the WebSocket /// and also connection/disconnect messages. public weak var delegate: WebSocketDelegate? @@ -118,7 +115,6 @@ open class WebSocket : NSObject, StreamDelegate { // MARK: - Block based API. - public var onConnect: ((Void) -> Void)? public var onDisconnect: ((NSError?) -> Void)? public var onText: ((String) -> Void)? @@ -128,7 +124,7 @@ open class WebSocket : NSObject, StreamDelegate { public var headers = [String: String]() public var voipEnabled = false public var disableSSLCertValidation = false - public var security: SSLSecurity? + public var security: SSLTrustValidator? public var enabledSSLCipherSuites: [SSLCipherSuite]? public var origin: String? public var timeout = 5 @@ -139,7 +135,6 @@ open class WebSocket : NSObject, StreamDelegate { public var currentURL: URL { return url } // MARK: - Private - private var url: URL private var inputStream: InputStream? private var outputStream: OutputStream? @@ -190,11 +185,8 @@ open class WebSocket : NSObject, StreamDelegate { /** Disconnect from the server. I send a Close control frame to the server, then expect the server to respond with a Close control frame and close the socket from its end. I notify my delegate once the socket has been closed. - If you supply a non-nil `forceTimeout`, I wait at most that long (in seconds) for the server to close the socket. After the timeout expires, I close the socket and notify my delegate. - If you supply a zero (or negative) `forceTimeout`, I immediately close the socket (without sending a Close control frame) and notify my delegate. - - Parameter forceTimeout: Maximum time to wait for the server to close the socket. - Parameter closeCode: The code to send on disconnect. The default is the normal close code for cleanly disconnecting a webSocket. */ @@ -216,9 +208,7 @@ open class WebSocket : NSObject, StreamDelegate { /** Write a string to the websocket. This sends it as a text frame. - If you supply a non-nil completion block, I will perform it when the write completes. - - parameter string: The string to write. - parameter completion: The (optional) completion handler. */ @@ -229,9 +219,7 @@ open class WebSocket : NSObject, StreamDelegate { /** Write binary data to the websocket. This sends it as a binary frame. - If you supply a non-nil completion block, I will perform it when the write completes. - - parameter data: The data to write. - parameter completion: The (optional) completion handler. */ @@ -313,7 +301,6 @@ open class WebSocket : NSObject, StreamDelegate { private func initStreamsWithData(_ data: Data, _ port: Int) { //higher level API we will cut over to at some point //NSStream.getStreamsToHostWithName(url.host, port: url.port.integerValue, inputStream: &inputStream, outputStream: &outputStream) - var readStream: Unmanaged? var writeStream: Unmanaged? let h = url.host! as NSString @@ -326,6 +313,28 @@ open class WebSocket : NSObject, StreamDelegate { if supportedSSLSchemes.contains(url.scheme!) { inStream.setProperty(StreamSocketSecurityLevel.negotiatedSSL as AnyObject, forKey: Stream.PropertyKey.socketSecurityLevelKey) outStream.setProperty(StreamSocketSecurityLevel.negotiatedSSL as AnyObject, forKey: Stream.PropertyKey.socketSecurityLevelKey) + if disableSSLCertValidation { + let settings: [NSObject: NSObject] = [kCFStreamSSLValidatesCertificateChain: NSNumber(value: false), kCFStreamSSLPeerName: kCFNull] + inStream.setProperty(settings, forKey: kCFStreamPropertySSLSettings as Stream.PropertyKey) + outStream.setProperty(settings, forKey: kCFStreamPropertySSLSettings as Stream.PropertyKey) + } + if let cipherSuites = self.enabledSSLCipherSuites { + if let sslContextIn = CFReadStreamCopyProperty(inputStream, CFStreamPropertyKey(rawValue: kCFStreamPropertySSLContext)) as! SSLContext?, + let sslContextOut = CFWriteStreamCopyProperty(outputStream, CFStreamPropertyKey(rawValue: kCFStreamPropertySSLContext)) as! SSLContext? { + let resIn = SSLSetEnabledCiphers(sslContextIn, cipherSuites, cipherSuites.count) + let resOut = SSLSetEnabledCiphers(sslContextOut, cipherSuites, cipherSuites.count) + if resIn != errSecSuccess { + let error = self.errorWithDetail("Error setting ingoing cypher suites", code: UInt16(resIn)) + disconnectStream(error) + return + } + if resOut != errSecSuccess { + let error = self.errorWithDetail("Error setting outgoing cypher suites", code: UInt16(resOut)) + disconnectStream(error) + return + } + } + } } else { certValidated = true //not a https session, so no need to check SSL pinning } @@ -333,28 +342,6 @@ open class WebSocket : NSObject, StreamDelegate { inStream.setProperty(StreamNetworkServiceTypeValue.voIP as AnyObject, forKey: Stream.PropertyKey.networkServiceType) outStream.setProperty(StreamNetworkServiceTypeValue.voIP as AnyObject, forKey: Stream.PropertyKey.networkServiceType) } - if disableSSLCertValidation { - let settings: [NSObject: NSObject] = [kCFStreamSSLValidatesCertificateChain: NSNumber(value: false), kCFStreamSSLPeerName: kCFNull] - inStream.setProperty(settings, forKey: kCFStreamPropertySSLSettings as Stream.PropertyKey) - outStream.setProperty(settings, forKey: kCFStreamPropertySSLSettings as Stream.PropertyKey) - } - if let cipherSuites = self.enabledSSLCipherSuites { - if let sslContextIn = CFReadStreamCopyProperty(inputStream, CFStreamPropertyKey(rawValue: kCFStreamPropertySSLContext)) as! SSLContext?, - let sslContextOut = CFWriteStreamCopyProperty(outputStream, CFStreamPropertyKey(rawValue: kCFStreamPropertySSLContext)) as! SSLContext? { - let resIn = SSLSetEnabledCiphers(sslContextIn, cipherSuites, cipherSuites.count) - let resOut = SSLSetEnabledCiphers(sslContextOut, cipherSuites, cipherSuites.count) - if resIn != errSecSuccess { - let error = self.errorWithDetail("Error setting ingoing cypher suites", code: UInt16(resIn)) - disconnectStream(error) - return - } - if resOut != errSecSuccess { - let error = self.errorWithDetail("Error setting outgoing cypher suites", code: UInt16(resOut)) - disconnectStream(error) - return - } - } - } CFReadStreamSetDispatchQueue(inStream, WebSocket.sharedWorkQueue) CFWriteStreamSetDispatchQueue(outStream, WebSocket.sharedWorkQueue) @@ -447,7 +434,6 @@ open class WebSocket : NSObject, StreamDelegate { let buf = NSMutableData(capacity: BUFFER_MAX) let buffer = UnsafeMutableRawPointer(mutating: buf!.bytes).assumingMemoryBound(to: UInt8.self) let length = inputStream!.read(buffer, maxLength: BUFFER_MAX) - guard length > 0 else { return } var process = false if inputQueue.count == 0 { @@ -643,34 +629,22 @@ open class WebSocket : NSObject, StreamDelegate { writeError(errCode) return emptyBuffer } + var closeCode = CloseCode.normal.rawValue if receivedOpcode == .connectionClose { - var code = CloseCode.normal.rawValue if payloadLen == 1 { - code = CloseCode.protocolError.rawValue + closeCode = CloseCode.protocolError.rawValue } else if payloadLen > 1 { - code = WebSocket.readUint16(baseAddress, offset: offset) - if code < 1000 || (code > 1003 && code < 1007) || (code > 1011 && code < 3000) { - code = CloseCode.protocolError.rawValue - } - offset += 2 - } - var closeReason = "connection closed by server" - if payloadLen > 2 { - let len = Int(payloadLen - 2) - if len > 0 { - let bytes = baseAddress + offset - if let customCloseReason = String(data: Data(bytes: bytes, count: len), encoding: .utf8) { - closeReason = customCloseReason - } else { - code = CloseCode.protocolError.rawValue - } + closeCode = WebSocket.readUint16(baseAddress, offset: offset) + if closeCode < 1000 || (closeCode > 1003 && closeCode < 1007) || (closeCode > 1011 && closeCode < 3000) { + closeCode = CloseCode.protocolError.rawValue } } - doDisconnect(errorWithDetail(closeReason, code: code)) - writeError(code) - return emptyBuffer - } - if isControlFrame && payloadLen > 125 { + if payloadLen < 2 { + doDisconnect(errorWithDetail("connection closed by server", code: closeCode)) + writeError(closeCode) + return emptyBuffer + } + } else if isControlFrame && payloadLen > 125 { writeError(CloseCode.protocolError.rawValue) return emptyBuffer } @@ -695,8 +669,24 @@ open class WebSocket : NSObject, StreamDelegate { len = 0 data = Data() } else { + if receivedOpcode == .connectionClose && len > 0 { + let size = MemoryLayout.size + offset += size + len -= UInt64(size) + } data = Data(bytes: baseAddress+offset, count: Int(len)) } + if receivedOpcode == .connectionClose { + var closeReason = "connection closed by server" + if let customCloseReason = String(data: data, encoding: .utf8) { + closeReason = customCloseReason + } else { + closeCode = CloseCode.protocolError.rawValue + } + doDisconnect(errorWithDetail(closeReason, code: closeCode)) + writeError(closeCode) + return emptyBuffer + } if receivedOpcode == .pong { if canDispatch { callbackQueue.async { [weak self] in @@ -910,7 +900,6 @@ open class WebSocket : NSObject, StreamDelegate { } // MARK: - Deinit - deinit { mutex.lock() readyToWrite = false From 85b6dc1766f5e76179ce45e6fcf4a6a6513c900f Mon Sep 17 00:00:00 2001 From: Erik Little Date: Thu, 27 Oct 2016 07:02:01 -0400 Subject: [PATCH 05/11] bump version --- README.md | 8 ++++---- Socket.IO-Client-Swift.podspec | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 55a53ad..929ee95 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{ [socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) { double cur = [[data objectAtIndex:0] floatValue]; - [socket emitWithAck:@"canUpdate" with:@[@(cur)]](0, ^(NSArray* data) { + [[socket emitWithAck:@"testAckEmit" with:@[@YES]] timingOutAfter:0 callback:^(NSArray* data) { [socket emit:@"update" withItems:@[@{@"amount": @(cur + 2.50)}]]; }]; @@ -95,7 +95,7 @@ Carthage ----------------- Add this line to your `Cartfile`: ``` -github "socketio/socket.io-client-swift" ~> 8.0.3 # Or latest version +github "socketio/socket.io-client-swift" ~> 8.1.0 # Or latest version ``` Run `carthage update --platform ios,macosx`. @@ -108,7 +108,7 @@ Create `Podfile` and add `pod 'Socket.IO-Client-Swift'`: use_frameworks! target 'YourApp' do - pod 'Socket.IO-Client-Swift', '~> 8.0.3' # Or latest version + pod 'Socket.IO-Client-Swift', '~> 8.1.0' # Or latest version end ``` @@ -137,7 +137,7 @@ CocoaSeeds Add this line to your `Seedfile`: ``` -github "socketio/socket.io-client-swift", "v8.0.3", :files => "Source/*.swift" # Or latest version +github "socketio/socket.io-client-swift", "v8.1.0", :files => "Source/*.swift" # Or latest version ``` Run `seed install`. diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index 01faaa6..36c8c06 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 = "8.0.3" + s.version = "8.1.0" 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 => 'v8.0.3' } + s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v8.1.0' } s.source_files = "Source/**/*.swift" s.requires_arc = true # s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files From 86181525dfefd6614fa3398bfc4a2344d4d3de6c Mon Sep 17 00:00:00 2001 From: Erik Little Date: Thu, 27 Oct 2016 07:14:53 -0400 Subject: [PATCH 06/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 929ee95..6a4dc16 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{ [socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) { double cur = [[data objectAtIndex:0] floatValue]; - [[socket emitWithAck:@"testAckEmit" with:@[@YES]] timingOutAfter:0 callback:^(NSArray* data) { + [[socket emitWithAck:@"canUpdate" with:@[@(cur)] timingOutAfter:0 callback:^(NSArray* data) { [socket emit:@"update" withItems:@[@{@"amount": @(cur + 2.50)}]]; }]; From ff12285e94ddc358c74b0ddd7191a8aa7bfba9f9 Mon Sep 17 00:00:00 2001 From: Nader Toukabri Date: Fri, 28 Oct 2016 14:23:22 +0100 Subject: [PATCH 07/11] add SocketAckEmitter.isRequired() --- Source/SocketAckEmitter.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/SocketAckEmitter.swift b/Source/SocketAckEmitter.swift index 6b86460..07fd239 100644 --- a/Source/SocketAckEmitter.swift +++ b/Source/SocketAckEmitter.swift @@ -44,6 +44,10 @@ public final class SocketAckEmitter : NSObject { socket.emitAck(ackNum, with: items) } + + public func isRequired() -> Bool { + return ackNum != -1; + } } public final class OnAckCallback : NSObject { From 863480acf2ece70af1f5f71b5c6abacc429bbce3 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Fri, 28 Oct 2016 09:43:46 -0400 Subject: [PATCH 08/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a4dc16..a67e0c5 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{ [socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) { double cur = [[data objectAtIndex:0] floatValue]; - [[socket emitWithAck:@"canUpdate" with:@[@(cur)] timingOutAfter:0 callback:^(NSArray* data) { + [[socket emitWithAck:@"canUpdate" with:@[@(cur)]] timingOutAfter:0 callback:^(NSArray* data) { [socket emit:@"update" withItems:@[@{@"amount": @(cur + 2.50)}]]; }]; From 018c993a9d794d6702980ef7751d33e10167b12f Mon Sep 17 00:00:00 2001 From: Nader Toukabri Date: Fri, 28 Oct 2016 15:09:21 +0100 Subject: [PATCH 09/11] remove semicolon --- Source/SocketAckEmitter.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SocketAckEmitter.swift b/Source/SocketAckEmitter.swift index 07fd239..2132ad6 100644 --- a/Source/SocketAckEmitter.swift +++ b/Source/SocketAckEmitter.swift @@ -46,7 +46,7 @@ public final class SocketAckEmitter : NSObject { } public func isRequired() -> Bool { - return ackNum != -1; + return ackNum != -1 } } From efad448fab09570bcb4e79255ac171b249717000 Mon Sep 17 00:00:00 2001 From: Nader Toukabri Date: Fri, 28 Oct 2016 15:14:07 +0100 Subject: [PATCH 10/11] change isRequired() to isExpected() --- Source/SocketAckEmitter.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SocketAckEmitter.swift b/Source/SocketAckEmitter.swift index 2132ad6..b4ae0b9 100644 --- a/Source/SocketAckEmitter.swift +++ b/Source/SocketAckEmitter.swift @@ -45,7 +45,7 @@ public final class SocketAckEmitter : NSObject { socket.emitAck(ackNum, with: items) } - public func isRequired() -> Bool { + public func isExpected() -> Bool { return ackNum != -1 } } From ea3fca376772ae4308eb2b2481f4e1937d84336f Mon Sep 17 00:00:00 2001 From: Nader Toukabri Date: Fri, 28 Oct 2016 15:59:50 +0100 Subject: [PATCH 11/11] SocketAckEmitter.isExpected => .expected --- Source/SocketAckEmitter.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/SocketAckEmitter.swift b/Source/SocketAckEmitter.swift index b4ae0b9..4af43e7 100644 --- a/Source/SocketAckEmitter.swift +++ b/Source/SocketAckEmitter.swift @@ -27,6 +27,10 @@ import Foundation public final class SocketAckEmitter : NSObject { let socket: SocketIOClient let ackNum: Int + + public var expected: Bool { + return ackNum != -1 + } init(socket: SocketIOClient, ackNum: Int) { self.socket = socket @@ -45,9 +49,6 @@ public final class SocketAckEmitter : NSObject { socket.emitAck(ackNum, with: items) } - public func isExpected() -> Bool { - return ackNum != -1 - } } public final class OnAckCallback : NSObject {