From 4dcfcc2a8459bc44f1d81dbcf4c50b71298ed5b7 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Wed, 20 Sep 2017 11:19:15 -0400 Subject: [PATCH 01/23] Fix warnings --- Socket.IO-Client-Swift.xcodeproj/project.pbxproj | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index c54d956..649de36 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -1087,6 +1087,7 @@ SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = $SRCROOT/zlib; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; @@ -1139,6 +1140,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = $SRCROOT/zlib; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; @@ -1303,7 +1305,7 @@ SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1361,7 +1363,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = ""; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1423,7 +1425,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Debug; @@ -1475,7 +1477,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Release; From 4d30b3c951945af0c1f6987948f7ae769d463b4d Mon Sep 17 00:00:00 2001 From: Erik Little Date: Mon, 25 Sep 2017 09:09:23 -0400 Subject: [PATCH 02/23] characters is going to be deprecated --- Source/SocketIO/Engine/SocketEngine.swift | 4 ++-- Source/SocketIO/Engine/SocketEnginePollable.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/SocketIO/Engine/SocketEngine.swift b/Source/SocketIO/Engine/SocketEngine.swift index 2a4e699..d2e6f56 100644 --- a/Source/SocketIO/Engine/SocketEngine.swift +++ b/Source/SocketIO/Engine/SocketEngine.swift @@ -517,13 +517,13 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll switch type { case .message: - handleMessage(String(message.characters.dropFirst())) + handleMessage(String(message.dropFirst())) case .noop: handleNOOP() case .pong: handlePong(with: message) case .open: - handleOpen(openData: String(message.characters.dropFirst())) + handleOpen(openData: String(message.dropFirst())) case .close: handleClose(message) default: diff --git a/Source/SocketIO/Engine/SocketEnginePollable.swift b/Source/SocketIO/Engine/SocketEnginePollable.swift index a42493a..680f9cf 100644 --- a/Source/SocketIO/Engine/SocketEnginePollable.swift +++ b/Source/SocketIO/Engine/SocketEnginePollable.swift @@ -184,7 +184,7 @@ extension SocketEnginePollable { } func parsePollingMessage(_ str: String) { - guard str.characters.count != 1 else { return } + guard str.count != 1 else { return } DefaultSocketLogger.Logger.log("Got poll message: \(str)", type: "SocketEnginePolling") From 752407fb6750ab6323db6717721d399770e802da Mon Sep 17 00:00:00 2001 From: Erik Little Date: Fri, 29 Sep 2017 22:09:38 -0400 Subject: [PATCH 03/23] More documentation --- .../project.pbxproj | 4 +-- Source/SocketIO/Client/SocketIOClient.swift | 20 ++++++++++-- .../SocketIO/Client/SocketIOClientSpec.swift | 32 +++++++++++++++++++ Source/Starscream | 2 +- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index 649de36..5d836cb 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -990,7 +990,7 @@ ONLY_ACTIVE_ARCH = YES; PRODUCT_NAME = SocketIO; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -1029,7 +1029,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SocketIO; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index 9875895..540fed0 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -64,7 +64,9 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So @objc public var handleQueue = DispatchQueue.main - /// The namespace for this client. + /// The namespace that this socket is currently connected to. + /// + /// **Must** start with a `/`. @objc public var nsp = "/" @@ -93,6 +95,11 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So public var socketURL: URL var ackHandlers = SocketAckManager() + + /// A list of packets that are waiting for binary data. + /// + /// The way that socket.io works all data should be sent directly after each packet. + /// So this should ideally be an array of one packet waiting for data. var waitingPackets = [SocketPacket]() private(set) var currentAck = -1 @@ -172,7 +179,9 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So engine = SocketEngine(client: self, url: socketURL, config: config) } - /// Connect to the server. + /// Connect to the server. The same as calling `connect(timeoutAfter:withHandler:)` with a timeout of 0. + /// + /// Only call after adding your event listeners, unless you know what you're doing. @objc open func connect() { connect(timeoutAfter: 0, withHandler: nil) @@ -180,6 +189,8 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So /// Connect to the server. If we aren't connected after `timeoutAfter` seconds, then `withHandler` is called. /// + /// Only call after adding your event listeners, unless you know what you're doing. + /// /// - parameter timeoutAfter: The number of seconds after which if we are not connected we assume the connection /// has failed. Pass 0 to never timeout. /// - parameter withHandler: The handler to call when the client fails to connect. @@ -219,6 +230,8 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So return OnAckCallback(ackNumber: currentAck, items: items, socket: self) } + /// Called when the client connects to a namespace. If the client was created with a namespace upfront, + /// then this is only called when the client connects to that namespace. func didConnect(toNamespace namespace: String) { DefaultSocketLogger.Logger.log("Socket connected", type: SocketIOClient.logType) @@ -227,6 +240,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So handleClientEvent(.connect, data: [namespace]) } + /// Called when the client has disconnected from socket.io. func didDisconnect(reason: String) { guard status != .disconnected else { return } @@ -437,7 +451,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So handleEvent(event.rawValue, data: data, isInternalMessage: true) } - /// Leaves nsp and goes back to the default namespace. + /// Call when you wish to leave a namespace and return to the default namespace. @objc open func leaveNamespace() { if nsp != "/" { diff --git a/Source/SocketIO/Client/SocketIOClientSpec.swift b/Source/SocketIO/Client/SocketIOClientSpec.swift index f53525f..68e9c59 100644 --- a/Source/SocketIO/Client/SocketIOClientSpec.swift +++ b/Source/SocketIO/Client/SocketIOClientSpec.swift @@ -25,20 +25,52 @@ import Dispatch protocol SocketIOClientSpec : class { + /// The queue that all interaction with the client must be on. var handleQueue: DispatchQueue { get set } + + /// The namespace that this socket is currently connected to. + /// + /// **Must** start with a `/`. var nsp: String { get set } + + /// A list of packets that are waiting for binary data. + /// + /// The way that socket.io works all data should be sent directly after each packet. + /// So this should ideally be an array of one packet waiting for data. var waitingPackets: [SocketPacket] { get set } + /// Called when the client connects to a namespace. If the client was created with a namespace upfront, + /// then this is only called when the client connects to that namespace. func didConnect(toNamespace namespace: String) + + /// Called when the client has disconnected from socket.io. func didDisconnect(reason: String) + + /// Called when the client encounters an error. func didError(reason: String) + + /// Called when socket.io has acked one of our emits. Causes the corresponding ack callback to be called. func handleAck(_ ack: Int, data: [Any]) + + /// Called when we get an event from socket.io. func handleEvent(_ event: String, data: [Any], isInternalMessage: Bool, withAck ack: Int) + + /// Called on socket.io events. func handleClientEvent(_ event: SocketClientEvent, data: [Any]) + + /// Call when you wish to leave a namespace and return to the default namespace. + func leaveNamespace() + + /// Joins `namespace`. + /// + /// **Do not use this to join the default namespace.** Instead call `leaveNamespace`. + /// + /// - parameter namespace: The namespace to join. func joinNamespace(_ namespace: String) } extension SocketIOClientSpec { + /// Default implementation. func didError(reason: String) { DefaultSocketLogger.Logger.error("\(reason)", type: "SocketIOClient") diff --git a/Source/Starscream b/Source/Starscream index f7e28f2..9ecc44c 160000 --- a/Source/Starscream +++ b/Source/Starscream @@ -1 +1 @@ -Subproject commit f7e28f24ae20898da5804079319da52682bb9212 +Subproject commit 9ecc44c2da053b1c4ff0ac505fe1d43a793d0b45 From 6eafce00827243a36e5922b089bb17182310ff15 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Fri, 29 Sep 2017 22:45:55 -0400 Subject: [PATCH 04/23] update starscream --- Package.swift | 2 +- Socket.IO-Client-Swift.podspec | 2 +- SocketIO-MacTests/SocketObjectiveCTest.m | 2 +- Source/Starscream | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index a782647..34c1298 100644 --- a/Package.swift +++ b/Package.swift @@ -8,7 +8,7 @@ let package = Package( .library(name: "SocketIO", targets: ["SocketIO"]) ], dependencies: [ - .package(url: "https://github.com/nuclearace/Starscream", .upToNextMajor(from: "8.0.0")), + .package(url: "https://github.com/nuclearace/Starscream", .upToNextMajor(from: "9.0.0")), ], targets: [ .target(name: "SocketIO", dependencies: ["StarscreamSocketIO"], exclude: ["Sources/Starscream"]) diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index d757230..68fbea3 100644 --- a/Socket.IO-Client-Swift.podspec +++ b/Socket.IO-Client-Swift.podspec @@ -24,5 +24,5 @@ Pod::Spec.new do |s| 'SWIFT_VERSION' => '4.0' } s.source_files = "Source/SocketIO/**/*.swift", "Source/SocketIO/*.swift" - s.dependency "StarscreamSocketIO", "~> 8.0.7" + s.dependency "StarscreamSocketIO", "~> 9.0.0" end diff --git a/SocketIO-MacTests/SocketObjectiveCTest.m b/SocketIO-MacTests/SocketObjectiveCTest.m index b9ddc04..6474123 100644 --- a/SocketIO-MacTests/SocketObjectiveCTest.m +++ b/SocketIO-MacTests/SocketObjectiveCTest.m @@ -103,7 +103,7 @@ - (void)testSSLSecurity { SSLSecurity* sec = [[SSLSecurity alloc] initWithUsePublicKeys:0]; - sec.isReady = 0; + sec = nil; } @end diff --git a/Source/Starscream b/Source/Starscream index 9ecc44c..6713338 160000 --- a/Source/Starscream +++ b/Source/Starscream @@ -1 +1 @@ -Subproject commit 9ecc44c2da053b1c4ff0ac505fe1d43a793d0b45 +Subproject commit 67133384e6d6654d5abcfbb143317ec8b3275bff From ca4261d8caa0e55d6e0586898c492a212abd82de Mon Sep 17 00:00:00 2001 From: Erik Little Date: Fri, 29 Sep 2017 23:09:36 -0400 Subject: [PATCH 05/23] work on fixing for latest version --- .../project.pbxproj | 144 +++++------------- Source/SocketIO/Engine/SocketEngine.swift | 11 +- .../Engine/SocketEngineWebsocket.swift | 4 +- Source/Starscream | 2 +- 4 files changed, 51 insertions(+), 110 deletions(-) diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index 5d836cb..3b09edc 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -126,68 +126,40 @@ remoteGlobalIDString = 576349FA1BD9B46A00E19CD7; remoteInfo = "SocketIO-tvOS"; }; - 745225EC1F1BA89E007EA874 /* PBXContainerItemProxy */ = { + 74B3C8391F7F3ECE007D96C8 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 33CCF0921F5DDC030099B092; + remoteInfo = StarscreamSocketIO; + }; + 74B3C83B1F7F3ECE007D96C8 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 335FA2021F5DF71D00F6D2EC; + remoteInfo = "Starscream Tests"; + }; + 74B3C8411F7F3F93007D96C8 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; proxyType = 1; - remoteGlobalIDString = 6B3E79E519D48B7F006071F7; - remoteInfo = "Starscream iOS"; + remoteGlobalIDString = 33CCF0841F5DDC030099B092; + remoteInfo = StarscreamSocketIO; }; - 74638B631F111CD000F5E1FF /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 6B3E79E619D48B7F006071F7; - remoteInfo = "Starscream iOS"; - }; - 74638B651F111CD000F5E1FF /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 6B3E79F119D48B7F006071F7; - remoteInfo = "Starscream iOSTests"; - }; - 74638B671F111CD000F5E1FF /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D9C3E35F19E48FF1009FC285; - remoteInfo = "Starscream OSX"; - }; - 74638B691F111CD000F5E1FF /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D9C3E36919E48FF1009FC285; - remoteInfo = "Starscream OSXTests"; - }; - 74638B6B1F111CD000F5E1FF /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 091277971BD673A70003036D; - remoteInfo = "Starscream tvOS"; - }; - 74638B6D1F111CD000F5E1FF /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 091277A01BD673A70003036D; - remoteInfo = "Starscream tvOSTests"; - }; - 74638B711F111CF100F5E1FF /* PBXContainerItemProxy */ = { + 74B3C8431F7F3F98007D96C8 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; proxyType = 1; - remoteGlobalIDString = D9C3E35E19E48FF1009FC285; - remoteInfo = "Starscream OSX"; + remoteGlobalIDString = 33CCF0841F5DDC030099B092; + remoteInfo = StarscreamSocketIO; }; - 74638B731F111CF600F5E1FF /* PBXContainerItemProxy */ = { + 74B3C8451F7F3F9C007D96C8 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; proxyType = 1; - remoteGlobalIDString = 091277961BD673A70003036D; - remoteInfo = "Starscream tvOS"; + remoteGlobalIDString = 33CCF0841F5DDC030099B092; + remoteInfo = StarscreamSocketIO; }; /* End PBXContainerItemProxy section */ @@ -436,12 +408,8 @@ 74638B5B1F111CD000F5E1FF /* Products */ = { isa = PBXGroup; children = ( - 74638B641F111CD000F5E1FF /* StarscreamSocketIO.framework */, - 74638B661F111CD000F5E1FF /* Starscream iOSTests.xctest */, - 74638B681F111CD000F5E1FF /* StarscreamSocketIO.framework */, - 74638B6A1F111CD000F5E1FF /* Starscream OSXTests.xctest */, - 74638B6C1F111CD000F5E1FF /* StarscreamSocketIO.framework */, - 74638B6E1F111CD000F5E1FF /* Starscream tvOSTests.xctest */, + 74B3C83A1F7F3ECE007D96C8 /* StarscreamSocketIO.framework */, + 74B3C83C1F7F3ECE007D96C8 /* Starscream Tests.xctest */, ); name = Products; sourceTree = ""; @@ -550,7 +518,7 @@ buildRules = ( ); dependencies = ( - 745225ED1F1BA89E007EA874 /* PBXTargetDependency */, + 74B3C8461F7F3F9C007D96C8 /* PBXTargetDependency */, ); name = "SocketIO-iOS"; productName = "SocketIO-iOS"; @@ -587,7 +555,7 @@ buildRules = ( ); dependencies = ( - 74638B721F111CF100F5E1FF /* PBXTargetDependency */, + 74B3C8441F7F3F98007D96C8 /* PBXTargetDependency */, ); name = "SocketIO-Mac"; productName = "SocketIO-Mac"; @@ -624,7 +592,7 @@ buildRules = ( ); dependencies = ( - 74638B741F111CF600F5E1FF /* PBXTargetDependency */, + 74B3C8421F7F3F93007D96C8 /* PBXTargetDependency */, ); name = "SocketIO-tvOS"; productName = "SocketIO-iOS"; @@ -704,46 +672,18 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - 74638B641F111CD000F5E1FF /* StarscreamSocketIO.framework */ = { + 74B3C83A1F7F3ECE007D96C8 /* StarscreamSocketIO.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; path = StarscreamSocketIO.framework; - remoteRef = 74638B631F111CD000F5E1FF /* PBXContainerItemProxy */; + remoteRef = 74B3C8391F7F3ECE007D96C8 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 74638B661F111CD000F5E1FF /* Starscream iOSTests.xctest */ = { + 74B3C83C1F7F3ECE007D96C8 /* Starscream Tests.xctest */ = { isa = PBXReferenceProxy; fileType = wrapper.cfbundle; - path = "Starscream iOSTests.xctest"; - remoteRef = 74638B651F111CD000F5E1FF /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 74638B681F111CD000F5E1FF /* StarscreamSocketIO.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = StarscreamSocketIO.framework; - remoteRef = 74638B671F111CD000F5E1FF /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 74638B6A1F111CD000F5E1FF /* Starscream OSXTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "Starscream OSXTests.xctest"; - remoteRef = 74638B691F111CD000F5E1FF /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 74638B6C1F111CD000F5E1FF /* StarscreamSocketIO.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = StarscreamSocketIO.framework; - remoteRef = 74638B6B1F111CD000F5E1FF /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 74638B6E1F111CD000F5E1FF /* Starscream tvOSTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "Starscream tvOSTests.xctest"; - remoteRef = 74638B6D1F111CD000F5E1FF /* PBXContainerItemProxy */; + path = "Starscream Tests.xctest"; + remoteRef = 74B3C83B1F7F3ECE007D96C8 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXReferenceProxy section */ @@ -936,20 +876,20 @@ target = 576349FA1BD9B46A00E19CD7 /* SocketIO-tvOS */; targetProxy = 57634A3D1BD9B4B800E19CD7 /* PBXContainerItemProxy */; }; - 745225ED1F1BA89E007EA874 /* PBXTargetDependency */ = { + 74B3C8421F7F3F93007D96C8 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - name = "Starscream iOS"; - targetProxy = 745225EC1F1BA89E007EA874 /* PBXContainerItemProxy */; + name = StarscreamSocketIO; + targetProxy = 74B3C8411F7F3F93007D96C8 /* PBXContainerItemProxy */; }; - 74638B721F111CF100F5E1FF /* PBXTargetDependency */ = { + 74B3C8441F7F3F98007D96C8 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - name = "Starscream OSX"; - targetProxy = 74638B711F111CF100F5E1FF /* PBXContainerItemProxy */; + name = StarscreamSocketIO; + targetProxy = 74B3C8431F7F3F98007D96C8 /* PBXContainerItemProxy */; }; - 74638B741F111CF600F5E1FF /* PBXTargetDependency */ = { + 74B3C8461F7F3F9C007D96C8 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - name = "Starscream tvOS"; - targetProxy = 74638B731F111CF600F5E1FF /* PBXContainerItemProxy */; + name = StarscreamSocketIO; + targetProxy = 74B3C8451F7F3F9C007D96C8 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ diff --git a/Source/SocketIO/Engine/SocketEngine.swift b/Source/SocketIO/Engine/SocketEngine.swift index d2e6f56..9553757 100644 --- a/Source/SocketIO/Engine/SocketEngine.swift +++ b/Source/SocketIO/Engine/SocketEngine.swift @@ -310,21 +310,22 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll private func createWebSocketAndConnect() { ws?.delegate = nil // TODO this seems a bit defensive, is this really needed? - ws = WebSocket(url: urlWebSocketWithSid) + var request = URLRequest(url: urlWebSocketWithSid) if cookies != nil { let headers = HTTPCookie.requestHeaderFields(with: cookies!) for (key, value) in headers { - ws?.headers[key] = value + request.setValue(value, forHTTPHeaderField: key) } } if extraHeaders != nil { for (headerName, value) in extraHeaders! { - ws?.headers[headerName] = value + request.setValue(value, forHTTPHeaderField: headerName) } } + ws = WebSocket(request: request) ws?.callbackQueue = engineQueue ws?.enableCompression = compress ws?.delegate = self @@ -604,7 +605,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll // MARK: Starscream delegate conformance /// Delegate method for connection. - public func websocketDidConnect(socket: WebSocket) { + public func websocketDidConnect(socket: WebSocketClient) { if !forceWebsockets { probing = true probeWebSocket() @@ -616,7 +617,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll } /// Delegate method for disconnection. - public func websocketDidDisconnect(socket: WebSocket, error: NSError?) { + public func websocketDidDisconnect(socket: WebSocketClient, error: Error?) { probing = false if closed { diff --git a/Source/SocketIO/Engine/SocketEngineWebsocket.swift b/Source/SocketIO/Engine/SocketEngineWebsocket.swift index e572d96..7e432aa 100644 --- a/Source/SocketIO/Engine/SocketEngineWebsocket.swift +++ b/Source/SocketIO/Engine/SocketEngineWebsocket.swift @@ -68,12 +68,12 @@ extension SocketEngineWebsocket { // MARK: Starscream delegate methods /// Delegate method for when a message is received. - public func websocketDidReceiveMessage(socket: WebSocket, text: String) { + public func websocketDidReceiveMessage(socket: WebSocketClient, text: String) { parseEngineMessage(text) } /// Delegate method for when binary is received. - public func websocketDidReceiveData(socket: WebSocket, data: Data) { + public func websocketDidReceiveData(socket: WebSocketClient, data: Data) { parseEngineData(data) } } diff --git a/Source/Starscream b/Source/Starscream index 6713338..f2a7f24 160000 --- a/Source/Starscream +++ b/Source/Starscream @@ -1 +1 @@ -Subproject commit 67133384e6d6654d5abcfbb143317ec8b3275bff +Subproject commit f2a7f24ffbcbdcf3e1fb500dd3e08984bcb5d76b From d878f56839563a219bf8e3f9133aab380b7f1286 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Fri, 29 Sep 2017 23:21:05 -0400 Subject: [PATCH 06/23] update version; again --- Socket.IO-Client-Swift.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index 68fbea3..a92bd04 100644 --- a/Socket.IO-Client-Swift.podspec +++ b/Socket.IO-Client-Swift.podspec @@ -24,5 +24,5 @@ Pod::Spec.new do |s| 'SWIFT_VERSION' => '4.0' } s.source_files = "Source/SocketIO/**/*.swift", "Source/SocketIO/*.swift" - s.dependency "StarscreamSocketIO", "~> 9.0.0" + s.dependency "StarscreamSocketIO", "~> 9.0.2" end From 5607280836e795918d04c0d75b152b7b0ce7fe19 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Fri, 29 Sep 2017 23:41:55 -0400 Subject: [PATCH 07/23] bump starscream dev --- Source/Starscream | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Starscream b/Source/Starscream index f2a7f24..24e71ab 160000 --- a/Source/Starscream +++ b/Source/Starscream @@ -1 +1 @@ -Subproject commit f2a7f24ffbcbdcf3e1fb500dd3e08984bcb5d76b +Subproject commit 24e71ab1c8855dbc16325d5cca6bceae918d5ea8 From 486a89d407182f8808aa9b7d8f9640a342f02528 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sat, 30 Sep 2017 10:24:40 -0400 Subject: [PATCH 08/23] More documentation --- .../SocketIO/Client/SocketIOClientSpec.swift | 2 ++ Source/SocketIO/Parse/SocketParsable.swift | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Source/SocketIO/Client/SocketIOClientSpec.swift b/Source/SocketIO/Client/SocketIOClientSpec.swift index 68e9c59..a514637 100644 --- a/Source/SocketIO/Client/SocketIOClientSpec.swift +++ b/Source/SocketIO/Client/SocketIOClientSpec.swift @@ -24,6 +24,8 @@ import Dispatch + +/// Defines the interface for a SocketIOClient. protocol SocketIOClientSpec : class { /// The queue that all interaction with the client must be on. var handleQueue: DispatchQueue { get set } diff --git a/Source/SocketIO/Parse/SocketParsable.swift b/Source/SocketIO/Parse/SocketParsable.swift index d99d0c1..137491a 100644 --- a/Source/SocketIO/Parse/SocketParsable.swift +++ b/Source/SocketIO/Parse/SocketParsable.swift @@ -22,8 +22,20 @@ import Foundation +/// Defines that a type will be able to parse socket.io-protocol messages. protocol SocketParsable { + /// Called when the engine has received some binary data that should be attached to a packet. + /// + /// Packets binary data should be sent directly after the packet that expects it, so there's confusion over + /// where the data should go. Data should be received in the order it is sent, so that the correct data is put + /// into the correct placeholder. + /// + /// - parameter data: The data that should be attached to a packet. func parseBinaryData(_ data: Data) + + /// Called when the engine has received a string that should be parsed into a socket.io packet. + /// + /// - parameter message: The string that needs parsing. func parseSocketMessage(_ message: String) } @@ -133,7 +145,9 @@ extension SocketParsable where Self: SocketIOClientSpec { } } - // Parses messages recieved + /// Called when the engine has received a string that should be parsed into a socket.io packet. + /// + /// - parameter message: The string that needs parsing. func parseSocketMessage(_ message: String) { guard !message.isEmpty else { return } @@ -150,6 +164,13 @@ extension SocketParsable where Self: SocketIOClientSpec { } } + /// Called when the engine has received some binary data that should be attached to a packet. + /// + /// Packets binary data should be sent directly after the packet that expects it, so there's confusion over + /// where the data should go. Data should be received in the order it is sent, so that the correct data is put + /// into the correct placeholder. + /// + /// - parameter data: The data that should be attached to a packet. func parseBinaryData(_ data: Data) { guard !waitingPackets.isEmpty else { DefaultSocketLogger.Logger.error("Got data when not remaking packet", type: "SocketParser") From 91eea96308bab7ced8a615b18e1bce840116efb9 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sat, 30 Sep 2017 11:33:39 -0400 Subject: [PATCH 09/23] Make a bunch of things public. Fixes #803 --- Source/SocketIO/Ack/SocketAckEmitter.swift | 8 +- .../SocketIO/Client/SocketEventHandler.swift | 27 ++- Source/SocketIO/Client/SocketIOClient.swift | 98 ++++++---- .../SocketIO/Client/SocketIOClientSpec.swift | 167 +++++++++++++++++- Source/SocketIO/Parse/SocketPacket.swift | 46 +++-- Source/SocketIO/Parse/SocketParsable.swift | 39 +++- 6 files changed, 313 insertions(+), 72 deletions(-) diff --git a/Source/SocketIO/Ack/SocketAckEmitter.swift b/Source/SocketIO/Ack/SocketAckEmitter.swift index b13e15a..d8a30c4 100644 --- a/Source/SocketIO/Ack/SocketAckEmitter.swift +++ b/Source/SocketIO/Ack/SocketAckEmitter.swift @@ -39,7 +39,13 @@ public final class SocketAckEmitter : NSObject { return ackNum != -1 } - init(socket: SocketIOClient, ackNum: Int) { + // MARK: Initializers + + /// Creates a new `SocketAckEmitter`. + /// + /// - parameter socket: The socket for this emitter. + /// - parameter ackNum: The ack number for this emitter. + public init(socket: SocketIOClient, ackNum: Int) { self.socket = socket self.ackNum = ackNum } diff --git a/Source/SocketIO/Client/SocketEventHandler.swift b/Source/SocketIO/Client/SocketEventHandler.swift index 5497f7f..4f75a5a 100644 --- a/Source/SocketIO/Client/SocketEventHandler.swift +++ b/Source/SocketIO/Client/SocketEventHandler.swift @@ -24,12 +24,27 @@ import Foundation -struct SocketEventHandler { - let event: String - let id: UUID - let callback: NormalCallback - - func executeCallback(with items: [Any], withAck ack: Int, withSocket socket: SocketIOClient) { +/// A wrapper around a handler. +public struct SocketEventHandler { + // MARK: Properties + + /// The event for this handler. + public let event: String + + /// A unique identifier for this handler. + public let id: UUID + + /// The actual handler function. + public let callback: NormalCallback + + // MARK: Methods + + /// Causes this handler to be executed. + /// + /// - parameter with: The data that this handler should be called with. + /// - parameter withAck: The ack number that this event expects. Pass -1 to say this event doesn't expect an ack. + /// - parameter withSocket: The socket that is calling this event. + public func executeCallback(with items: [Any], withAck ack: Int, withSocket socket: SocketIOClient) { callback(items, SocketAckEmitter(socket: socket, ackNum: ack)) } } diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index 540fed0..22b122d 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -35,26 +35,6 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So private static let logType = "SocketIOClient" - /// The engine for this client. - @objc - public private(set) var engine: SocketEngineSpec? - - /// The status of this client. - @objc - public private(set) var status = SocketIOClientStatus.notConnected { - didSet { - switch status { - case .connected: - reconnecting = false - currentReconnectAttempt = 0 - default: - break - } - - handleClientEvent(.statusChange, data: [status]) - } - } - /// If `true` then every time `connect` is called, a new engine will be created. @objc public var forceNew = false @@ -94,20 +74,46 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So @objc public var socketURL: URL - var ackHandlers = SocketAckManager() - /// A list of packets that are waiting for binary data. /// /// The way that socket.io works all data should be sent directly after each packet. /// So this should ideally be an array of one packet waiting for data. - var waitingPackets = [SocketPacket]() + /// + /// **This should not be modified directly.** + public var waitingPackets = [SocketPacket]() + + /// A handler that will be called on any event. + public private(set) var anyHandler: ((SocketAnyEvent) -> ())? + + /// The engine for this client. + @objc + public private(set) var engine: SocketEngineSpec? + + /// The array of handlers for this socket. + public private(set) var handlers = [SocketEventHandler]() + + /// The status of this client. + @objc + public private(set) var status = SocketIOClientStatus.notConnected { + didSet { + switch status { + case .connected: + reconnecting = false + currentReconnectAttempt = 0 + default: + break + } + + handleClientEvent(.statusChange, data: [status]) + } + } + + var ackHandlers = SocketAckManager() private(set) var currentAck = -1 private(set) var reconnectAttempts = -1 - private var anyHandler: ((SocketAnyEvent) -> ())? private var currentReconnectAttempt = 0 - private var handlers = [SocketEventHandler]() private var reconnecting = false // MARK: Initializers @@ -232,7 +238,9 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So /// Called when the client connects to a namespace. If the client was created with a namespace upfront, /// then this is only called when the client connects to that namespace. - func didConnect(toNamespace namespace: String) { + /// + /// - parameter toNamespace: The namespace that was connected to. + open func didConnect(toNamespace namespace: String) { DefaultSocketLogger.Logger.log("Socket connected", type: SocketIOClient.logType) status = .connected @@ -241,7 +249,9 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So } /// Called when the client has disconnected from socket.io. - func didDisconnect(reason: String) { + /// + /// - parameter reason: The reason for the disconnection. + open func didDisconnect(reason: String) { guard status != .disconnected else { return } DefaultSocketLogger.Logger.log("Disconnected: \(reason)", type: SocketIOClient.logType) @@ -361,8 +371,13 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So engine?.send(str, withData: packet.binary) } - // If the server wants to know that the client received data - func emitAck(_ ack: Int, with items: [Any]) { + /// Call when you wish to tell the server that you've received the event for `ack`. + /// + /// **You shouldn't need to call this directly.** Instead use an `SocketAckEmitter` that comes in an event callback. + /// + /// - parameter ack: The ack number. + /// - parameter with: The data for this ack. + open func emitAck(_ ack: Int, with items: [Any]) { guard status == .connected else { return } let packet = SocketPacket.packetFromEmit(items, id: ack, nsp: nsp, ack: true) @@ -419,8 +434,12 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So DefaultSocketLogger.Logger.log(reason, type: SocketIOClient.logType) } - // Called when the socket gets an ack for something it sent - func handleAck(_ ack: Int, data: [Any]) { + /// Called when socket.io has acked one of our emits. Causes the corresponding ack callback to be called. + /// + /// - parameter ack: The number for this ack. + /// - parameter data: The data sent back with this ack. + @objc + open func handleAck(_ ack: Int, data: [Any]) { guard status == .connected else { return } DefaultSocketLogger.Logger.log("Handling ack: \(ack) with data: \(data)", type: SocketIOClient.logType) @@ -428,12 +447,12 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So ackHandlers.executeAck(ack, with: data, onQueue: handleQueue) } - /// Causes an event to be handled, and any event handlers for that event to be called. + /// Called when we get an event from socket.io. /// - /// - parameter event: The event that is to be handled. - /// - parameter data: the data associated with this event. - /// - parameter isInternalMessage: If `true` event handlers for this event will be called regardless of status. - /// - parameter withAck: The ack number for this event. May be left out. + /// - parameter event: The name of the event. + /// - parameter data: The data that was sent with this event. + /// - parameter isInternalMessage: Whether this event was sent internally. If `true` it is always sent to handlers. + /// - parameter withAck: If > 0 then this event expects to get an ack back from the client. @objc open func handleEvent(_ event: String, data: [Any], isInternalMessage: Bool, withAck ack: Int = -1) { guard status == .connected || isInternalMessage else { return } @@ -447,7 +466,11 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So } } - func handleClientEvent(_ event: SocketClientEvent, data: [Any]) { + /// Called on socket.io specific events. + /// + /// - parameter event: The `SocketClientEvent`. + /// - parameter data: The data for this event. + open func handleClientEvent(_ event: SocketClientEvent, data: [Any]) { handleEvent(event.rawValue, data: data, isInternalMessage: true) } @@ -615,6 +638,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So } /// Removes all handlers. + /// /// Can be used after disconnecting to break any potential remaining retain cycles. @objc open func removeAllHandlers() { diff --git a/Source/SocketIO/Client/SocketIOClientSpec.swift b/Source/SocketIO/Client/SocketIOClientSpec.swift index a514637..5b301fb 100644 --- a/Source/SocketIO/Client/SocketIOClientSpec.swift +++ b/Source/SocketIO/Client/SocketIOClientSpec.swift @@ -23,41 +23,118 @@ // THE SOFTWARE. import Dispatch - +import Foundation /// Defines the interface for a SocketIOClient. -protocol SocketIOClientSpec : class { +public protocol SocketIOClientSpec : class { + // MARK: Properties + + /// A handler that will be called on any event. + var anyHandler: ((SocketAnyEvent) -> ())? { get } + /// The queue that all interaction with the client must be on. var handleQueue: DispatchQueue { get set } + /// The array of handlers for this socket. + var handlers: [SocketEventHandler] { get } + /// The namespace that this socket is currently connected to. /// /// **Must** start with a `/`. var nsp: String { get set } - /// A list of packets that are waiting for binary data. + /// The status of this client. + var status: SocketIOClientStatus { get } + + // MARK: Methods + + /// Connect to the server. The same as calling `connect(timeoutAfter:withHandler:)` with a timeout of 0. /// - /// The way that socket.io works all data should be sent directly after each packet. - /// So this should ideally be an array of one packet waiting for data. - var waitingPackets: [SocketPacket] { get set } + /// Only call after adding your event listeners, unless you know what you're doing. + func connect() + + /// Connect to the server. If we aren't connected after `timeoutAfter` seconds, then `withHandler` is called. + /// + /// Only call after adding your event listeners, unless you know what you're doing. + /// + /// - parameter timeoutAfter: The number of seconds after which if we are not connected we assume the connection + /// has failed. Pass 0 to never timeout. + /// - parameter withHandler: The handler to call when the client fails to connect. + func connect(timeoutAfter: Double, withHandler handler: (() -> ())?) /// Called when the client connects to a namespace. If the client was created with a namespace upfront, /// then this is only called when the client connects to that namespace. + /// + /// - parameter toNamespace: The namespace that was connected to. func didConnect(toNamespace namespace: String) /// Called when the client has disconnected from socket.io. + /// + /// - parameter reason: The reason for the disconnection. func didDisconnect(reason: String) /// Called when the client encounters an error. + /// + /// - parameter reason: The reason for the disconnection. func didError(reason: String) + /// Disconnects the socket. + func disconnect() + + /// Send an event to the server, with optional data items. + /// + /// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error` + /// will be emitted. The structure of the error data is `[eventName, items, theError]` + /// + /// - parameter event: The event to send. + /// - parameter items: The items to send with this event. May be left out. + func emit(_ event: String, _ items: SocketData...) + + /// Call when you wish to tell the server that you've received the event for `ack`. + /// + /// - parameter ack: The ack number. + /// - parameter with: The data for this ack. + func emitAck(_ ack: Int, with items: [Any]) + + /// Sends a message to the server, requesting an ack. + /// + /// **NOTE**: It is up to the server send an ack back, just calling this method does not mean the server will ack. + /// Check that your server's api will ack the event being sent. + /// + /// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error` + /// will be emitted. The structure of the error data is `[eventName, items, theError]` + /// + /// Example: + /// + /// ```swift + /// socket.emitWithAck("myEvent", 1).timingOut(after: 1) {data in + /// ... + /// } + /// ``` + /// + /// - parameter event: The event to send. + /// - parameter items: The items to send with this event. May be left out. + /// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent. + func emitWithAck(_ event: String, _ items: SocketData...) -> OnAckCallback + /// Called when socket.io has acked one of our emits. Causes the corresponding ack callback to be called. + /// + /// - parameter ack: The number for this ack. + /// - parameter data: The data sent back with this ack. func handleAck(_ ack: Int, data: [Any]) /// Called when we get an event from socket.io. + /// + /// - parameter event: The name of the event. + /// - parameter data: The data that was sent with this event. + /// - parameter isInternalMessage: Whether this event was sent internally. If `true` it is always sent to handlers. + /// - parameter withAck: If > 0 then this event expects to get an ack back from the client. func handleEvent(_ event: String, data: [Any], isInternalMessage: Bool, withAck ack: Int) - /// Called on socket.io events. + /// Called on socket.io specific events. + /// + /// - parameter event: The `SocketClientEvent`. + /// - parameter data: The data for this event. func handleClientEvent(_ event: SocketClientEvent, data: [Any]) /// Call when you wish to leave a namespace and return to the default namespace. @@ -69,11 +146,81 @@ protocol SocketIOClientSpec : class { /// /// - parameter namespace: The namespace to join. func joinNamespace(_ namespace: String) + + /// Removes handler(s) for a client event. + /// + /// If you wish to remove a client event handler, call the `off(id:)` with the UUID received from its `on` call. + /// + /// - parameter clientEvent: The event to remove handlers for. + func off(clientEvent event: SocketClientEvent) + + /// Removes handler(s) based on an event name. + /// + /// If you wish to remove a specific event, call the `off(id:)` with the UUID received from its `on` call. + /// + /// - parameter event: The event to remove handlers for. + func off(_ event: String) + + /// Removes a handler with the specified UUID gotten from an `on` or `once` + /// + /// If you want to remove all events for an event, call the off `off(_:)` method with the event name. + /// + /// - parameter id: The UUID of the handler you wish to remove. + func off(id: UUID) + + /// Adds a handler for an event. + /// + /// - parameter event: The event name for this handler. + /// - parameter callback: The callback that will execute when this event is received. + /// - returns: A unique id for the handler that can be used to remove it. + func on(_ event: String, callback: @escaping NormalCallback) -> UUID + + /// Adds a handler for a client event. + /// + /// Example: + /// + /// ```swift + /// socket.on(clientEvent: .connect) {data, ack in + /// ... + /// } + /// ``` + /// + /// - parameter event: The event for this handler. + /// - parameter callback: The callback that will execute when this event is received. + /// - returns: A unique id for the handler that can be used to remove it. + func on(clientEvent event: SocketClientEvent, callback: @escaping NormalCallback) -> UUID + + /// Adds a single-use handler for a client event. + /// + /// - parameter clientEvent: The event for this handler. + /// - parameter callback: The callback that will execute when this event is received. + /// - returns: A unique id for the handler that can be used to remove it. + func once(clientEvent event: SocketClientEvent, callback: @escaping NormalCallback) -> UUID + + /// Adds a single-use handler for an event. + /// + /// - parameter event: The event name for this handler. + /// - parameter callback: The callback that will execute when this event is received. + /// - returns: A unique id for the handler that can be used to remove it. + func once(_ event: String, callback: @escaping NormalCallback) -> UUID + + /// Adds a handler that will be called on every event. + /// + /// - parameter handler: The callback that will execute whenever an event is received. + func onAny(_ handler: @escaping (SocketAnyEvent) -> ()) + + /// Tries to reconnect to the server. + func reconnect() + + /// Removes all handlers. + /// + /// Can be used after disconnecting to break any potential remaining retain cycles. + func removeAllHandlers() } -extension SocketIOClientSpec { +public extension SocketIOClientSpec { /// Default implementation. - func didError(reason: String) { + public func didError(reason: String) { DefaultSocketLogger.Logger.error("\(reason)", type: "SocketIOClient") handleClientEvent(.error, data: [reason]) @@ -82,6 +229,8 @@ extension SocketIOClientSpec { /// The set of events that are generated by the client. public enum SocketClientEvent : String { + // MARK: Cases + /// Emitted when the client connects. This is also called on a successful reconnection. A connect event gets one /// data item: the namespace that was connected to. /// diff --git a/Source/SocketIO/Parse/SocketPacket.swift b/Source/SocketIO/Parse/SocketPacket.swift index a8a8bf1..8aebaf8 100644 --- a/Source/SocketIO/Parse/SocketPacket.swift +++ b/Source/SocketIO/Parse/SocketPacket.swift @@ -25,22 +25,39 @@ import Foundation -struct SocketPacket { - enum PacketType: Int { +/// A struct that represents a socket.io packet. +public struct SocketPacket : CustomStringConvertible { + // MARK: PacketType enum + + /// The type of packets. + public enum PacketType: Int { case connect, disconnect, event, ack, error, binaryEvent, binaryAck } - private let placeholders: Int + // MARK: Properties private static let logType = "SocketPacket" - let nsp: String - let id: Int - let type: PacketType + /// The namespace for this packet. + public let nsp: String - var binary: [Data] - var data: [Any] - var args: [Any] { + /// If > 0 then this packet is using acking. + public let id: Int + + /// The type of this packet. + public let type: PacketType + + /// An array of binary data for this packet. + public internal(set) var binary: [Data] + + /// The data for this event. + /// + /// Note: This includes all data inside of the socket.io packet payload array, which includes the event name for + /// event type packets. + public internal(set) var data: [Any] + + /// Returns the payload for this packet, minus the event name if this is an event or binaryEvent type packet. + public var args: [Any] { if type == .event || type == .binaryEvent && data.count != 0 { return Array(data.dropFirst()) } else { @@ -48,16 +65,21 @@ struct SocketPacket { } } - var description: String { + private let placeholders: Int + + /// A string representation of this packet. + public var description: String { return "SocketPacket {type: \(String(type.rawValue)); data: " + "\(String(describing: data)); id: \(id); placeholders: \(placeholders); nsp: \(nsp)}" } - var event: String { + /// The event name for this packet. + public var event: String { return String(describing: data[0]) } - var packetString: String { + /// A string representation of this packet. + public var packetString: String { return createPacketString() } diff --git a/Source/SocketIO/Parse/SocketParsable.swift b/Source/SocketIO/Parse/SocketParsable.swift index 137491a..578c704 100644 --- a/Source/SocketIO/Parse/SocketParsable.swift +++ b/Source/SocketIO/Parse/SocketParsable.swift @@ -23,7 +23,19 @@ import Foundation /// Defines that a type will be able to parse socket.io-protocol messages. -protocol SocketParsable { +public protocol SocketParsable : class { + // MARK: Properties + + /// A list of packets that are waiting for binary data. + /// + /// The way that socket.io works all data should be sent directly after each packet. + /// So this should ideally be an array of one packet waiting for data. + /// + /// **This should not be modified directly.** + var waitingPackets: [SocketPacket] { get set } + + // MARK: Methods + /// Called when the engine has received some binary data that should be attached to a packet. /// /// Packets binary data should be sent directly after the packet that expects it, so there's confusion over @@ -39,18 +51,28 @@ protocol SocketParsable { func parseSocketMessage(_ message: String) } -enum SocketParsableError : Error { +/// Errors that can be thrown during parsing. +public enum SocketParsableError : Error { + // MARK: Cases + + /// Thrown when a packet received has an invalid data array, or is missing the data array. case invalidDataArray + + /// Thrown when an malformed packet is received. case invalidPacket + + /// Thrown when the parser receives an unknown packet type. case invalidPacketType } -extension SocketParsable where Self: SocketIOClientSpec { +public extension SocketParsable where Self: SocketIOClientSpec { private func isCorrectNamespace(_ nsp: String) -> Bool { return nsp == self.nsp } private func handleConnect(_ packetNamespace: String) { + // If we connected with a namespace, check if we've joined the default namespace first, then switch to the + // other namespace if packetNamespace == "/" && nsp != "/" { joinNamespace(nsp) } else { @@ -79,8 +101,11 @@ extension SocketParsable where Self: SocketIOClientSpec { } } - /// Parses a messsage from the engine, returning a complete SocketPacket or throwing. - func parseString(_ message: String) throws -> SocketPacket { + /// Parses a message from the engine, returning a complete SocketPacket or throwing. + /// + /// - parameter message: The message to parse. + /// - returns: A completed packet, or throwing. + internal func parseString(_ message: String) throws -> SocketPacket { var reader = SocketStringReader(message: message) guard let type = Int(reader.read(count: 1)).flatMap({ SocketPacket.PacketType(rawValue: $0) }) else { @@ -148,7 +173,7 @@ extension SocketParsable where Self: SocketIOClientSpec { /// Called when the engine has received a string that should be parsed into a socket.io packet. /// /// - parameter message: The string that needs parsing. - func parseSocketMessage(_ message: String) { + public func parseSocketMessage(_ message: String) { guard !message.isEmpty else { return } DefaultSocketLogger.Logger.log("Parsing \(message)", type: "SocketParser") @@ -171,7 +196,7 @@ extension SocketParsable where Self: SocketIOClientSpec { /// into the correct placeholder. /// /// - parameter data: The data that should be attached to a packet. - func parseBinaryData(_ data: Data) { + public func parseBinaryData(_ data: Data) { guard !waitingPackets.isEmpty else { DefaultSocketLogger.Logger.error("Got data when not remaking packet", type: "SocketParser") return From 321bb186df02fe1cd82e3ce3f073dfa7cf698e14 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sat, 30 Sep 2017 13:19:49 -0400 Subject: [PATCH 10/23] Allow changing config after init but before connect. Fixes #680 --- SocketIO-MacTests/SocketSideEffectTest.swift | 19 +++++ Source/SocketIO/Client/SocketIOClient.swift | 69 ++++++++++++------- .../SocketIO/Client/SocketIOClientSpec.swift | 3 + 3 files changed, 67 insertions(+), 24 deletions(-) diff --git a/SocketIO-MacTests/SocketSideEffectTest.swift b/SocketIO-MacTests/SocketSideEffectTest.swift index f2e43dd..b92ce62 100644 --- a/SocketIO-MacTests/SocketSideEffectTest.swift +++ b/SocketIO-MacTests/SocketSideEffectTest.swift @@ -351,6 +351,25 @@ class SocketSideEffectTest: XCTestCase { waitForExpectations(timeout: 0.2) } + func testSettingConfigAfterInit() { + socket.setTestStatus(.notConnected) + socket.config.insert(.log(true)) + + XCTAssertTrue(DefaultSocketLogger.Logger.log, "It should set logging to true after creation") + + socket.config = [.log(false), .nsp("/test")] + + XCTAssertFalse(DefaultSocketLogger.Logger.log, "It should set logging to false after creation") + XCTAssertEqual(socket.nsp, "/test", "It should set the namespace after creation") + } + + func testSettingConfigAfterInitWhenConnectedIgnoresChanges() { + socket.config = [.log(true), .nsp("/test")] + + XCTAssertFalse(DefaultSocketLogger.Logger.log, "It should set logging to false after creation") + XCTAssertEqual(socket.nsp, "/", "It should set the namespace after creation") + } + let data = "test".data(using: String.Encoding.utf8)! let data2 = "test2".data(using: String.Encoding.utf8)! private var socket: SocketIOClient! diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index 22b122d..54ff64e 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -51,7 +51,24 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So public var nsp = "/" /// The configuration for this client. - public var config: SocketIOClientConfiguration + /// + /// **This cannot be set after calling one of the connect methods**. + public var config: SocketIOClientConfiguration { + didSet { + guard status == .notConnected else { + DefaultSocketLogger.Logger.error("Tried setting config after calling connect", + type: SocketIOClient.logType) + return + } + + if socketURL.absoluteString.hasPrefix("https://") { + config.insert(.secure(true)) + } + + config.insert(.path("/socket.io/"), replacing: false) + setConfigs() + } + } /// If `true`, this client will try and reconnect on any disconnects. @objc @@ -130,32 +147,11 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So self.config.insert(.secure(true)) } - for option in config { - switch option { - case let .reconnects(reconnects): - self.reconnects = reconnects - case let .reconnectAttempts(attempts): - reconnectAttempts = attempts - case let .reconnectWait(wait): - reconnectWait = abs(wait) - case let .nsp(nsp): - self.nsp = nsp - case let .log(log): - DefaultSocketLogger.Logger.log = log - case let .logger(logger): - DefaultSocketLogger.Logger = logger - case let .handleQueue(queue): - handleQueue = queue - case let .forceNew(force): - forceNew = force - default: - continue - } - } - self.config.insert(.path("/socket.io/"), replacing: false) super.init() + + setConfigs() } /// Not so type safe way to create a SocketIOClient, meant for Objective-C compatiblity. @@ -670,6 +666,31 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So handleQueue.asyncAfter(deadline: DispatchTime.now() + Double(reconnectWait), execute: _tryReconnect) } + private func setConfigs() { + for option in config { + switch option { + case let .reconnects(reconnects): + self.reconnects = reconnects + case let .reconnectAttempts(attempts): + reconnectAttempts = attempts + case let .reconnectWait(wait): + reconnectWait = abs(wait) + case let .nsp(nsp): + self.nsp = nsp + case let .log(log): + DefaultSocketLogger.Logger.log = log + case let .logger(logger): + DefaultSocketLogger.Logger = logger + case let .handleQueue(queue): + handleQueue = queue + case let .forceNew(force): + forceNew = force + default: + continue + } + } + } + // Test properties var testHandlers: [SocketEventHandler] { diff --git a/Source/SocketIO/Client/SocketIOClientSpec.swift b/Source/SocketIO/Client/SocketIOClientSpec.swift index 5b301fb..0616a6e 100644 --- a/Source/SocketIO/Client/SocketIOClientSpec.swift +++ b/Source/SocketIO/Client/SocketIOClientSpec.swift @@ -32,6 +32,9 @@ public protocol SocketIOClientSpec : class { /// A handler that will be called on any event. var anyHandler: ((SocketAnyEvent) -> ())? { get } + /// The configuration for this client. + var config: SocketIOClientConfiguration { get set } + /// The queue that all interaction with the client must be on. var handleQueue: DispatchQueue { get set } From 28cc8eef192129805e59efd34b022db9b2be1c98 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sat, 30 Sep 2017 13:32:44 -0400 Subject: [PATCH 11/23] Don't set configs after connect --- Source/SocketIO/Client/SocketIOClient.swift | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index 54ff64e..5ef4f56 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -54,18 +54,24 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So /// /// **This cannot be set after calling one of the connect methods**. public var config: SocketIOClientConfiguration { - didSet { + get { + return _config + } + + set { guard status == .notConnected else { DefaultSocketLogger.Logger.error("Tried setting config after calling connect", type: SocketIOClient.logType) return } + _config = newValue + if socketURL.absoluteString.hasPrefix("https://") { - config.insert(.secure(true)) + _config.insert(.secure(true)) } - config.insert(.path("/socket.io/"), replacing: false) + _config.insert(.path("/socket.io/"), replacing: false) setConfigs() } } @@ -130,6 +136,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So private(set) var currentAck = -1 private(set) var reconnectAttempts = -1 + private var _config: SocketIOClientConfiguration private var currentReconnectAttempt = 0 private var reconnecting = false @@ -140,14 +147,14 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So /// - parameter socketURL: The url of the socket.io server. /// - parameter config: The config for this socket. public init(socketURL: URL, config: SocketIOClientConfiguration = []) { - self.config = config + self._config = config self.socketURL = socketURL if socketURL.absoluteString.hasPrefix("https://") { - self.config.insert(.secure(true)) + self._config.insert(.secure(true)) } - self.config.insert(.path("/socket.io/"), replacing: false) + self._config.insert(.path("/socket.io/"), replacing: false) super.init() From 819735efbf0597a6f38823e7f3e2f0a55111fd28 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sat, 30 Sep 2017 13:48:35 -0400 Subject: [PATCH 12/23] Fix documentation --- Source/SocketIO/Client/SocketIOClient.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index 5ef4f56..256b4d1 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -296,7 +296,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So /// Same as emit, but meant for Objective-C /// /// - parameter event: The event to send. - /// - parameter with: The items to send with this event. May be left out. + /// - parameter with: The items to send with this event. Send an empty array to send no data. @objc open func emit(_ event: String, with items: [Any]) { guard status == .connected else { From 42d96d96fd9c25f7f4e5b5a4f2f616489fcbda0b Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Sun, 24 Sep 2017 16:16:00 +0200 Subject: [PATCH 13/23] Remove StarScream --- .gitmodules | 4 ---- Source/Starscream | 1 - 2 files changed, 5 deletions(-) delete mode 160000 Source/Starscream diff --git a/.gitmodules b/.gitmodules index 63f6f1b..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +0,0 @@ -[submodule "Source/Starscream"] - path = Source/Starscream - url = https://github.com/nuclearace/Starscream - branch = socket.io-dev diff --git a/Source/Starscream b/Source/Starscream deleted file mode 160000 index 24e71ab..0000000 --- a/Source/Starscream +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 24e71ab1c8855dbc16325d5cca6bceae918d5ea8 From 6bff01a3b56ac231a97a19210bddd40f2586cc46 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Sun, 24 Sep 2017 16:31:12 +0200 Subject: [PATCH 14/23] Proof of concept --- Cartfile | 1 + Cartfile.resolved | 1 + .../project.pbxproj | 155 ++++++------------ .../Client/SocketIOClientOption.swift | 2 +- Source/SocketIO/Engine/SocketEngine.swift | 6 +- Source/SocketIO/Engine/SocketEngineSpec.swift | 2 +- .../Engine/SocketEngineWebsocket.swift | 2 +- Source/SocketIO/Util/SSLSecurity.swift | 30 ++++ Source/SocketIO/Util/SocketExtensions.swift | 2 +- 9 files changed, 91 insertions(+), 110 deletions(-) create mode 100644 Cartfile create mode 100644 Cartfile.resolved create mode 100644 Source/SocketIO/Util/SSLSecurity.swift diff --git a/Cartfile b/Cartfile new file mode 100644 index 0000000..2ef3a0d --- /dev/null +++ b/Cartfile @@ -0,0 +1 @@ +github "daltoniam/Starscream" ~> 2.0 \ No newline at end of file diff --git a/Cartfile.resolved b/Cartfile.resolved new file mode 100644 index 0000000..be023fb --- /dev/null +++ b/Cartfile.resolved @@ -0,0 +1 @@ +github "daltoniam/Starscream" "2.1.1" diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index 3b09edc..bc243c9 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -30,12 +30,16 @@ 7472C65F1BCAC46E003CA70D /* SocketSideEffectTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65E1BCAC46E003CA70D /* SocketSideEffectTest.swift */; }; 7472C6601BCAC46E003CA70D /* SocketSideEffectTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65E1BCAC46E003CA70D /* SocketSideEffectTest.swift */; }; 747BC59F1D5F9BA200CA5FA4 /* SocketIOClientConfigurationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 747BC59E1D5F9BA200CA5FA4 /* SocketIOClientConfigurationTest.swift */; }; - 74DA21721F094408009C19EE /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 74DA21711F094408009C19EE /* libz.tbd */; }; 74DA21741F09440F009C19EE /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 74DA21731F09440F009C19EE /* libz.tbd */; }; - 74DA21761F094417009C19EE /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 74DA21751F094417009C19EE /* libz.tbd */; }; 74DA217C1F09457B009C19EE /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 74DA21731F09440F009C19EE /* libz.tbd */; }; 74F124F01BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */; }; 74F124F11BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */; }; + 9432E0071F77F7CA006AF628 /* SSLSecurity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9432E0061F77F7CA006AF628 /* SSLSecurity.swift */; }; + 9432E00A1F77F87D006AF628 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9432E0091F77F87D006AF628 /* Starscream.framework */; }; + 9432E00C1F77F883006AF628 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9432E00B1F77F883006AF628 /* Starscream.framework */; }; + 9432E00E1F77F889006AF628 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9432E00D1F77F889006AF628 /* Starscream.framework */; }; + 9432E00F1F77F8C4006AF628 /* SSLSecurity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9432E0061F77F7CA006AF628 /* SSLSecurity.swift */; }; + 9432E0101F77F8C4006AF628 /* SSLSecurity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9432E0061F77F7CA006AF628 /* SSLSecurity.swift */; }; DD52B048C71D724ABBD18C71 /* SocketTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD52BDC9E66AADA2CC5E8246 /* SocketTypes.swift */; }; DD52B06F898CD9164AC8F80E /* SocketAnyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD52B5A9DE10C7A8AD35617F /* SocketAnyEvent.swift */; }; DD52B099A5166C5FF975FAB5 /* SocketClientManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD52B282975446C9A9C56D7B /* SocketClientManager.swift */; }; @@ -126,41 +130,6 @@ remoteGlobalIDString = 576349FA1BD9B46A00E19CD7; remoteInfo = "SocketIO-tvOS"; }; - 74B3C8391F7F3ECE007D96C8 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 33CCF0921F5DDC030099B092; - remoteInfo = StarscreamSocketIO; - }; - 74B3C83B1F7F3ECE007D96C8 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 335FA2021F5DF71D00F6D2EC; - remoteInfo = "Starscream Tests"; - }; - 74B3C8411F7F3F93007D96C8 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 33CCF0841F5DDC030099B092; - remoteInfo = StarscreamSocketIO; - }; - 74B3C8431F7F3F98007D96C8 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 33CCF0841F5DDC030099B092; - remoteInfo = StarscreamSocketIO; - }; - 74B3C8451F7F3F9C007D96C8 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 33CCF0841F5DDC030099B092; - remoteInfo = StarscreamSocketIO; - }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ @@ -182,15 +151,16 @@ 742D150B1CA5794B00BD987D /* SocketObjectiveCTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SocketObjectiveCTest.m; sourceTree = ""; }; 74321DC91C2D939A00CF6F43 /* SocketAckManagerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketAckManagerTest.swift; sourceTree = ""; }; 74321DCA1C2D939A00CF6F43 /* SocketParserTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketParserTest.swift; sourceTree = ""; }; - 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Starscream.xcodeproj; path = Source/Starscream/Starscream.xcodeproj; sourceTree = ""; }; 7472C65B1BCAB53E003CA70D /* SocketNamespacePacketTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketNamespacePacketTest.swift; sourceTree = ""; }; 7472C65E1BCAC46E003CA70D /* SocketSideEffectTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketSideEffectTest.swift; sourceTree = ""; }; 747BC59E1D5F9BA200CA5FA4 /* SocketIOClientConfigurationTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketIOClientConfigurationTest.swift; sourceTree = ""; }; - 74DA21711F094408009C19EE /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; }; 74DA21731F09440F009C19EE /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; - 74DA21751F094417009C19EE /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS10.2.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; }; 74DA217D1F0945E9009C19EE /* libcommonCrypto.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcommonCrypto.tbd; path = usr/lib/system/libcommonCrypto.tbd; sourceTree = SDKROOT; }; 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketBasicPacketTest.swift; sourceTree = ""; }; + 9432E0061F77F7CA006AF628 /* SSLSecurity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSLSecurity.swift; sourceTree = ""; }; + 9432E0091F77F87D006AF628 /* Starscream.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Starscream.framework; path = Carthage/Build/iOS/Starscream.framework; sourceTree = ""; }; + 9432E00B1F77F883006AF628 /* Starscream.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Starscream.framework; path = Carthage/Build/Mac/Starscream.framework; sourceTree = ""; }; + 9432E00D1F77F889006AF628 /* Starscream.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Starscream.framework; path = Carthage/Build/tvOS/Starscream.framework; sourceTree = ""; }; DD52B078DB0A3C3D1BB507CD /* SocketIOClientOption.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketIOClientOption.swift; sourceTree = ""; }; DD52B09F7984E730513AB7E5 /* SocketAckManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketAckManager.swift; sourceTree = ""; }; DD52B1D9BC4AE46D38D827DE /* SocketIOClientStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketIOClientStatus.swift; sourceTree = ""; }; @@ -220,8 +190,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 74DA21721F094408009C19EE /* libz.tbd in Frameworks */, 6CA08A961D615C040061FD2A /* Security.framework in Frameworks */, + 9432E00A1F77F87D006AF628 /* Starscream.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -239,6 +209,7 @@ files = ( 74DA21741F09440F009C19EE /* libz.tbd in Frameworks */, 6CA08A981D615C0B0061FD2A /* Security.framework in Frameworks */, + 9432E00C1F77F883006AF628 /* Starscream.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -255,8 +226,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 74DA21761F094417009C19EE /* libz.tbd in Frameworks */, 6CA08A9A1D615C140061FD2A /* Security.framework in Frameworks */, + 9432E00E1F77F889006AF628 /* Starscream.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -274,7 +245,6 @@ 572EF20D1B51F12F00EEBB58 = { isa = PBXGroup; children = ( - 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */, 6CA08A9B1D615C190061FD2A /* Frameworks */, 572EF21A1B51F16C00EEBB58 /* Products */, 572EF21B1B51F16C00EEBB58 /* SocketIO-iOS */, @@ -370,10 +340,11 @@ 6CA08A9B1D615C190061FD2A /* Frameworks */ = { isa = PBXGroup; children = ( + 9432E0091F77F87D006AF628 /* Starscream.framework */, + 9432E00B1F77F883006AF628 /* Starscream.framework */, + 9432E00D1F77F889006AF628 /* Starscream.framework */, 74DA217D1F0945E9009C19EE /* libcommonCrypto.tbd */, - 74DA21751F094417009C19EE /* libz.tbd */, 74DA21731F09440F009C19EE /* libz.tbd */, - 74DA21711F094408009C19EE /* libz.tbd */, 6CA08A9E1D615C340061FD2A /* tvOS */, 6CA08A9D1D615C2C0061FD2A /* Mac */, 6CA08A9C1D615C270061FD2A /* iOS */, @@ -405,15 +376,6 @@ name = tvOS; sourceTree = ""; }; - 74638B5B1F111CD000F5E1FF /* Products */ = { - isa = PBXGroup; - children = ( - 74B3C83A1F7F3ECE007D96C8 /* StarscreamSocketIO.framework */, - 74B3C83C1F7F3ECE007D96C8 /* Starscream Tests.xctest */, - ); - name = Products; - sourceTree = ""; - }; DD52B1D10D761CEF3944A6BC /* Util */ = { isa = PBXGroup; children = ( @@ -422,6 +384,7 @@ DD52B471D780013E18DF9335 /* SocketExtensions.swift */, DD52BA240D139F72633D4159 /* SocketStringReader.swift */, DD52B282975446C9A9C56D7B /* SocketClientManager.swift */, + 9432E0061F77F7CA006AF628 /* SSLSecurity.swift */, ); name = Util; path = Source/SocketIO/Util; @@ -518,7 +481,6 @@ buildRules = ( ); dependencies = ( - 74B3C8461F7F3F9C007D96C8 /* PBXTargetDependency */, ); name = "SocketIO-iOS"; productName = "SocketIO-iOS"; @@ -555,7 +517,6 @@ buildRules = ( ); dependencies = ( - 74B3C8441F7F3F98007D96C8 /* PBXTargetDependency */, ); name = "SocketIO-Mac"; productName = "SocketIO-Mac"; @@ -592,7 +553,6 @@ buildRules = ( ); dependencies = ( - 74B3C8421F7F3F93007D96C8 /* PBXTargetDependency */, ); name = "SocketIO-tvOS"; productName = "SocketIO-iOS"; @@ -653,12 +613,6 @@ mainGroup = 572EF20D1B51F12F00EEBB58; productRefGroup = 572EF21A1B51F16C00EEBB58 /* Products */; projectDirPath = ""; - projectReferences = ( - { - ProductGroup = 74638B5B1F111CD000F5E1FF /* Products */; - ProjectRef = 74638B5A1F111CD000F5E1FF /* Starscream.xcodeproj */; - }, - ); projectRoot = ""; targets = ( 572EF2181B51F16C00EEBB58 /* SocketIO-iOS */, @@ -671,23 +625,6 @@ }; /* End PBXProject section */ -/* Begin PBXReferenceProxy section */ - 74B3C83A1F7F3ECE007D96C8 /* StarscreamSocketIO.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = StarscreamSocketIO.framework; - remoteRef = 74B3C8391F7F3ECE007D96C8 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 74B3C83C1F7F3ECE007D96C8 /* Starscream Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "Starscream Tests.xctest"; - remoteRef = 74B3C83B1F7F3ECE007D96C8 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - /* Begin PBXResourcesBuildPhase section */ 572EF2171B51F16C00EEBB58 /* Resources */ = { isa = PBXResourcesBuildPhase; @@ -749,6 +686,7 @@ DD52B06F898CD9164AC8F80E /* SocketAnyEvent.swift in Sources */, DD52B16128003D74FC23A01F /* SocketIOClient.swift in Sources */, DD52BDB51FE41BAB49073BEF /* SocketEventHandler.swift in Sources */, + 9432E0071F77F7CA006AF628 /* SSLSecurity.swift in Sources */, DD52BB88BD4C5641CFD2E8D4 /* SocketIOClientSpec.swift in Sources */, DD52B1FEE4C81226884B1E67 /* SocketIOClientOption.swift in Sources */, DD52B6E44917CA5DFC3CE6B5 /* SocketIOClientStatus.swift in Sources */, @@ -789,6 +727,7 @@ DD52BB69B6D260035B652CA4 /* SocketAnyEvent.swift in Sources */, DD52BF924BEF05E1235CFD29 /* SocketIOClient.swift in Sources */, DD52BFEB4DBD3BF8D93DAEFF /* SocketEventHandler.swift in Sources */, + 9432E00F1F77F8C4006AF628 /* SSLSecurity.swift in Sources */, DD52BB9A3E42FF2DD6BE7C2F /* SocketIOClientSpec.swift in Sources */, DD52B2AFE7D46039C7AE4D19 /* SocketIOClientOption.swift in Sources */, DD52BE4D1E6BB752CD9614A6 /* SocketIOClientStatus.swift in Sources */, @@ -833,6 +772,7 @@ DD52B6BE1D398DBD144C4D14 /* SocketAnyEvent.swift in Sources */, DD52B26DA9E4D566276B7E49 /* SocketIOClient.swift in Sources */, DD52B27DABA4C475B850A326 /* SocketEventHandler.swift in Sources */, + 9432E0101F77F8C4006AF628 /* SSLSecurity.swift in Sources */, DD52B4223DCCB75630441370 /* SocketIOClientSpec.swift in Sources */, DD52B6FC2F0A6A3106FFCBE3 /* SocketIOClientOption.swift in Sources */, DD52B3D941DB2A0C678F8251 /* SocketIOClientStatus.swift in Sources */, @@ -876,21 +816,6 @@ target = 576349FA1BD9B46A00E19CD7 /* SocketIO-tvOS */; targetProxy = 57634A3D1BD9B4B800E19CD7 /* PBXContainerItemProxy */; }; - 74B3C8421F7F3F93007D96C8 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = StarscreamSocketIO; - targetProxy = 74B3C8411F7F3F93007D96C8 /* PBXContainerItemProxy */; - }; - 74B3C8441F7F3F98007D96C8 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = StarscreamSocketIO; - targetProxy = 74B3C8431F7F3F98007D96C8 /* PBXContainerItemProxy */; - }; - 74B3C8461F7F3F9C007D96C8 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = StarscreamSocketIO; - targetProxy = 74B3C8451F7F3F9C007D96C8 /* PBXContainerItemProxy */; - }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -930,7 +855,7 @@ ONLY_ACTIVE_ARCH = YES; PRODUCT_NAME = SocketIO; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 3.0; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -969,7 +894,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SocketIO; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 3.0; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -1003,6 +928,10 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_STRICT_OBJC_MSGSEND = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -1027,7 +956,6 @@ SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = $SRCROOT/zlib; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; @@ -1064,6 +992,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -1080,7 +1012,6 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = $SRCROOT/zlib; - SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; @@ -1216,6 +1147,11 @@ ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + "$(PROJECT_DIR)/Carthage/Build/Mac", + ); FRAMEWORK_VERSION = A; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; @@ -1245,7 +1181,7 @@ SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_SWIFT3_OBJC_INFERENCE = On; SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1282,6 +1218,11 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + "$(PROJECT_DIR)/Carthage/Build/Mac", + ); FRAMEWORK_VERSION = A; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; @@ -1303,7 +1244,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = ""; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_SWIFT3_OBJC_INFERENCE = On; SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1365,7 +1306,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_SWIFT3_OBJC_INFERENCE = On; SWIFT_VERSION = 4.0; }; name = Debug; @@ -1417,7 +1358,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_SWIFT3_OBJC_INFERENCE = On; SWIFT_VERSION = 4.0; }; name = Release; @@ -1450,6 +1391,10 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_STRICT_OBJC_MSGSEND = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/tvOS", + ); GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -1512,6 +1457,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/tvOS", + ); GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; diff --git a/Source/SocketIO/Client/SocketIOClientOption.swift b/Source/SocketIO/Client/SocketIOClientOption.swift index e258bbd..10b521e 100644 --- a/Source/SocketIO/Client/SocketIOClientOption.swift +++ b/Source/SocketIO/Client/SocketIOClientOption.swift @@ -23,7 +23,7 @@ // THE SOFTWARE. import Foundation -import StarscreamSocketIO +import Starscream protocol ClientOption : CustomStringConvertible, Equatable { func getSocketIOOptionValue() -> Any diff --git a/Source/SocketIO/Engine/SocketEngine.swift b/Source/SocketIO/Engine/SocketEngine.swift index 9553757..c07ffe4 100644 --- a/Source/SocketIO/Engine/SocketEngine.swift +++ b/Source/SocketIO/Engine/SocketEngine.swift @@ -24,7 +24,7 @@ import Dispatch import Foundation -import StarscreamSocketIO +import Starscream /// The class that handles the engine.io protocol and transports. /// See `SocketEnginePollable` and `SocketEngineWebsocket` for transport specific methods. @@ -134,7 +134,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll private var pongsMissedMax = 0 private var probeWait = ProbeWaitQueue() private var secure = false - private var security: SSLSecurity? + private var security: SocketIO.SSLSecurity? private var selfSigned = false // MARK: Initializers @@ -330,7 +330,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll ws?.enableCompression = compress ws?.delegate = self ws?.disableSSLCertValidation = selfSigned - ws?.security = security + ws?.security = security?.security ws?.connect() } diff --git a/Source/SocketIO/Engine/SocketEngineSpec.swift b/Source/SocketIO/Engine/SocketEngineSpec.swift index 0f549db..4dba805 100644 --- a/Source/SocketIO/Engine/SocketEngineSpec.swift +++ b/Source/SocketIO/Engine/SocketEngineSpec.swift @@ -24,7 +24,7 @@ // import Foundation -import StarscreamSocketIO +import Starscream /// Specifies a SocketEngine. @objc public protocol SocketEngineSpec { diff --git a/Source/SocketIO/Engine/SocketEngineWebsocket.swift b/Source/SocketIO/Engine/SocketEngineWebsocket.swift index 7e432aa..75da709 100644 --- a/Source/SocketIO/Engine/SocketEngineWebsocket.swift +++ b/Source/SocketIO/Engine/SocketEngineWebsocket.swift @@ -24,7 +24,7 @@ // import Foundation -import StarscreamSocketIO +import Starscream /// Protocol that is used to implement socket.io WebSocket support public protocol SocketEngineWebsocket : SocketEngineSpec, WebSocketDelegate { diff --git a/Source/SocketIO/Util/SSLSecurity.swift b/Source/SocketIO/Util/SSLSecurity.swift new file mode 100644 index 0000000..05f424f --- /dev/null +++ b/Source/SocketIO/Util/SSLSecurity.swift @@ -0,0 +1,30 @@ +// +// SSLSecurity.swift +// SocketIO-iOS +// +// Created by Lukas Schmidt on 24.09.17. +// + +import Starscream + +public class SSLSecurity: NSObject { + public let security: Starscream.SSLSecurity + + init(security: Starscream.SSLSecurity) { + self.security = security + } + + public convenience init(usePublicKeys: Bool = true) { + let security = Starscream.SSLSecurity(usePublicKeys: usePublicKeys) + self.init(security: security) + } + + public convenience init(certs: [SSLCert], usePublicKeys: Bool) { + let security = Starscream.SSLSecurity(certs: certs, usePublicKeys: usePublicKeys) + self.init(security: security) + } + + public func isValid(_ trust: SecTrust, domain: String?) -> Bool { + return security.isValid(trust, domain: domain) + } +} diff --git a/Source/SocketIO/Util/SocketExtensions.swift b/Source/SocketIO/Util/SocketExtensions.swift index 3959f6d..e80cf6e 100644 --- a/Source/SocketIO/Util/SocketExtensions.swift +++ b/Source/SocketIO/Util/SocketExtensions.swift @@ -23,7 +23,7 @@ // THE SOFTWARE. import Foundation -import StarscreamSocketIO +import Starscream enum JSONError : Error { case notArray From 883b0f3ba4b6d61b15fe27a6065d3ba5d706fa18 Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Sun, 24 Sep 2017 16:43:19 +0200 Subject: [PATCH 15/23] Fixes Mac build --- Socket.IO-Client-Swift.xcodeproj/project.pbxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index bc243c9..55ff5e2 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -1149,7 +1149,6 @@ ENABLE_TESTABILITY = YES; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", "$(PROJECT_DIR)/Carthage/Build/Mac", ); FRAMEWORK_VERSION = A; @@ -1220,7 +1219,6 @@ ENABLE_TESTABILITY = YES; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", "$(PROJECT_DIR)/Carthage/Build/Mac", ); FRAMEWORK_VERSION = A; From fb02d154e16f8262d5f1329dcced611baff62984 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sat, 30 Sep 2017 18:05:02 -0400 Subject: [PATCH 16/23] Go back to Starscream 2.1.1 Add objc Fix some warnings --- .travis.yml | 5 +- Package.swift | 4 +- .../project.pbxproj | 64 +++++++++++++++++-- SocketIO-MacTests/SocketObjectiveCTest.m | 1 - SocketIO-MacTests/SocketSideEffectTest.swift | 1 - Source/SocketIO/Engine/SocketEngine.swift | 12 ++-- .../Engine/SocketEngineWebsocket.swift | 4 +- Source/SocketIO/Util/SSLSecurity.swift | 2 + 8 files changed, 73 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 46c3a79..fe1c178 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,17 @@ language: objective-c xcode_project: Socket.IO-Client-Swift.xcodeproj # path to your xcodeproj folder -xcode_scheme: SocketIO-iOS +xcode_scheme: SocketIO-Mac osx_image: xcode9 branches: only: - master - development - - swift4.0 before_install: - brew update - brew outdated xctool || brew upgrade xctool + - brew outdated carthage || brew upgrade carthage script: + - carthage update - xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build test -quiet # - xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build-for-testing -quiet # - xctool -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac run-tests --parallelize diff --git a/Package.swift b/Package.swift index 34c1298..61ff8a5 100644 --- a/Package.swift +++ b/Package.swift @@ -8,9 +8,9 @@ let package = Package( .library(name: "SocketIO", targets: ["SocketIO"]) ], dependencies: [ - .package(url: "https://github.com/nuclearace/Starscream", .upToNextMajor(from: "9.0.0")), + .package(url: "https://github.com/daltoniam/Starscream", .upToNextMajor(from: "2.1.1")), ], targets: [ - .target(name: "SocketIO", dependencies: ["StarscreamSocketIO"], exclude: ["Sources/Starscream"]) + .target(name: "SocketIO", dependencies: ["Starscream"]) ] ) diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index 55ff5e2..c870e3f 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -30,13 +30,19 @@ 7472C65F1BCAC46E003CA70D /* SocketSideEffectTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65E1BCAC46E003CA70D /* SocketSideEffectTest.swift */; }; 7472C6601BCAC46E003CA70D /* SocketSideEffectTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65E1BCAC46E003CA70D /* SocketSideEffectTest.swift */; }; 747BC59F1D5F9BA200CA5FA4 /* SocketIOClientConfigurationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 747BC59E1D5F9BA200CA5FA4 /* SocketIOClientConfigurationTest.swift */; }; + 749FA1961F811190002FBB30 /* SocketAckManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74321DC91C2D939A00CF6F43 /* SocketAckManagerTest.swift */; }; + 749FA1971F811190002FBB30 /* SocketIOClientConfigurationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 747BC59E1D5F9BA200CA5FA4 /* SocketIOClientConfigurationTest.swift */; }; + 749FA1981F811190002FBB30 /* SocketObjectiveCTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 742D150B1CA5794B00BD987D /* SocketObjectiveCTest.m */; }; + 749FA1991F811190002FBB30 /* SocketParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74321DCA1C2D939A00CF6F43 /* SocketParserTest.swift */; }; + 749FA1A61F81152B002FBB30 /* Starscream.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9432E00B1F77F883006AF628 /* Starscream.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 74D0F58E1F804FED0037C4DC /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 74D0F58D1F804FED0037C4DC /* libz.tbd */; }; + 74D0F5961F8053950037C4DC /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9432E00B1F77F883006AF628 /* Starscream.framework */; }; 74DA21741F09440F009C19EE /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 74DA21731F09440F009C19EE /* libz.tbd */; }; 74DA217C1F09457B009C19EE /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 74DA21731F09440F009C19EE /* libz.tbd */; }; 74F124F01BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */; }; 74F124F11BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */; }; 9432E0071F77F7CA006AF628 /* SSLSecurity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9432E0061F77F7CA006AF628 /* SSLSecurity.swift */; }; 9432E00A1F77F87D006AF628 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9432E0091F77F87D006AF628 /* Starscream.framework */; }; - 9432E00C1F77F883006AF628 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9432E00B1F77F883006AF628 /* Starscream.framework */; }; 9432E00E1F77F889006AF628 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9432E00D1F77F889006AF628 /* Starscream.framework */; }; 9432E00F1F77F8C4006AF628 /* SSLSecurity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9432E0061F77F7CA006AF628 /* SSLSecurity.swift */; }; 9432E0101F77F8C4006AF628 /* SSLSecurity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9432E0061F77F7CA006AF628 /* SSLSecurity.swift */; }; @@ -132,6 +138,19 @@ }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + 749FA1A51F811521002FBB30 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 749FA1A61F81152B002FBB30 /* Starscream.framework in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 572EF2191B51F16C00EEBB58 /* SocketIO.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SocketIO.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 572EF21D1B51F16C00EEBB58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -154,6 +173,9 @@ 7472C65B1BCAB53E003CA70D /* SocketNamespacePacketTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketNamespacePacketTest.swift; sourceTree = ""; }; 7472C65E1BCAC46E003CA70D /* SocketSideEffectTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketSideEffectTest.swift; sourceTree = ""; }; 747BC59E1D5F9BA200CA5FA4 /* SocketIOClientConfigurationTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketIOClientConfigurationTest.swift; sourceTree = ""; }; + 749FA19F1F8112E7002FBB30 /* Starscream.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = Starscream.framework.dSYM; path = Carthage/Build/Mac/Starscream.framework.dSYM; sourceTree = ""; }; + 749FA1A11F811408002FBB30 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 74D0F58D1F804FED0037C4DC /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; }; 74DA21731F09440F009C19EE /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 74DA217D1F0945E9009C19EE /* libcommonCrypto.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcommonCrypto.tbd; path = usr/lib/system/libcommonCrypto.tbd; sourceTree = SDKROOT; }; 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketBasicPacketTest.swift; sourceTree = ""; }; @@ -190,6 +212,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 74D0F58E1F804FED0037C4DC /* libz.tbd in Frameworks */, 6CA08A961D615C040061FD2A /* Security.framework in Frameworks */, 9432E00A1F77F87D006AF628 /* Starscream.framework in Frameworks */, ); @@ -209,7 +232,7 @@ files = ( 74DA21741F09440F009C19EE /* libz.tbd in Frameworks */, 6CA08A981D615C0B0061FD2A /* Security.framework in Frameworks */, - 9432E00C1F77F883006AF628 /* Starscream.framework in Frameworks */, + 74D0F5961F8053950037C4DC /* Starscream.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -340,6 +363,9 @@ 6CA08A9B1D615C190061FD2A /* Frameworks */ = { isa = PBXGroup; children = ( + 749FA1A11F811408002FBB30 /* Foundation.framework */, + 749FA19F1F8112E7002FBB30 /* Starscream.framework.dSYM */, + 74D0F58D1F804FED0037C4DC /* libz.tbd */, 9432E0091F77F87D006AF628 /* Starscream.framework */, 9432E00B1F77F883006AF628 /* Starscream.framework */, 9432E00D1F77F889006AF628 /* Starscream.framework */, @@ -494,6 +520,7 @@ 572EF2201B51F16C00EEBB58 /* Sources */, 572EF2211B51F16C00EEBB58 /* Frameworks */, 572EF2221B51F16C00EEBB58 /* Resources */, + 749FA19A1F8111A6002FBB30 /* ShellScript */, ); buildRules = ( ); @@ -530,6 +557,7 @@ 572EF23E1B51F18A00EEBB58 /* Sources */, 572EF23F1B51F18A00EEBB58 /* Frameworks */, 572EF2401B51F18A00EEBB58 /* Resources */, + 749FA1A51F811521002FBB30 /* CopyFiles */, ); buildRules = ( ); @@ -670,6 +698,24 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 749FA19A1F8111A6002FBB30 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "$(SRCROOT)/Carthage/Build/iOS/Starscream.framework", + ); + outputPaths = ( + "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Starscream.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/usr/local/bin/carthage copy-frameworks"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 572EF2141B51F16C00EEBB58 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -705,6 +751,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 749FA1961F811190002FBB30 /* SocketAckManagerTest.swift in Sources */, + 749FA1971F811190002FBB30 /* SocketIOClientConfigurationTest.swift in Sources */, + 749FA1981F811190002FBB30 /* SocketObjectiveCTest.m in Sources */, + 749FA1991F811190002FBB30 /* SocketParserTest.swift in Sources */, 7472C65F1BCAC46E003CA70D /* SocketSideEffectTest.swift in Sources */, 741F39EE1BD025D80026C9CC /* SocketEngineTest.swift in Sources */, 74F124F01BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */, @@ -1180,7 +1230,7 @@ SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1242,7 +1292,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = ""; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1275,6 +1325,7 @@ FRAMEWORK_SEARCH_PATHS = ( "$(DEVELOPER_FRAMEWORKS_DIR)", "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/Mac", ); GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; @@ -1304,7 +1355,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Debug; @@ -1336,6 +1387,7 @@ FRAMEWORK_SEARCH_PATHS = ( "$(DEVELOPER_FRAMEWORKS_DIR)", "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/Mac", ); GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; @@ -1356,7 +1408,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Release; diff --git a/SocketIO-MacTests/SocketObjectiveCTest.m b/SocketIO-MacTests/SocketObjectiveCTest.m index 6474123..6246701 100644 --- a/SocketIO-MacTests/SocketObjectiveCTest.m +++ b/SocketIO-MacTests/SocketObjectiveCTest.m @@ -11,7 +11,6 @@ @import Foundation; @import XCTest; @import SocketIO; -@import StarscreamSocketIO; @interface SocketObjectiveCTest : XCTestCase diff --git a/SocketIO-MacTests/SocketSideEffectTest.swift b/SocketIO-MacTests/SocketSideEffectTest.swift index b92ce62..bf9a12e 100644 --- a/SocketIO-MacTests/SocketSideEffectTest.swift +++ b/SocketIO-MacTests/SocketSideEffectTest.swift @@ -8,7 +8,6 @@ import XCTest @testable import SocketIO -@testable import StarscreamSocketIO class SocketSideEffectTest: XCTestCase { func testInitialCurrentAck() { diff --git a/Source/SocketIO/Engine/SocketEngine.swift b/Source/SocketIO/Engine/SocketEngine.swift index c07ffe4..64bf370 100644 --- a/Source/SocketIO/Engine/SocketEngine.swift +++ b/Source/SocketIO/Engine/SocketEngine.swift @@ -310,22 +310,22 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll private func createWebSocketAndConnect() { ws?.delegate = nil // TODO this seems a bit defensive, is this really needed? - var request = URLRequest(url: urlWebSocketWithSid) + ws = WebSocket(url: urlWebSocketWithSid) if cookies != nil { let headers = HTTPCookie.requestHeaderFields(with: cookies!) for (key, value) in headers { - request.setValue(value, forHTTPHeaderField: key) + ws?.headers[key] = value } } if extraHeaders != nil { for (headerName, value) in extraHeaders! { - request.setValue(value, forHTTPHeaderField: headerName) + ws?.headers[headerName] = value } } - ws = WebSocket(request: request) + ws?.callbackQueue = engineQueue ws?.enableCompression = compress ws?.delegate = self @@ -605,7 +605,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll // MARK: Starscream delegate conformance /// Delegate method for connection. - public func websocketDidConnect(socket: WebSocketClient) { + public func websocketDidConnect(socket: WebSocket) { if !forceWebsockets { probing = true probeWebSocket() @@ -617,7 +617,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll } /// Delegate method for disconnection. - public func websocketDidDisconnect(socket: WebSocketClient, error: Error?) { + public func websocketDidDisconnect(socket: WebSocket, error: NSError?) { probing = false if closed { diff --git a/Source/SocketIO/Engine/SocketEngineWebsocket.swift b/Source/SocketIO/Engine/SocketEngineWebsocket.swift index 75da709..514ea3a 100644 --- a/Source/SocketIO/Engine/SocketEngineWebsocket.swift +++ b/Source/SocketIO/Engine/SocketEngineWebsocket.swift @@ -68,12 +68,12 @@ extension SocketEngineWebsocket { // MARK: Starscream delegate methods /// Delegate method for when a message is received. - public func websocketDidReceiveMessage(socket: WebSocketClient, text: String) { + public func websocketDidReceiveMessage(socket: WebSocket, text: String) { parseEngineMessage(text) } /// Delegate method for when binary is received. - public func websocketDidReceiveData(socket: WebSocketClient, data: Data) { + public func websocketDidReceiveData(socket: WebSocket, data: Data) { parseEngineData(data) } } diff --git a/Source/SocketIO/Util/SSLSecurity.swift b/Source/SocketIO/Util/SSLSecurity.swift index 05f424f..e49581e 100644 --- a/Source/SocketIO/Util/SSLSecurity.swift +++ b/Source/SocketIO/Util/SSLSecurity.swift @@ -5,6 +5,7 @@ // Created by Lukas Schmidt on 24.09.17. // +import Foundation import Starscream public class SSLSecurity: NSObject { @@ -14,6 +15,7 @@ public class SSLSecurity: NSObject { self.security = security } + @objc public convenience init(usePublicKeys: Bool = true) { let security = Starscream.SSLSecurity(usePublicKeys: usePublicKeys) self.init(security: security) From 15198fd9c21f776b27e9442a79090120766b1391 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sun, 1 Oct 2017 08:46:50 -0400 Subject: [PATCH 17/23] update versions; use upstream starscream in podfile dep --- .gitmodules | 0 README.md | 5 ++--- Socket.IO-Client-Swift.podspec | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md index 9755d4a..a92b759 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,7 @@ Then import `import SocketIO`. ### Carthage Add these line to your `Cartfile`: ``` -github "nuclearace/Starscream" ~> 8.0.7 -github "socketio/socket.io-client-swift" ~> 12.0.0 # Or latest version +github "socketio/socket.io-client-swift" ~> 12.1.0 # Or latest version ``` Run `carthage update --platform ios,macosx`. @@ -100,7 +99,7 @@ Create `Podfile` and add `pod 'Socket.IO-Client-Swift'`: use_frameworks! target 'YourApp' do - pod 'Socket.IO-Client-Swift', '~> 12.0.0' # Or latest version + pod 'Socket.IO-Client-Swift', '~> 12.1.0' # Or latest version end ``` diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index a92bd04..5f0aa95 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 = "12.0.0" + s.version = "12.1.0" s.summary = "Socket.IO-client for iOS and OS X" s.description = <<-DESC Socket.IO-client for iOS and OS X. @@ -17,12 +17,12 @@ Pod::Spec.new do |s| s.requires_arc = true s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", - :tag => 'v12.0.0', + :tag => 'v12.1.0', :submodules => true } s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.0' } s.source_files = "Source/SocketIO/**/*.swift", "Source/SocketIO/*.swift" - s.dependency "StarscreamSocketIO", "~> 9.0.2" + s.dependency "Starscream", "~> 2.1.1" end From 392e479c59246338d7602bbeafcd8abfeb387b4f Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sun, 1 Oct 2017 08:53:42 -0400 Subject: [PATCH 18/23] Document SSLSecurity class --- Source/SocketIO/Util/SSLSecurity.swift | 38 +++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Source/SocketIO/Util/SSLSecurity.swift b/Source/SocketIO/Util/SSLSecurity.swift index e49581e..f621782 100644 --- a/Source/SocketIO/Util/SSLSecurity.swift +++ b/Source/SocketIO/Util/SSLSecurity.swift @@ -4,28 +4,64 @@ // // Created by Lukas Schmidt on 24.09.17. // +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. import Foundation import Starscream -public class SSLSecurity: NSObject { +/// A wrapper around Starscream's SSLSecurity that provides a minimal Objective-C interface. +open class SSLSecurity : NSObject { + /// The internal Starscream SSLSecurity. public let security: Starscream.SSLSecurity init(security: Starscream.SSLSecurity) { self.security = security } + /// Creates a new SSLSecurity that specifies whether to use publicKeys or certificates should be used for SSL + /// pinning validation + /// + /// - parameter usePublicKeys: is to specific if the publicKeys or certificates should be used for SSL pinning + /// validation @objc public convenience init(usePublicKeys: Bool = true) { let security = Starscream.SSLSecurity(usePublicKeys: usePublicKeys) self.init(security: security) } + + /// Designated init + /// + /// - 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 public convenience init(certs: [SSLCert], usePublicKeys: Bool) { let security = Starscream.SSLSecurity(certs: certs, usePublicKeys: usePublicKeys) self.init(security: security) } + /// Returns whether or not the given trust is valid. + /// + /// - parameter trust: The trust to validate. + /// - parameter domain: The CN domain to validate. + /// - returns: Whether or not this is valid. public func isValid(_ trust: SecTrust, domain: String?) -> Bool { return security.isValid(trust, domain: domain) } From 6138c535c9ccc99680a3fbd891466bc79c1d34b6 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sun, 1 Oct 2017 09:03:50 -0400 Subject: [PATCH 19/23] move carthage update to before_install --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fe1c178..abdb9ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,10 +8,10 @@ branches: - development before_install: - brew update - - brew outdated xctool || brew upgrade xctool + # - brew outdated xctool || brew upgrade xctool - brew outdated carthage || brew upgrade carthage -script: - carthage update +script: - xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build test -quiet # - xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build-for-testing -quiet # - xctool -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac run-tests --parallelize From 185d9708cd56a9187c256484163a538392e7eec5 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sun, 1 Oct 2017 09:58:43 -0400 Subject: [PATCH 20/23] update readme for carthage --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a92b759..502a5b2 100644 --- a/README.md +++ b/README.md @@ -85,13 +85,15 @@ let package = Package( Then import `import SocketIO`. ### Carthage -Add these line to your `Cartfile`: +Add this line to your `Cartfile`: ``` github "socketio/socket.io-client-swift" ~> 12.1.0 # Or latest version ``` Run `carthage update --platform ios,macosx`. +Add the `Starscream` and `SocketIO` frameworks to your projects and follow the usual Carthage process. + ### CocoaPods 1.0.0 or later Create `Podfile` and add `pod 'Socket.IO-Client-Swift'`: From 5e69272ebc3a678e58206b0f57c81efe7172bc25 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sun, 1 Oct 2017 10:08:00 -0400 Subject: [PATCH 21/23] rename method --- Source/SocketIO/Ack/SocketAckEmitter.swift | 2 +- Source/SocketIO/Client/SocketIOClient.swift | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/SocketIO/Ack/SocketAckEmitter.swift b/Source/SocketIO/Ack/SocketAckEmitter.swift index d8a30c4..5776289 100644 --- a/Source/SocketIO/Ack/SocketAckEmitter.swift +++ b/Source/SocketIO/Ack/SocketAckEmitter.swift @@ -116,7 +116,7 @@ public final class OnAckCallback : NSObject { guard let socket = self.socket, ackNumber != -1 else { return } socket.ackHandlers.addAck(ackNumber, callback: callback) - socket._emit(items, ack: ackNumber) + socket.emit(items, ack: ackNumber) guard seconds != 0 else { return } diff --git a/Source/SocketIO/Client/SocketIOClient.swift b/Source/SocketIO/Client/SocketIOClient.swift index 256b4d1..0ce0f97 100644 --- a/Source/SocketIO/Client/SocketIOClient.swift +++ b/Source/SocketIO/Client/SocketIOClient.swift @@ -304,7 +304,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So return } - _emit([event] + items) + emit([event] + items) } /// Sends a message to the server, requesting an ack. @@ -360,7 +360,7 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So return createOnAck([event] + items) } - func _emit(_ data: [Any], ack: Int? = nil) { + func emit(_ data: [Any], ack: Int? = nil) { guard status == .connected else { handleClientEvent(.error, data: ["Tried emitting when not connected"]) return @@ -717,6 +717,6 @@ open class SocketIOClient : NSObject, SocketIOClientSpec, SocketEngineClient, So } func emitTest(event: String, _ data: Any...) { - _emit([event] + data) + emit([event] + data) } } From a2b1a999e53fb99ba83cb28a6739fc1983c6f5fb Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sun, 1 Oct 2017 10:10:05 -0400 Subject: [PATCH 22/23] add package resolved file --- Package.resolved | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Package.resolved diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..e2fb1ed --- /dev/null +++ b/Package.resolved @@ -0,0 +1,34 @@ +{ + "object": { + "pins": [ + { + "package": "SSCZLib", + "repositoryURL": "https://github.com/daltoniam/zlib-spm.git", + "state": { + "branch": null, + "revision": "83ac8d719a2f3aa775dbdf116a57f56fb2c49abb", + "version": "1.1.0" + } + }, + { + "package": "SSCommonCrypto", + "repositoryURL": "https://github.com/daltoniam/common-crypto-spm", + "state": { + "branch": null, + "revision": "2eb3aff0fb57f92f5722fac5d6d20bf64669ca66", + "version": "1.1.0" + } + }, + { + "package": "Starscream", + "repositoryURL": "https://github.com/daltoniam/Starscream", + "state": { + "branch": null, + "revision": "21678c9426dde2a77152a0d5982cdb952baf0455", + "version": "2.1.1" + } + } + ] + }, + "version": 1 +} From 66d052cee24d84ee2ebf7570271b8025790685bb Mon Sep 17 00:00:00 2001 From: Erik Little Date: Sun, 1 Oct 2017 10:19:51 -0400 Subject: [PATCH 23/23] only build mac since the other targets aren't used in testing --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index abdb9ab..8261b18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ before_install: - brew update # - brew outdated xctool || brew upgrade xctool - brew outdated carthage || brew upgrade carthage - - carthage update + - carthage update --platform macosx script: - xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build test -quiet # - xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build-for-testing -quiet