From fe02b8eff21e7666665605a51d9283140d51b9fb Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 3 Jan 2016 13:11:18 -0500 Subject: [PATCH] change socketparser into a protocol --- .../project.pbxproj | 48 ++++++++---- .../xcschemes/SocketIO-Mac.xcscheme | 2 +- .../xcschemes/SocketIO-iOS.xcscheme | 2 +- .../xcschemes/SocketIO-tvOS.xcscheme | 2 +- SocketIO-Mac/Info.plist | 2 +- SocketIO-MacTests/Info.plist | 2 +- SocketIO-MacTests/SocketParserTest.swift | 7 +- SocketIO-iOS/Info.plist | 2 +- SocketIO-iOSTests/Info.plist | 2 +- Source/SocketClientSpec.swift | 37 ++++++++++ Source/SocketEngine.swift | 6 +- Source/SocketEngineClient.swift | 4 +- Source/SocketIOClient.swift | 16 ++-- ...ocketParser.swift => SocketParsable.swift} | 74 ++++++++++--------- 14 files changed, 135 insertions(+), 71 deletions(-) create mode 100644 Source/SocketClientSpec.swift rename Source/{SocketParser.swift => SocketParsable.swift} (73%) diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index 88c2396..4675dee 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -88,11 +88,11 @@ 74171EB31C10CD240062D398 /* SocketPacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5D1C10CD240062D398 /* SocketPacket.swift */; }; 74171EB51C10CD240062D398 /* SocketPacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5D1C10CD240062D398 /* SocketPacket.swift */; }; 74171EB61C10CD240062D398 /* SocketPacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5D1C10CD240062D398 /* SocketPacket.swift */; }; - 74171EB71C10CD240062D398 /* SocketParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5E1C10CD240062D398 /* SocketParser.swift */; }; - 74171EB81C10CD240062D398 /* SocketParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5E1C10CD240062D398 /* SocketParser.swift */; }; - 74171EB91C10CD240062D398 /* SocketParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5E1C10CD240062D398 /* SocketParser.swift */; }; - 74171EBB1C10CD240062D398 /* SocketParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5E1C10CD240062D398 /* SocketParser.swift */; }; - 74171EBC1C10CD240062D398 /* SocketParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5E1C10CD240062D398 /* SocketParser.swift */; }; + 74171EB71C10CD240062D398 /* SocketParsable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5E1C10CD240062D398 /* SocketParsable.swift */; }; + 74171EB81C10CD240062D398 /* SocketParsable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5E1C10CD240062D398 /* SocketParsable.swift */; }; + 74171EB91C10CD240062D398 /* SocketParsable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5E1C10CD240062D398 /* SocketParsable.swift */; }; + 74171EBB1C10CD240062D398 /* SocketParsable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5E1C10CD240062D398 /* SocketParsable.swift */; }; + 74171EBC1C10CD240062D398 /* SocketParsable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5E1C10CD240062D398 /* SocketParsable.swift */; }; 74171EBD1C10CD240062D398 /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5F1C10CD240062D398 /* SocketStringReader.swift */; }; 74171EBE1C10CD240062D398 /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5F1C10CD240062D398 /* SocketStringReader.swift */; }; 74171EBF1C10CD240062D398 /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74171E5F1C10CD240062D398 /* SocketStringReader.swift */; }; @@ -117,10 +117,13 @@ 741F39EF1BD025D80026C9CC /* SocketEngineTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 741F39ED1BD025D80026C9CC /* SocketEngineTest.swift */; }; 74321DCB1C2D939A00CF6F43 /* SocketAckManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74321DC91C2D939A00CF6F43 /* SocketAckManagerTest.swift */; }; 74321DCC1C2D939A00CF6F43 /* SocketParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74321DCA1C2D939A00CF6F43 /* SocketParserTest.swift */; }; + 7471CCEA1C39926300364B59 /* SocketClientSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74ABF7761C3991C10078C657 /* SocketClientSpec.swift */; }; + 7471CCEB1C39926C00364B59 /* SocketClientSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74ABF7761C3991C10078C657 /* SocketClientSpec.swift */; }; 7472C65C1BCAB53E003CA70D /* SocketNamespacePacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65B1BCAB53E003CA70D /* SocketNamespacePacketTest.swift */; }; 7472C65D1BCAB53E003CA70D /* SocketNamespacePacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65B1BCAB53E003CA70D /* SocketNamespacePacketTest.swift */; }; 7472C65F1BCAC46E003CA70D /* SocketSideEffectTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65E1BCAC46E003CA70D /* SocketSideEffectTest.swift */; }; 7472C6601BCAC46E003CA70D /* SocketSideEffectTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472C65E1BCAC46E003CA70D /* SocketSideEffectTest.swift */; }; + 74ABF7771C3991C10078C657 /* SocketClientSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74ABF7761C3991C10078C657 /* SocketClientSpec.swift */; }; 74F124F01BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */; }; 74F124F11BC574CF002966F4 /* SocketBasicPacketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */; }; /* End PBXBuildFile section */ @@ -176,7 +179,7 @@ 74171E5B1C10CD240062D398 /* SocketIOClientStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketIOClientStatus.swift; path = Source/SocketIOClientStatus.swift; sourceTree = ""; }; 74171E5C1C10CD240062D398 /* SocketLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketLogger.swift; path = Source/SocketLogger.swift; sourceTree = ""; }; 74171E5D1C10CD240062D398 /* SocketPacket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketPacket.swift; path = Source/SocketPacket.swift; sourceTree = ""; }; - 74171E5E1C10CD240062D398 /* SocketParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketParser.swift; path = Source/SocketParser.swift; sourceTree = ""; }; + 74171E5E1C10CD240062D398 /* SocketParsable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketParsable.swift; path = Source/SocketParsable.swift; sourceTree = ""; }; 74171E5F1C10CD240062D398 /* SocketStringReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketStringReader.swift; path = Source/SocketStringReader.swift; sourceTree = ""; }; 74171E601C10CD240062D398 /* SocketTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketTypes.swift; path = Source/SocketTypes.swift; sourceTree = ""; }; 74171E611C10CD240062D398 /* SwiftRegex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftRegex.swift; path = Source/SwiftRegex.swift; sourceTree = ""; }; @@ -186,6 +189,7 @@ 74321DCA1C2D939A00CF6F43 /* SocketParserTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketParserTest.swift; 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 = ""; }; + 74ABF7761C3991C10078C657 /* SocketClientSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketClientSpec.swift; path = Source/SocketClientSpec.swift; sourceTree = ""; }; 74F124EF1BC574CF002966F4 /* SocketBasicPacketTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketBasicPacketTest.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -341,6 +345,7 @@ 74171E501C10CD240062D398 /* SocketAckEmitter.swift */, 74171E511C10CD240062D398 /* SocketAckManager.swift */, 74171E521C10CD240062D398 /* SocketAnyEvent.swift */, + 74ABF7761C3991C10078C657 /* SocketClientSpec.swift */, 74171E531C10CD240062D398 /* SocketEngine.swift */, 74171E541C10CD240062D398 /* SocketEngineClient.swift */, 74171E551C10CD240062D398 /* SocketEnginePacketType.swift */, @@ -352,7 +357,7 @@ 74171E5B1C10CD240062D398 /* SocketIOClientStatus.swift */, 74171E5C1C10CD240062D398 /* SocketLogger.swift */, 74171E5D1C10CD240062D398 /* SocketPacket.swift */, - 74171E5E1C10CD240062D398 /* SocketParser.swift */, + 74171E5E1C10CD240062D398 /* SocketParsable.swift */, 74171E5F1C10CD240062D398 /* SocketStringReader.swift */, 74171E601C10CD240062D398 /* SocketTypes.swift */, 74171E611C10CD240062D398 /* SwiftRegex.swift */, @@ -506,7 +511,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0640; + LastUpgradeCheck = 0720; TargetAttributes = { 572EF2181B51F16C00EEBB58 = { CreatedOnToolsVersion = 6.4; @@ -598,6 +603,7 @@ 74171EA51C10CD240062D398 /* SocketIOClientStatus.swift in Sources */, 74171E751C10CD240062D398 /* SocketEngine.swift in Sources */, 74171E691C10CD240062D398 /* SocketAckManager.swift in Sources */, + 74ABF7771C3991C10078C657 /* SocketClientSpec.swift in Sources */, 74171E871C10CD240062D398 /* SocketEngineSpec.swift in Sources */, 74171E631C10CD240062D398 /* SocketAckEmitter.swift in Sources */, 74171EBD1C10CD240062D398 /* SocketStringReader.swift in Sources */, @@ -609,7 +615,7 @@ 74171E7B1C10CD240062D398 /* SocketEngineClient.swift in Sources */, 74171ECF1C10CD240062D398 /* WebSocket.swift in Sources */, 74171EB11C10CD240062D398 /* SocketPacket.swift in Sources */, - 74171EB71C10CD240062D398 /* SocketParser.swift in Sources */, + 74171EB71C10CD240062D398 /* SocketParsable.swift in Sources */, 74171E811C10CD240062D398 /* SocketEnginePacketType.swift in Sources */, 74171E6F1C10CD240062D398 /* SocketAnyEvent.swift in Sources */, 74171E9F1C10CD240062D398 /* SocketIOClientOption.swift in Sources */, @@ -639,7 +645,7 @@ 74171E6A1C10CD240062D398 /* SocketAckManager.swift in Sources */, 74171E761C10CD240062D398 /* SocketEngine.swift in Sources */, 74171E641C10CD240062D398 /* SocketAckEmitter.swift in Sources */, - 74171EB81C10CD240062D398 /* SocketParser.swift in Sources */, + 74171EB81C10CD240062D398 /* SocketParsable.swift in Sources */, 74171EAC1C10CD240062D398 /* SocketLogger.swift in Sources */, 7472C65C1BCAB53E003CA70D /* SocketNamespacePacketTest.swift in Sources */, 74171E9A1C10CD240062D398 /* SocketIOClient.swift in Sources */, @@ -650,6 +656,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 7471CCEA1C39926300364B59 /* SocketClientSpec.swift in Sources */, 74171E951C10CD240062D398 /* SocketFixUTF8.swift in Sources */, 74171EA71C10CD240062D398 /* SocketIOClientStatus.swift in Sources */, 74171E771C10CD240062D398 /* SocketEngine.swift in Sources */, @@ -665,7 +672,7 @@ 74171E7D1C10CD240062D398 /* SocketEngineClient.swift in Sources */, 74171ED11C10CD240062D398 /* WebSocket.swift in Sources */, 74171EB31C10CD240062D398 /* SocketPacket.swift in Sources */, - 74171EB91C10CD240062D398 /* SocketParser.swift in Sources */, + 74171EB91C10CD240062D398 /* SocketParsable.swift in Sources */, 74171E831C10CD240062D398 /* SocketEnginePacketType.swift in Sources */, 74171E711C10CD240062D398 /* SocketAnyEvent.swift in Sources */, 74171EA11C10CD240062D398 /* SocketIOClientOption.swift in Sources */, @@ -690,6 +697,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 7471CCEB1C39926C00364B59 /* SocketClientSpec.swift in Sources */, 74171E971C10CD240062D398 /* SocketFixUTF8.swift in Sources */, 74171EA91C10CD240062D398 /* SocketIOClientStatus.swift in Sources */, 74171E791C10CD240062D398 /* SocketEngine.swift in Sources */, @@ -705,7 +713,7 @@ 74171E7F1C10CD240062D398 /* SocketEngineClient.swift in Sources */, 74171ED31C10CD240062D398 /* WebSocket.swift in Sources */, 74171EB51C10CD240062D398 /* SocketPacket.swift in Sources */, - 74171EBB1C10CD240062D398 /* SocketParser.swift in Sources */, + 74171EBB1C10CD240062D398 /* SocketParsable.swift in Sources */, 74171E851C10CD240062D398 /* SocketEnginePacketType.swift in Sources */, 74171E731C10CD240062D398 /* SocketAnyEvent.swift in Sources */, 74171EA31C10CD240062D398 /* SocketIOClientOption.swift in Sources */, @@ -735,7 +743,7 @@ 74171E6E1C10CD240062D398 /* SocketAckManager.swift in Sources */, 74171E7A1C10CD240062D398 /* SocketEngine.swift in Sources */, 74171E681C10CD240062D398 /* SocketAckEmitter.swift in Sources */, - 74171EBC1C10CD240062D398 /* SocketParser.swift in Sources */, + 74171EBC1C10CD240062D398 /* SocketParsable.swift in Sources */, 74171EB01C10CD240062D398 /* SocketLogger.swift in Sources */, 57634A321BD9B46D00E19CD7 /* SocketNamespacePacketTest.swift in Sources */, 74171E9E1C10CD240062D398 /* SocketIOClient.swift in Sources */, @@ -769,9 +777,11 @@ BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "Developer ID Application"; ENABLE_BITCODE = YES; + ENABLE_TESTABILITY = YES; GCC_OPTIMIZATION_LEVEL = 0; IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; + ONLY_ACTIVE_ARCH = YES; PRODUCT_NAME = SocketIO; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; TVOS_DEPLOYMENT_TARGET = 9.0; @@ -840,6 +850,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -889,6 +900,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; SDKROOT = iphoneos; SKIP_INSTALL = YES; TARGETED_DEVICE_FAMILY = "1,2"; @@ -943,6 +955,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; }; @@ -986,6 +999,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.4; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; @@ -1041,6 +1055,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -1092,6 +1107,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; SDKROOT = macosx; SKIP_INSTALL = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -1146,6 +1162,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; }; @@ -1191,6 +1208,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; }; @@ -1242,6 +1260,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SocketIO; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1293,6 +1312,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SocketIO; SDKROOT = appletvos; SKIP_INSTALL = YES; @@ -1349,6 +1369,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; }; @@ -1392,6 +1413,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.4; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; VALIDATE_PRODUCT = YES; diff --git a/Socket.IO-Client-Swift.xcodeproj/xcshareddata/xcschemes/SocketIO-Mac.xcscheme b/Socket.IO-Client-Swift.xcodeproj/xcshareddata/xcschemes/SocketIO-Mac.xcscheme index 4b74905..7fef4ce 100644 --- a/Socket.IO-Client-Swift.xcodeproj/xcshareddata/xcschemes/SocketIO-Mac.xcscheme +++ b/Socket.IO-Client-Swift.xcodeproj/xcshareddata/xcschemes/SocketIO-Mac.xcscheme @@ -1,6 +1,6 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - io.socket.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/SocketIO-MacTests/Info.plist b/SocketIO-MacTests/Info.plist index 8129ec1..ba72822 100644 --- a/SocketIO-MacTests/Info.plist +++ b/SocketIO-MacTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - io.socket.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/SocketIO-MacTests/SocketParserTest.swift b/SocketIO-MacTests/SocketParserTest.swift index 63c4406..2428dd4 100644 --- a/SocketIO-MacTests/SocketParserTest.swift +++ b/SocketIO-MacTests/SocketParserTest.swift @@ -10,6 +10,7 @@ import XCTest @testable import SocketIO class SocketParserTest: XCTestCase { + let testSocket = SocketIOClient(socketURL: "") //Format key: message; namespace-data-binary-id static let packetTypes: Dictionary = [ @@ -93,7 +94,7 @@ class SocketParserTest: XCTestCase { func testInvalidInput() { let message = "8" - switch SocketParser.parseString(message) { + switch testSocket.parseString(message) { case .Left(_): return case .Right(_): @@ -111,7 +112,7 @@ class SocketParserTest: XCTestCase { func validateParseResult(message: String) { let validValues = SocketParserTest.packetTypes[message]! - let packet = SocketParser.parseString(message) + let packet = testSocket.parseString(message) let type = message.substringWithRange(Range(start: message.startIndex, end: message.startIndex.advancedBy(1))) if case let .Right(packet) = packet { XCTAssertEqual(packet.type, SocketPacket.PacketType(rawValue: Int(type) ?? -1)!) @@ -128,7 +129,7 @@ class SocketParserTest: XCTestCase { let keys = Array(SocketParserTest.packetTypes.keys) measureBlock({ for item in keys.enumerate() { - SocketParser.parseString(item.element) + self.testSocket.parseString(item.element) } }) } diff --git a/SocketIO-iOS/Info.plist b/SocketIO-iOS/Info.plist index 00ec026..d3de8ee 100644 --- a/SocketIO-iOS/Info.plist +++ b/SocketIO-iOS/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - io.socket.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/SocketIO-iOSTests/Info.plist b/SocketIO-iOSTests/Info.plist index 8129ec1..ba72822 100644 --- a/SocketIO-iOSTests/Info.plist +++ b/SocketIO-iOSTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - io.socket.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Source/SocketClientSpec.swift b/Source/SocketClientSpec.swift new file mode 100644 index 0000000..a717a3c --- /dev/null +++ b/Source/SocketClientSpec.swift @@ -0,0 +1,37 @@ +// +// SocketClientSpec.swift +// Socket.IO-Client-Swift +// +// Created by Erik Little on 1/3/16. +// +// 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 + +protocol SocketClientSpec: class { + var nsp: String { get set } + var waitingData: [SocketPacket] { get set } + + func didConnect() + func didDisconnect(reason: String) + func didError(reason: AnyObject) + func handleAck(ack: Int, data: [AnyObject]) + func handleEvent(event: String, data: [AnyObject], isInternalMessage: Bool, withAck ack: Int) + func joinNamespace(namespace: String) +} \ No newline at end of file diff --git a/Source/SocketEngine.swift b/Source/SocketEngine.swift index a605cf2..5eb023e 100644 --- a/Source/SocketEngine.swift +++ b/Source/SocketEngine.swift @@ -154,7 +154,7 @@ public final class SocketEngine: NSObject, SocketEngineSpec, WebSocketDelegate { if let data = NSData(base64EncodedString: noPrefix, options: .IgnoreUnknownCharacters) { - client?.parseBinaryData(data) + client?.parseEngineBinaryData(data) } return true @@ -299,7 +299,7 @@ public final class SocketEngine: NSObject, SocketEngineSpec, WebSocketDelegate { } private func handleMessage(message: String) { - client?.parseSocketMessage(message) + client?.parseEngineMessage(message) } private func handleNOOP() { @@ -414,7 +414,7 @@ public final class SocketEngine: NSObject, SocketEngineSpec, WebSocketDelegate { private func parseEngineData(data: NSData) { DefaultSocketLogger.Logger.log("Got binary data: %@", type: "SocketEngine", args: data) - client?.parseBinaryData(data.subdataWithRange(NSMakeRange(1, data.length - 1))) + client?.parseEngineBinaryData(data.subdataWithRange(NSMakeRange(1, data.length - 1))) } private func parseEngineMessage(message: String, fromPolling: Bool) { diff --git a/Source/SocketEngineClient.swift b/Source/SocketEngineClient.swift index 1f11549..776dc5a 100644 --- a/Source/SocketEngineClient.swift +++ b/Source/SocketEngineClient.swift @@ -28,6 +28,6 @@ import Foundation @objc public protocol SocketEngineClient { func didError(reason: AnyObject) func engineDidClose(reason: String) - func parseSocketMessage(msg: String) - func parseBinaryData(data: NSData) + func parseEngineMessage(msg: String) + func parseEngineBinaryData(data: NSData) } diff --git a/Source/SocketIOClient.swift b/Source/SocketIOClient.swift index 424c285..16ab0a4 100644 --- a/Source/SocketIOClient.swift +++ b/Source/SocketIOClient.swift @@ -24,7 +24,7 @@ import Foundation -public final class SocketIOClient: NSObject, SocketEngineClient { +public final class SocketIOClient: NSObject, SocketEngineClient, SocketParsable { public let socketURL: String public private(set) var engine: SocketEngineSpec? @@ -319,13 +319,12 @@ public final class SocketIOClient: NSObject, SocketEngineClient { } // Called when the socket gets an ack for something it sent - func handleAck(ack: Int, data: AnyObject?) { + func handleAck(ack: Int, data: [AnyObject]) { guard status == .Connected else {return} DefaultSocketLogger.Logger.log("Handling ack: %@ with data: %@", type: logType, args: ack, data ?? "") - ackHandlers.executeAck(ack, - items: (data as? [AnyObject]) ?? (data != nil ? [data!] : [])) + ackHandlers.executeAck(ack, items: data) } /** @@ -436,15 +435,16 @@ public final class SocketIOClient: NSObject, SocketEngineClient { connect() } - public func parseSocketMessage(msg: String) { + public func parseEngineMessage(msg: String) { + DefaultSocketLogger.Logger.log("Should parse message", type: "SocketIOClient") dispatch_async(parseQueue) { - SocketParser.parseSocketMessage(msg, socket: self) + self.parseSocketMessage(msg) } } - public func parseBinaryData(data: NSData) { + public func parseEngineBinaryData(data: NSData) { dispatch_async(parseQueue) { - SocketParser.parseBinaryData(data, socket: self) + self.parseBinaryData(data) } } diff --git a/Source/SocketParser.swift b/Source/SocketParsable.swift similarity index 73% rename from Source/SocketParser.swift rename to Source/SocketParsable.swift index 4cab27b..f9e7a3e 100644 --- a/Source/SocketParser.swift +++ b/Source/SocketParsable.swift @@ -1,5 +1,5 @@ // -// SocketParser.swift +// SocketParsable.swift // Socket.IO-Client-Swift // // Permission is hereby granted, free of charge, to any person obtaining a copy @@ -22,46 +22,50 @@ import Foundation -class SocketParser { - - private static func isCorrectNamespace(nsp: String, _ socket: SocketIOClient) -> Bool { - return nsp == socket.nsp - } +protocol SocketParsable: class, SocketClientSpec { + func parseBinaryData(data: NSData) + func parseSocketMessage(message: String) +} - private static func handleConnect(p: SocketPacket, socket: SocketIOClient) { - if p.nsp == "/" && socket.nsp != "/" { - socket.joinNamespace(socket.nsp) - } else if p.nsp != "/" && socket.nsp == "/" { - socket.didConnect() +extension SocketParsable { + private func isCorrectNamespace(nsp: String) -> Bool { + return nsp == self.nsp + } + + private func handleConnect(p: SocketPacket) { + if p.nsp == "/" && nsp != "/" { + joinNamespace(nsp) + } else if p.nsp != "/" && nsp == "/" { + didConnect() } else { - socket.didConnect() + didConnect() } } - private static func handlePacket(pack: SocketPacket, withSocket socket: SocketIOClient) { + private func handlePacket(pack: SocketPacket) { switch pack.type { - case .Event where isCorrectNamespace(pack.nsp, socket): - socket.handleEvent(pack.event, data: pack.args, + case .Event where isCorrectNamespace(pack.nsp): + handleEvent(pack.event, data: pack.args, isInternalMessage: false, withAck: pack.id) - case .Ack where isCorrectNamespace(pack.nsp, socket): - socket.handleAck(pack.id, data: pack.data) - case .BinaryEvent where isCorrectNamespace(pack.nsp, socket): - socket.waitingData.append(pack) - case .BinaryAck where isCorrectNamespace(pack.nsp, socket): - socket.waitingData.append(pack) + case .Ack where isCorrectNamespace(pack.nsp): + handleAck(pack.id, data: pack.data) + case .BinaryEvent where isCorrectNamespace(pack.nsp): + waitingData.append(pack) + case .BinaryAck where isCorrectNamespace(pack.nsp): + waitingData.append(pack) case .Connect: - handleConnect(pack, socket: socket) + handleConnect(pack) case .Disconnect: - socket.didDisconnect("Got Disconnect") + didDisconnect("Got Disconnect") case .Error: - socket.didError(pack.data) + didError(pack.data) default: DefaultSocketLogger.Logger.log("Got invalid packet: %@", type: "SocketParser", args: pack.description) } } /// Parses a messsage from the engine. Returning either a string error or a complete SocketPacket - static func parseString(message: String) -> Either { + func parseString(message: String) -> Either { var parser = SocketStringReader(message: message) guard let type = SocketPacket.PacketType(rawValue: Int(parser.read(1)) ?? -1) else { @@ -79,7 +83,7 @@ class SocketParser { if let holders = Int(parser.readUntilStringOccurence("-")) { placeholders = holders } else { - return .Left("Invalid packet") + return .Left("Invalid packet") } } @@ -126,7 +130,7 @@ class SocketParser { } // Parses data for events - private static func parseData(data: String) -> Either { + private func parseData(data: String) -> Either { let stringData = data.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) do { if let arr = try NSJSONSerialization.JSONObjectWithData(stringData!, @@ -141,7 +145,7 @@ class SocketParser { } // Parses messages recieved - static func parseSocketMessage(message: String, socket: SocketIOClient) { + func parseSocketMessage(message: String) { guard !message.isEmpty else { return } DefaultSocketLogger.Logger.log("Parsing %@", type: "SocketParser", args: message) @@ -151,28 +155,28 @@ class SocketParser { DefaultSocketLogger.Logger.error("\(err): %@", type: "SocketParser", args: message) case let .Right(pack): DefaultSocketLogger.Logger.log("Decoded packet as: %@", type: "SocketParser", args: pack.description) - handlePacket(pack, withSocket: socket) + handlePacket(pack) } } - static func parseBinaryData(data: NSData, socket: SocketIOClient) { - guard !socket.waitingData.isEmpty else { + func parseBinaryData(data: NSData) { + guard !waitingData.isEmpty else { DefaultSocketLogger.Logger.error("Got data when not remaking packet", type: "SocketParser") return } // Should execute event? - guard socket.waitingData[socket.waitingData.count - 1].addData(data) else { + guard waitingData[waitingData.count - 1].addData(data) else { return } - let packet = socket.waitingData.removeLast() + let packet = waitingData.removeLast() if packet.type != .BinaryAck { - socket.handleEvent(packet.event, data: packet.args ?? [], + handleEvent(packet.event, data: packet.args ?? [], isInternalMessage: false, withAck: packet.id) } else { - socket.handleAck(packet.id, data: packet.args) + handleAck(packet.id, data: packet.args) } } }