commit
7bdf80d133
14
README.md
14
README.md
@ -17,7 +17,7 @@ socket.on("currentAmount") {data, ack in
|
|||||||
socket.emit("update", ["amount": cur + 2.50])
|
socket.emit("update", ["amount": cur + 2.50])
|
||||||
}
|
}
|
||||||
|
|
||||||
ack?("Got your currentAmount", "dude")
|
ack?.with("Got your currentAmount", "dude")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,18 +28,18 @@ socket.connect()
|
|||||||
```objective-c
|
```objective-c
|
||||||
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" opts:nil];
|
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" opts:nil];
|
||||||
|
|
||||||
[socket onObjectiveC:@"connect" callback:^(NSArray* data, void (^ack)(NSArray*)) {
|
[socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
|
||||||
NSLog(@"socket connected");
|
NSLog(@"socket connected");
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[socket onObjectiveC:@"currentAmount" callback:^(NSArray* data, void (^ack)(NSArray*)) {
|
[socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) {
|
||||||
double cur = [[data objectAtIndex:0] floatValue];
|
double cur = [[data objectAtIndex:0] floatValue];
|
||||||
|
|
||||||
[socket emitWithAck:@"canUpdate" withItems:@[@(cur)]](0, ^(NSArray* data) {
|
[socket emitWithAck:@"canUpdate" withItems:@[@(cur)]](0, ^(NSArray* data) {
|
||||||
[socket emit:@"update" withItems:@[@{@"amount": @(cur + 2.50)}]];
|
[socket emit:@"update" withItems:@[@{@"amount": @(cur + 2.50)}]];
|
||||||
});
|
});
|
||||||
|
|
||||||
ack(@[@"Got your currentAmount, ", @"dude"]);
|
[ack with:@[@"Got your currentAmount, ", @"dude"]];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[socket connect];
|
[socket connect];
|
||||||
@ -128,8 +128,8 @@ Options
|
|||||||
|
|
||||||
Methods
|
Methods
|
||||||
-------
|
-------
|
||||||
1. `on(name: String, callback: ((data: NSArray?, ack: AckEmitter?) -> Void))` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example.
|
1. `on(event: String, callback: NormalCallback)` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example.
|
||||||
2. `onObjectiveC(name: String, callback: ((data: NSArray?, ack: AckEmitter?) -> Void))` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example.
|
2. `once(event: String, callback: NormalCallback)` - Adds a handler that will only be executed once.
|
||||||
3. `onAny(callback:((event: String, items: AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
|
3. `onAny(callback:((event: String, items: AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
|
||||||
4. `emit(event: String, _ items: AnyObject...)` - Sends a message. Can send multiple items.
|
4. `emit(event: String, _ items: AnyObject...)` - Sends a message. Can send multiple items.
|
||||||
5. `emit(event: String, withItems items: [AnyObject])` - `emit` for Objective-C
|
5. `emit(event: String, withItems items: [AnyObject])` - `emit` for Objective-C
|
||||||
@ -141,8 +141,6 @@ Methods
|
|||||||
11. `reconnect()` - Causes the client to reconnect to the server.
|
11. `reconnect()` - Causes the client to reconnect to the server.
|
||||||
12. `joinNamespace()` - Causes the client to join nsp. Shouldn't need to be called unless you change nsp manually.
|
12. `joinNamespace()` - Causes the client to join nsp. Shouldn't need to be called unless you change nsp manually.
|
||||||
13. `leaveNamespace()` - Causes the client to leave the nsp and go back to /
|
13. `leaveNamespace()` - Causes the client to leave the nsp and go back to /
|
||||||
14. `once(event: String, callback: NormalCallback)` - Adds a handler that will only be executed once.
|
|
||||||
15. `once(event event: String, callback: NormalCallbackObjectiveC)` - Adds a handler that will only be executed once.
|
|
||||||
|
|
||||||
Client Events
|
Client Events
|
||||||
------
|
------
|
||||||
|
|||||||
@ -83,6 +83,12 @@
|
|||||||
74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
|
74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
|
||||||
74781D5C1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
|
74781D5C1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
|
||||||
74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
|
74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
|
||||||
|
749A7F8B1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
|
749A7F8C1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
|
749A7F8D1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
|
749A7F8E1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
|
749A7F8F1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
|
749A7F901BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
74D765621B9F0D870028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
|
74D765621B9F0D870028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
|
||||||
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
|
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
|
||||||
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
|
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
|
||||||
@ -162,6 +168,7 @@
|
|||||||
5764DF871B51F254004FF46E /* SwiftRegex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftRegex.swift; path = SocketIOClientSwift/SwiftRegex.swift; sourceTree = "<group>"; };
|
5764DF871B51F254004FF46E /* SwiftRegex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftRegex.swift; path = SocketIOClientSwift/SwiftRegex.swift; sourceTree = "<group>"; };
|
||||||
5764DF881B51F254004FF46E /* WebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebSocket.swift; path = SocketIOClientSwift/WebSocket.swift; sourceTree = "<group>"; };
|
5764DF881B51F254004FF46E /* WebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebSocket.swift; path = SocketIOClientSwift/WebSocket.swift; sourceTree = "<group>"; };
|
||||||
74781D591B7E83930042CACA /* SocketIOClientStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketIOClientStatus.swift; path = SocketIOClientSwift/SocketIOClientStatus.swift; sourceTree = "<group>"; };
|
74781D591B7E83930042CACA /* SocketIOClientStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketIOClientStatus.swift; path = SocketIOClientSwift/SocketIOClientStatus.swift; sourceTree = "<group>"; };
|
||||||
|
749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketAckEmitter.swift; path = SocketIOClientSwift/SocketAckEmitter.swift; sourceTree = "<group>"; };
|
||||||
74D765611B9F0D870028551C /* SocketStringReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SocketStringReader.swift; path = SocketIOClientSwift/SocketStringReader.swift; sourceTree = "<group>"; };
|
74D765611B9F0D870028551C /* SocketStringReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SocketStringReader.swift; path = SocketIOClientSwift/SocketStringReader.swift; sourceTree = "<group>"; };
|
||||||
941A4AB91B67A56C00C42318 /* TestKind.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestKind.swift; sourceTree = "<group>"; };
|
941A4AB91B67A56C00C42318 /* TestKind.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestKind.swift; sourceTree = "<group>"; };
|
||||||
94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketNamespaceAcknowledgementTest.swift; sourceTree = "<group>"; };
|
94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketNamespaceAcknowledgementTest.swift; sourceTree = "<group>"; };
|
||||||
@ -268,16 +275,16 @@
|
|||||||
572EF2281B51F16C00EEBB58 /* SocketIO-iOSTests */ = {
|
572EF2281B51F16C00EEBB58 /* SocketIO-iOSTests */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
945B65421B63D9DB0081E995 /* SocketEmitTest.swift */,
|
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */,
|
||||||
94ADAC4A1B6632DD00FD79AE /* SocketAcknowledgementTest.swift */,
|
94ADAC4A1B6632DD00FD79AE /* SocketAcknowledgementTest.swift */,
|
||||||
|
945B65421B63D9DB0081E995 /* SocketEmitTest.swift */,
|
||||||
94ADAC481B652D3300FD79AE /* SocketNamespaceEmitTest.swift */,
|
94ADAC481B652D3300FD79AE /* SocketNamespaceEmitTest.swift */,
|
||||||
94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */,
|
94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */,
|
||||||
941A4AB91B67A56C00C42318 /* TestKind.swift */,
|
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */,
|
||||||
94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */,
|
94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */,
|
||||||
94CB8F0C1B6E66E60019ED53 /* AbstractSocketTest.swift */,
|
94CB8F0C1B6E66E60019ED53 /* AbstractSocketTest.swift */,
|
||||||
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */,
|
941A4AB91B67A56C00C42318 /* TestKind.swift */,
|
||||||
572EF2291B51F16C00EEBB58 /* Supporting Files */,
|
572EF2291B51F16C00EEBB58 /* Supporting Files */,
|
||||||
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */,
|
|
||||||
);
|
);
|
||||||
path = "SocketIO-iOSTests";
|
path = "SocketIO-iOSTests";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -327,6 +334,7 @@
|
|||||||
5764DF7B1B51F24A004FF46E /* Source */ = {
|
5764DF7B1B51F24A004FF46E /* Source */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */,
|
||||||
5764DF7C1B51F254004FF46E /* SocketAckManager.swift */,
|
5764DF7C1B51F254004FF46E /* SocketAckManager.swift */,
|
||||||
5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */,
|
5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */,
|
||||||
5764DF7E1B51F254004FF46E /* SocketEngine.swift */,
|
5764DF7E1B51F254004FF46E /* SocketEngine.swift */,
|
||||||
@ -582,6 +590,7 @@
|
|||||||
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */,
|
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */,
|
||||||
5764DF8D1B51F254004FF46E /* SocketEngine.swift in Sources */,
|
5764DF8D1B51F254004FF46E /* SocketEngine.swift in Sources */,
|
||||||
5764DF9B1B51F254004FF46E /* SocketParser.swift in Sources */,
|
5764DF9B1B51F254004FF46E /* SocketParser.swift in Sources */,
|
||||||
|
749A7F8B1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
|
||||||
5764DF9D1B51F254004FF46E /* SocketTypes.swift in Sources */,
|
5764DF9D1B51F254004FF46E /* SocketTypes.swift in Sources */,
|
||||||
5764DF8F1B51F254004FF46E /* SocketEngineClient.swift in Sources */,
|
5764DF8F1B51F254004FF46E /* SocketEngineClient.swift in Sources */,
|
||||||
5764DF911B51F254004FF46E /* SocketEventHandler.swift in Sources */,
|
5764DF911B51F254004FF46E /* SocketEventHandler.swift in Sources */,
|
||||||
@ -607,6 +616,7 @@
|
|||||||
945B653A1B5FCEEA0081E995 /* SocketFixUTF8.swift in Sources */,
|
945B653A1B5FCEEA0081E995 /* SocketFixUTF8.swift in Sources */,
|
||||||
945B65391B5FCEEA0081E995 /* SocketEventHandler.swift in Sources */,
|
945B65391B5FCEEA0081E995 /* SocketEventHandler.swift in Sources */,
|
||||||
94CB8F0B1B6E48B90019ED53 /* SocketTestCases.swift in Sources */,
|
94CB8F0B1B6E48B90019ED53 /* SocketTestCases.swift in Sources */,
|
||||||
|
749A7F8C1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
|
||||||
945B65371B5FCEEA0081E995 /* SocketEngine.swift in Sources */,
|
945B65371B5FCEEA0081E995 /* SocketEngine.swift in Sources */,
|
||||||
945B65351B5FCEEA0081E995 /* SocketAckManager.swift in Sources */,
|
945B65351B5FCEEA0081E995 /* SocketAckManager.swift in Sources */,
|
||||||
941A4ABA1B67A56C00C42318 /* TestKind.swift in Sources */,
|
941A4ABA1B67A56C00C42318 /* TestKind.swift in Sources */,
|
||||||
@ -635,6 +645,7 @@
|
|||||||
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */,
|
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */,
|
||||||
5764DF8E1B51F254004FF46E /* SocketEngine.swift in Sources */,
|
5764DF8E1B51F254004FF46E /* SocketEngine.swift in Sources */,
|
||||||
5764DF9C1B51F254004FF46E /* SocketParser.swift in Sources */,
|
5764DF9C1B51F254004FF46E /* SocketParser.swift in Sources */,
|
||||||
|
749A7F8F1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
|
||||||
5764DF9E1B51F254004FF46E /* SocketTypes.swift in Sources */,
|
5764DF9E1B51F254004FF46E /* SocketTypes.swift in Sources */,
|
||||||
5764DF901B51F254004FF46E /* SocketEngineClient.swift in Sources */,
|
5764DF901B51F254004FF46E /* SocketEngineClient.swift in Sources */,
|
||||||
5764DF921B51F254004FF46E /* SocketEventHandler.swift in Sources */,
|
5764DF921B51F254004FF46E /* SocketEventHandler.swift in Sources */,
|
||||||
@ -654,6 +665,7 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
749A7F901BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
|
||||||
572EF24A1B51F18A00EEBB58 /* SocketIO_MacTests.swift in Sources */,
|
572EF24A1B51F18A00EEBB58 /* SocketIO_MacTests.swift in Sources */,
|
||||||
74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */,
|
74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */,
|
||||||
);
|
);
|
||||||
@ -666,6 +678,7 @@
|
|||||||
57425F9C1BA3A46000BDAAC1 /* SocketStringReader.swift in Sources */,
|
57425F9C1BA3A46000BDAAC1 /* SocketStringReader.swift in Sources */,
|
||||||
57425F9D1BA3A46000BDAAC1 /* SocketEngine.swift in Sources */,
|
57425F9D1BA3A46000BDAAC1 /* SocketEngine.swift in Sources */,
|
||||||
57425F9E1BA3A46000BDAAC1 /* SocketParser.swift in Sources */,
|
57425F9E1BA3A46000BDAAC1 /* SocketParser.swift in Sources */,
|
||||||
|
749A7F8D1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
|
||||||
57425F9F1BA3A46000BDAAC1 /* SocketTypes.swift in Sources */,
|
57425F9F1BA3A46000BDAAC1 /* SocketTypes.swift in Sources */,
|
||||||
57425FA01BA3A46000BDAAC1 /* SocketEngineClient.swift in Sources */,
|
57425FA01BA3A46000BDAAC1 /* SocketEngineClient.swift in Sources */,
|
||||||
57425FA11BA3A46000BDAAC1 /* SocketEventHandler.swift in Sources */,
|
57425FA11BA3A46000BDAAC1 /* SocketEventHandler.swift in Sources */,
|
||||||
@ -691,6 +704,7 @@
|
|||||||
57425FDF1BA3A4F100BDAAC1 /* SocketFixUTF8.swift in Sources */,
|
57425FDF1BA3A4F100BDAAC1 /* SocketFixUTF8.swift in Sources */,
|
||||||
57425FE01BA3A4F100BDAAC1 /* SocketEventHandler.swift in Sources */,
|
57425FE01BA3A4F100BDAAC1 /* SocketEventHandler.swift in Sources */,
|
||||||
57425FE11BA3A4F100BDAAC1 /* SocketTestCases.swift in Sources */,
|
57425FE11BA3A4F100BDAAC1 /* SocketTestCases.swift in Sources */,
|
||||||
|
749A7F8E1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
|
||||||
57425FE21BA3A4F100BDAAC1 /* SocketEngine.swift in Sources */,
|
57425FE21BA3A4F100BDAAC1 /* SocketEngine.swift in Sources */,
|
||||||
57425FE31BA3A4F100BDAAC1 /* SocketAckManager.swift in Sources */,
|
57425FE31BA3A4F100BDAAC1 /* SocketAckManager.swift in Sources */,
|
||||||
57425FE41BA3A4F100BDAAC1 /* TestKind.swift in Sources */,
|
57425FE41BA3A4F100BDAAC1 /* TestKind.swift in Sources */,
|
||||||
|
|||||||
@ -37,10 +37,10 @@
|
|||||||
</BuildActionEntries>
|
</BuildActionEntries>
|
||||||
</BuildAction>
|
</BuildAction>
|
||||||
<TestAction
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
buildConfiguration = "Debug">
|
|
||||||
<Testables>
|
<Testables>
|
||||||
<TestableReference
|
<TestableReference
|
||||||
skipped = "NO">
|
skipped = "NO">
|
||||||
@ -62,15 +62,18 @@
|
|||||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||||
</BuildableReference>
|
</BuildableReference>
|
||||||
</MacroExpansion>
|
</MacroExpansion>
|
||||||
|
<AdditionalOptions>
|
||||||
|
</AdditionalOptions>
|
||||||
</TestAction>
|
</TestAction>
|
||||||
<LaunchAction
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
buildConfiguration = "Debug"
|
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
debugDocumentVersioning = "YES"
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
allowLocationSimulation = "YES">
|
allowLocationSimulation = "YES">
|
||||||
<MacroExpansion>
|
<MacroExpansion>
|
||||||
<BuildableReference
|
<BuildableReference
|
||||||
@ -85,10 +88,10 @@
|
|||||||
</AdditionalOptions>
|
</AdditionalOptions>
|
||||||
</LaunchAction>
|
</LaunchAction>
|
||||||
<ProfileAction
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
savedToolIdentifier = ""
|
savedToolIdentifier = ""
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
buildConfiguration = "Release"
|
|
||||||
debugDocumentVersioning = "YES">
|
debugDocumentVersioning = "YES">
|
||||||
<MacroExpansion>
|
<MacroExpansion>
|
||||||
<BuildableReference
|
<BuildableReference
|
||||||
|
|||||||
@ -45,7 +45,7 @@ class AbstractSocketTest: XCTestCase {
|
|||||||
func socketMultipleEmit(testName:String, emitData:Array<AnyObject>, callback:NormalCallback){
|
func socketMultipleEmit(testName:String, emitData:Array<AnyObject>, callback:NormalCallback){
|
||||||
let finalTestname = generateTestName(testName)
|
let finalTestname = generateTestName(testName)
|
||||||
weak var expection = self.expectationWithDescription(finalTestname)
|
weak var expection = self.expectationWithDescription(finalTestname)
|
||||||
func didGetEmit(result:NSArray?, ack:AckEmitter?) {
|
func didGetEmit(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
callback(result, ack)
|
callback(result, ack)
|
||||||
if let expection = expection {
|
if let expection = expection {
|
||||||
expection.fulfill()
|
expection.fulfill()
|
||||||
@ -61,7 +61,7 @@ class AbstractSocketTest: XCTestCase {
|
|||||||
func socketEmit(testName:String, emitData:AnyObject?, callback:NormalCallback){
|
func socketEmit(testName:String, emitData:AnyObject?, callback:NormalCallback){
|
||||||
let finalTestname = generateTestName(testName)
|
let finalTestname = generateTestName(testName)
|
||||||
weak var expection = self.expectationWithDescription(finalTestname)
|
weak var expection = self.expectationWithDescription(finalTestname)
|
||||||
func didGetEmit(result:NSArray?, ack:AckEmitter?) {
|
func didGetEmit(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
callback(result, ack)
|
callback(result, ack)
|
||||||
if let expection = expection {
|
if let expection = expection {
|
||||||
expection.fulfill()
|
expection.fulfill()
|
||||||
@ -79,11 +79,12 @@ class AbstractSocketTest: XCTestCase {
|
|||||||
waitForExpectationsWithTimeout(SocketEmitTest.TEST_TIMEOUT, handler: nil)
|
waitForExpectationsWithTimeout(SocketEmitTest.TEST_TIMEOUT, handler: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func socketAcknwoledgeMultiple(testName:String, Data:Array<AnyObject>, callback:NormalCallback){
|
func socketAcknwoledgeMultiple(testName:String, Data:Array<AnyObject>, callback:NormalCallback){
|
||||||
let finalTestname = generateTestName(testName)
|
let finalTestname = generateTestName(testName)
|
||||||
weak var expection = self.expectationWithDescription(finalTestname)
|
weak var expection = self.expectationWithDescription(finalTestname)
|
||||||
func didGetResult(result:NSArray?) {
|
func didGetResult(result: [AnyObject]) {
|
||||||
callback(result, nil)
|
callback(result, SocketAckEmitter(socket: AbstractSocketTest.socket, ackNum: -1))
|
||||||
if let expection = expection {
|
if let expection = expection {
|
||||||
expection.fulfill()
|
expection.fulfill()
|
||||||
}
|
}
|
||||||
@ -96,8 +97,8 @@ class AbstractSocketTest: XCTestCase {
|
|||||||
func socketAcknwoledge(testName:String, Data:AnyObject?, callback:NormalCallback){
|
func socketAcknwoledge(testName:String, Data:AnyObject?, callback:NormalCallback){
|
||||||
let finalTestname = generateTestName(testName)
|
let finalTestname = generateTestName(testName)
|
||||||
weak var expection = self.expectationWithDescription(finalTestname)
|
weak var expection = self.expectationWithDescription(finalTestname)
|
||||||
func didGet(result:NSArray?) {
|
func didGet(result:[AnyObject]) {
|
||||||
callback(result, nil)
|
callback(result, SocketAckEmitter(socket: AbstractSocketTest.socket, ackNum: -1))
|
||||||
if let expection = expection {
|
if let expection = expection {
|
||||||
expection.fulfill()
|
expection.fulfill()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,9 +14,8 @@ class SocketAckManagerTest: XCTestCase {
|
|||||||
func testAddAcks() {
|
func testAddAcks() {
|
||||||
let callbackExpection = self.expectationWithDescription("callbackExpection")
|
let callbackExpection = self.expectationWithDescription("callbackExpection")
|
||||||
let itemsArray = ["Hi", "ho"]
|
let itemsArray = ["Hi", "ho"]
|
||||||
func callback(items: NSArray?) {
|
func callback(items: [AnyObject]) {
|
||||||
callbackExpection.fulfill()
|
callbackExpection.fulfill()
|
||||||
items?.isEqualToArray(itemsArray)
|
|
||||||
}
|
}
|
||||||
ackManager.addAck(1, callback: callback)
|
ackManager.addAck(1, callback: callback)
|
||||||
ackManager.executeAck(1, items: itemsArray)
|
ackManager.executeAck(1, items: itemsArray)
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class SocketTestCases: NSObject {
|
|||||||
|
|
||||||
static func testBasic(abstractSocketSend:SocketSendFunction) {
|
static func testBasic(abstractSocketSend:SocketSendFunction) {
|
||||||
let testName = "basicTest"
|
let testName = "basicTest"
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
|
|
||||||
}
|
}
|
||||||
abstractSocketSend(testName: testName, emitData: nil, callback: didGetResult)
|
abstractSocketSend(testName: testName, emitData: nil, callback: didGetResult)
|
||||||
@ -22,8 +22,8 @@ class SocketTestCases: NSObject {
|
|||||||
|
|
||||||
static func testNull(abstractSocketSend:SocketSendFunction) {
|
static func testNull(abstractSocketSend:SocketSendFunction) {
|
||||||
let testName = "testNull"
|
let testName = "testNull"
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
if let _ = result?.firstObject as? NSNull {
|
if let _ = result.first as? NSNull {
|
||||||
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
@ -35,8 +35,8 @@ class SocketTestCases: NSObject {
|
|||||||
|
|
||||||
static func testBinary(abstractSocketSend:SocketSendFunction) {
|
static func testBinary(abstractSocketSend:SocketSendFunction) {
|
||||||
let testName = "testBinary"
|
let testName = "testBinary"
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
if let data = result?.firstObject as? NSData {
|
if let data = result.first as? NSData {
|
||||||
let string = NSString(data: data, encoding: NSUTF8StringEncoding)!
|
let string = NSString(data: data, encoding: NSUTF8StringEncoding)!
|
||||||
XCTAssertEqual(string, "gakgakgak2")
|
XCTAssertEqual(string, "gakgakgak2")
|
||||||
}else {
|
}else {
|
||||||
@ -49,8 +49,8 @@ class SocketTestCases: NSObject {
|
|||||||
|
|
||||||
static func testArray(abstractSocketSend:SocketSendFunction) {
|
static func testArray(abstractSocketSend:SocketSendFunction) {
|
||||||
let testName = "testArray"
|
let testName = "testArray"
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
if let array = result?.firstObject as? NSArray {
|
if let array = result.first as? NSArray {
|
||||||
XCTAssertEqual(array.count, 2)
|
XCTAssertEqual(array.count, 2)
|
||||||
XCTAssertEqual((array.firstObject! as! String), "test3")
|
XCTAssertEqual((array.firstObject! as! String), "test3")
|
||||||
XCTAssertEqual((array.lastObject! as! String), "test4")
|
XCTAssertEqual((array.lastObject! as! String), "test4")
|
||||||
@ -63,8 +63,8 @@ class SocketTestCases: NSObject {
|
|||||||
|
|
||||||
static func testString(abstractSocketSend:SocketSendFunction) {
|
static func testString(abstractSocketSend:SocketSendFunction) {
|
||||||
let testName = "testString"
|
let testName = "testString"
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
if let string = result?.firstObject as? String {
|
if let string = result.first as? String {
|
||||||
XCTAssertEqual(string, "polo")
|
XCTAssertEqual(string, "polo")
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have String as result")
|
XCTFail("Should have String as result")
|
||||||
@ -75,8 +75,8 @@ class SocketTestCases: NSObject {
|
|||||||
|
|
||||||
static func testBool(abstractSocketSend:SocketSendFunction) {
|
static func testBool(abstractSocketSend:SocketSendFunction) {
|
||||||
let testName = "testBool"
|
let testName = "testBool"
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
if let bool = result?.firstObject as? NSNumber {
|
if let bool = result.first as? NSNumber {
|
||||||
XCTAssertTrue(bool.boolValue)
|
XCTAssertTrue(bool.boolValue)
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have Boolean as result")
|
XCTFail("Should have Boolean as result")
|
||||||
@ -87,8 +87,8 @@ class SocketTestCases: NSObject {
|
|||||||
|
|
||||||
static func testInteger(abstractSocketSend:SocketSendFunction) {
|
static func testInteger(abstractSocketSend:SocketSendFunction) {
|
||||||
let testName = "testInteger"
|
let testName = "testInteger"
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
if let integer = result?.firstObject as? Int {
|
if let integer = result.first as? Int {
|
||||||
XCTAssertEqual(integer, 20)
|
XCTAssertEqual(integer, 20)
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have Integer as result")
|
XCTFail("Should have Integer as result")
|
||||||
@ -99,8 +99,8 @@ class SocketTestCases: NSObject {
|
|||||||
|
|
||||||
static func testDouble(abstractSocketSend:SocketSendFunction) {
|
static func testDouble(abstractSocketSend:SocketSendFunction) {
|
||||||
let testName = "testDouble"
|
let testName = "testDouble"
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
if let double = result?.firstObject as? NSNumber {
|
if let double = result.first as? NSNumber {
|
||||||
XCTAssertEqual(double.floatValue, 1.2)
|
XCTAssertEqual(double.floatValue, 1.2)
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have Double as result")
|
XCTFail("Should have Double as result")
|
||||||
@ -113,8 +113,8 @@ class SocketTestCases: NSObject {
|
|||||||
let testName = "testJSONWithBuffer"
|
let testName = "testJSONWithBuffer"
|
||||||
let data = "0".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
|
let data = "0".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
|
||||||
|
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
if let json = result?.firstObject as? NSDictionary {
|
if let json = result.first as? NSDictionary {
|
||||||
XCTAssertEqual((json.valueForKey("testString")! as! String), "test")
|
XCTAssertEqual((json.valueForKey("testString")! as! String), "test")
|
||||||
XCTAssertEqual((json.valueForKey("testNumber")! as! Int), 15)
|
XCTAssertEqual((json.valueForKey("testNumber")! as! Int), 15)
|
||||||
XCTAssertEqual((json.valueForKey("testArray")! as! Array<AnyObject>).count, 2)
|
XCTAssertEqual((json.valueForKey("testArray")! as! Array<AnyObject>).count, 2)
|
||||||
@ -132,8 +132,8 @@ class SocketTestCases: NSObject {
|
|||||||
|
|
||||||
static func testJSON(abstractSocketSend:SocketSendFunction) {
|
static func testJSON(abstractSocketSend:SocketSendFunction) {
|
||||||
let testName = "testJSON"
|
let testName = "testJSON"
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
if let json = result?.firstObject as? NSDictionary {
|
if let json = result.first as? NSDictionary {
|
||||||
XCTAssertEqual((json.valueForKey("testString")! as! String), "test")
|
XCTAssertEqual((json.valueForKey("testString")! as! String), "test")
|
||||||
XCTAssertEqual(json.valueForKey("testNumber")! as? Int, 15)
|
XCTAssertEqual(json.valueForKey("testNumber")! as? Int, 15)
|
||||||
XCTAssertEqual((json.valueForKey("testArray")! as! Array<AnyObject>).count, 2)
|
XCTAssertEqual((json.valueForKey("testArray")! as! Array<AnyObject>).count, 2)
|
||||||
@ -151,8 +151,8 @@ class SocketTestCases: NSObject {
|
|||||||
|
|
||||||
static func testUnicode(abstractSocketSend:SocketSendFunction) {
|
static func testUnicode(abstractSocketSend:SocketSendFunction) {
|
||||||
let testName = "testUnicode"
|
let testName = "testUnicode"
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
if let unicode = result?.firstObject as? String {
|
if let unicode = result.first as? String {
|
||||||
XCTAssertEqual(unicode, "🚄")
|
XCTAssertEqual(unicode, "🚄")
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have String as result")
|
XCTFail("Should have String as result")
|
||||||
@ -163,37 +163,37 @@ class SocketTestCases: NSObject {
|
|||||||
|
|
||||||
static func testMultipleItemsWithBuffer(abstractSocketMultipleSend:(testName:String, emitData:Array<AnyObject>, callback:NormalCallback)->()) {
|
static func testMultipleItemsWithBuffer(abstractSocketMultipleSend:(testName:String, emitData:Array<AnyObject>, callback:NormalCallback)->()) {
|
||||||
let testName = "testMultipleItemsWithBuffer"
|
let testName = "testMultipleItemsWithBuffer"
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
XCTAssertEqual(result!.count, 5)
|
XCTAssertEqual(result.count, 5)
|
||||||
if result!.count != 5 {
|
if result.count != 5 {
|
||||||
XCTFail("Fatal Fail. Lost some Data")
|
XCTFail("Fatal Fail. Lost some Data")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let array = result?.firstObject as? Array<AnyObject> {
|
if let array = result.first as? Array<AnyObject> {
|
||||||
XCTAssertEqual((array.last! as! Int), 2)
|
XCTAssertEqual((array.last! as! Int), 2)
|
||||||
XCTAssertEqual((array.first! as! Int), 1)
|
XCTAssertEqual((array.first! as! Int), 1)
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have Array as result")
|
XCTFail("Should have Array as result")
|
||||||
}
|
}
|
||||||
if let dict = result?[1] as? NSDictionary {
|
if let dict = result[1] as? NSDictionary {
|
||||||
XCTAssertEqual((dict.valueForKey("test") as! String), "bob")
|
XCTAssertEqual((dict.valueForKey("test") as! String), "bob")
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have NSDictionary as result")
|
XCTFail("Should have NSDictionary as result")
|
||||||
}
|
}
|
||||||
if let number = result?[2] as? Int {
|
if let number = result[2] as? Int {
|
||||||
XCTAssertEqual(number, 25)
|
XCTAssertEqual(number, 25)
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have Integer as result")
|
XCTFail("Should have Integer as result")
|
||||||
}
|
}
|
||||||
if let string = result?[3] as? String {
|
if let string = result[3] as? String {
|
||||||
XCTAssertEqual(string, "polo")
|
XCTAssertEqual(string, "polo")
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have Integer as result")
|
XCTFail("Should have Integer as result")
|
||||||
}
|
}
|
||||||
if let data = result?[4] as? NSData {
|
if let data = result[4] as? NSData {
|
||||||
let string = NSString(data: data, encoding: NSUTF8StringEncoding)!
|
let string = NSString(data: data, encoding: NSUTF8StringEncoding)!
|
||||||
XCTAssertEqual(string, "gakgakgak2")
|
XCTAssertEqual(string, "gakgakgak2")
|
||||||
}else {
|
}else {
|
||||||
@ -207,36 +207,36 @@ class SocketTestCases: NSObject {
|
|||||||
|
|
||||||
static func testMultipleItems(abstractSocketMultipleSend:(testName:String, emitData:Array<AnyObject>, callback:NormalCallback)->()) {
|
static func testMultipleItems(abstractSocketMultipleSend:(testName:String, emitData:Array<AnyObject>, callback:NormalCallback)->()) {
|
||||||
let testName = "testMultipleItems"
|
let testName = "testMultipleItems"
|
||||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
func didGetResult(result:[AnyObject], ack:SocketAckEmitter?) {
|
||||||
XCTAssertEqual(result!.count, 5)
|
XCTAssertEqual(result.count, 5)
|
||||||
if result!.count != 5 {
|
if result.count != 5 {
|
||||||
XCTFail("Fatal Fail. Lost some Data")
|
XCTFail("Fatal Fail. Lost some Data")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let array = result?.firstObject as? Array<AnyObject> {
|
if let array = result.first as? Array<AnyObject> {
|
||||||
XCTAssertEqual((array.last! as! Int), 2)
|
XCTAssertEqual((array.last! as! Int), 2)
|
||||||
XCTAssertEqual((array.first! as! Int), 1)
|
XCTAssertEqual((array.first! as! Int), 1)
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have Array as result")
|
XCTFail("Should have Array as result")
|
||||||
}
|
}
|
||||||
if let dict = result?[1] as? NSDictionary {
|
if let dict = result[1] as? NSDictionary {
|
||||||
XCTAssertEqual((dict.valueForKey("test") as! String), "bob")
|
XCTAssertEqual((dict.valueForKey("test") as! String), "bob")
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have NSDictionary as result")
|
XCTFail("Should have NSDictionary as result")
|
||||||
}
|
}
|
||||||
if let number = result?[2] as? Int {
|
if let number = result[2] as? Int {
|
||||||
XCTAssertEqual(number, 25)
|
XCTAssertEqual(number, 25)
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have Integer as result")
|
XCTFail("Should have Integer as result")
|
||||||
}
|
}
|
||||||
if let string = result?[3] as? String {
|
if let string = result[3] as? String {
|
||||||
XCTAssertEqual(string, "polo")
|
XCTAssertEqual(string, "polo")
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have Integer as result")
|
XCTFail("Should have Integer as result")
|
||||||
}
|
}
|
||||||
if let bool = result?[4] as? NSNumber {
|
if let bool = result[4] as? NSNumber {
|
||||||
XCTAssertFalse(bool.boolValue)
|
XCTAssertFalse(bool.boolValue)
|
||||||
}else {
|
}else {
|
||||||
XCTFail("Should have NSNumber as result")
|
XCTFail("Should have NSNumber as result")
|
||||||
|
|||||||
43
SocketIOClientSwift/SocketAckEmitter.swift
Normal file
43
SocketIOClientSwift/SocketAckEmitter.swift
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
//
|
||||||
|
// SocketAckEmitter.swift
|
||||||
|
// Socket.IO-Client-Swift
|
||||||
|
//
|
||||||
|
// Created by Erik Little on 9/16/15.
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
|
||||||
|
public final class SocketAckEmitter: NSObject {
|
||||||
|
let socket: SocketIOClient
|
||||||
|
let ackNum: Int
|
||||||
|
|
||||||
|
init(socket: SocketIOClient, ackNum: Int) {
|
||||||
|
self.socket = socket
|
||||||
|
self.ackNum = ackNum
|
||||||
|
}
|
||||||
|
|
||||||
|
public func with(items: AnyObject...) {
|
||||||
|
socket.emitAck(ackNum, withItems: items)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func with(items: [AnyObject]) {
|
||||||
|
socket.emitAck(ackNum, withItems: items)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -56,7 +56,7 @@ struct SocketAckManager {
|
|||||||
acks.insert(SocketAck(ack: ack, callback: callback))
|
acks.insert(SocketAck(ack: ack, callback: callback))
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func executeAck(ack: Int, items: [AnyObject]?) {
|
mutating func executeAck(ack: Int, items: [AnyObject]) {
|
||||||
let callback = acks.remove(SocketAck(ack: ack))
|
let callback = acks.remove(SocketAck(ack: ack))
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue()) {
|
dispatch_async(dispatch_get_main_queue()) {
|
||||||
|
|||||||
@ -24,40 +24,23 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
private func emitAckCallback(socket: SocketIOClient?, num: Int?)
|
private func emitAckCallback(socket: SocketIOClient, num: Int?) -> SocketAckEmitter? {
|
||||||
(items: AnyObject...) -> Void {
|
return num != nil ? SocketAckEmitter(socket: socket, ackNum: num!) : nil
|
||||||
socket?.emitAck(num ?? -1, withItems: items)
|
|
||||||
}
|
|
||||||
|
|
||||||
private func emitAckCallbackObjectiveC(socket: SocketIOClient?, num: Int?)
|
|
||||||
(items: NSArray) -> Void {
|
|
||||||
socket?.emitAck(num ?? -1, withItems: items as [AnyObject])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SocketEventHandler {
|
struct SocketEventHandler {
|
||||||
let event: String
|
let event: String
|
||||||
|
let callback: NormalCallback
|
||||||
let id: NSUUID
|
let id: NSUUID
|
||||||
let callback: NormalCallback?
|
|
||||||
let callBackObjectiveC: NormalCallbackObjectiveC?
|
|
||||||
|
|
||||||
init(event: String, id: NSUUID = NSUUID(), callback: NormalCallback) {
|
init(event: String, id: NSUUID = NSUUID(), callback: NormalCallback) {
|
||||||
self.event = event
|
self.event = event
|
||||||
self.id = id
|
self.id = id
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.callBackObjectiveC = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init(event: String, id: NSUUID = NSUUID(), callback: NormalCallbackObjectiveC) {
|
func executeCallback(items: [AnyObject], withAck ack: Int? = nil, withAckType type: Int? = nil,
|
||||||
self.event = event
|
withSocket socket: SocketIOClient) {
|
||||||
self.id = id
|
self.callback(items, emitAckCallback(socket, num: ack))
|
||||||
self.callback = nil
|
|
||||||
self.callBackObjectiveC = callback
|
|
||||||
}
|
|
||||||
|
|
||||||
func executeCallback(items:NSArray? = nil, withAck ack:Int? = nil, withAckType type:Int? = nil,
|
|
||||||
withSocket socket:SocketIOClient? = nil) {
|
|
||||||
self.callback != nil ?
|
|
||||||
self.callback?(items, emitAckCallback(socket, num: ack))
|
|
||||||
: self.callBackObjectiveC?(items, emitAckCallbackObjectiveC(socket, num: ack))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -210,7 +210,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
|
|
||||||
// Don't handle as internal because something crazy could happen where
|
// Don't handle as internal because something crazy could happen where
|
||||||
// we disconnect before it's handled
|
// we disconnect before it's handled
|
||||||
handleEvent("connect", data: nil, isInternalMessage: false)
|
handleEvent("connect", data: [], isInternalMessage: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func didDisconnect(reason: String) {
|
func didDisconnect(reason: String) {
|
||||||
@ -331,13 +331,13 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
Logger.log("Handling ack: %@ with data: %@", type: logType, args: ack, data ?? "")
|
Logger.log("Handling ack: %@ with data: %@", type: logType, args: ack, data ?? "")
|
||||||
|
|
||||||
ackHandlers.executeAck(ack,
|
ackHandlers.executeAck(ack,
|
||||||
items: (data as? [AnyObject]?) ?? (data != nil ? [data!] : nil))
|
items: (data as? [AnyObject]) ?? (data != nil ? [data!] : []))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Causes an event to be handled. Only use if you know what you're doing.
|
Causes an event to be handled. Only use if you know what you're doing.
|
||||||
*/
|
*/
|
||||||
public func handleEvent(event: String, data: [AnyObject]?, isInternalMessage: Bool,
|
public func handleEvent(event: String, data: [AnyObject], isInternalMessage: Bool,
|
||||||
wantsAck ack: Int? = nil) {
|
wantsAck ack: Int? = nil) {
|
||||||
guard status == .Connected || isInternalMessage else {
|
guard status == .Connected || isInternalMessage else {
|
||||||
return
|
return
|
||||||
@ -358,7 +358,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dispatch_async(handleQueue) {
|
dispatch_async(handleQueue) {
|
||||||
handler.executeCallback(data)
|
handler.executeCallback(data, withAck: ack, withSocket: self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -412,16 +412,6 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
handlers.append(handler)
|
handlers.append(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Adds a handler for an event.
|
|
||||||
*/
|
|
||||||
public func onObjectiveC(event: String, callback: NormalCallbackObjectiveC) {
|
|
||||||
Logger.log("Adding handler for event: %@", type: logType, args: event)
|
|
||||||
|
|
||||||
let handler = SocketEventHandler(event: event, callback: callback)
|
|
||||||
handlers.append(handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Adds a single-use handler for an event.
|
Adds a single-use handler for an event.
|
||||||
*/
|
*/
|
||||||
@ -430,7 +420,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
|
|
||||||
let id = NSUUID()
|
let id = NSUUID()
|
||||||
|
|
||||||
let handler = SocketEventHandler(event: event, id: id) {[weak self] (data, ack: AckEmitter?) in
|
let handler = SocketEventHandler(event: event, id: id) {[weak self] data, ack in
|
||||||
guard let this = self else {return}
|
guard let this = self else {return}
|
||||||
this.handlers = ContiguousArray(this.handlers.filter {$0.id != id})
|
this.handlers = ContiguousArray(this.handlers.filter {$0.id != id})
|
||||||
callback(data, ack)
|
callback(data, ack)
|
||||||
@ -439,23 +429,6 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
handlers.append(handler)
|
handlers.append(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Adds a single-use handler for an event.
|
|
||||||
*/
|
|
||||||
public func once(event event: String, callback: NormalCallbackObjectiveC) {
|
|
||||||
Logger.log("Adding once handler for event: %@", type: logType, args: event)
|
|
||||||
|
|
||||||
let id = NSUUID()
|
|
||||||
|
|
||||||
let handler = SocketEventHandler(event: event, id: id) {[weak self] (data, ack: AckEmitterObjectiveC?) in
|
|
||||||
guard let this = self else {return}
|
|
||||||
this.handlers = ContiguousArray(this.handlers.filter {$0.id != id})
|
|
||||||
callback(data, ack)
|
|
||||||
}
|
|
||||||
|
|
||||||
handlers.append(handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Removes all handlers.
|
Removes all handlers.
|
||||||
Can be used after disconnecting to break any potential remaining retain cycles.
|
Can be used after disconnecting to break any potential remaining retain cycles.
|
||||||
|
|||||||
@ -31,7 +31,7 @@ class SocketParser {
|
|||||||
private static func handleEvent(p: SocketPacket, socket: SocketIOClient) {
|
private static func handleEvent(p: SocketPacket, socket: SocketIOClient) {
|
||||||
guard isCorrectNamespace(p.nsp, socket) else { return }
|
guard isCorrectNamespace(p.nsp, socket) else { return }
|
||||||
|
|
||||||
socket.handleEvent(p.event, data: p.args,
|
socket.handleEvent(p.event, data: p.args ?? [],
|
||||||
isInternalMessage: false, wantsAck: p.id)
|
isInternalMessage: false, wantsAck: p.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ class SocketParser {
|
|||||||
packet.fillInPlaceholders()
|
packet.fillInPlaceholders()
|
||||||
|
|
||||||
if packet.type != .BinaryAck {
|
if packet.type != .BinaryAck {
|
||||||
socket.handleEvent(packet.event, data: packet.args,
|
socket.handleEvent(packet.event, data: packet.args ?? [],
|
||||||
isInternalMessage: false, wantsAck: packet.id)
|
isInternalMessage: false, wantsAck: packet.id)
|
||||||
} else {
|
} else {
|
||||||
socket.handleAck(packet.id, data: packet.args)
|
socket.handleAck(packet.id, data: packet.args)
|
||||||
|
|||||||
@ -24,10 +24,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public typealias AckCallback = (NSArray?) -> Void
|
public typealias AckCallback = ([AnyObject]) -> Void
|
||||||
public typealias AckEmitter = (AnyObject...) -> Void
|
public typealias NormalCallback = ([AnyObject], SocketAckEmitter?) -> Void
|
||||||
public typealias AckEmitterObjectiveC = (NSArray) -> Void
|
public typealias OnAckCallback = (timeoutAfter: UInt64, callback: AckCallback) -> Void
|
||||||
public typealias NormalCallback = (NSArray?, AckEmitter?) -> Void
|
|
||||||
public typealias NormalCallbackObjectiveC = (NSArray?, AckEmitterObjectiveC?) -> Void
|
|
||||||
public typealias OnAckCallback = (timeoutAfter:UInt64, callback:AckCallback) -> Void
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user