Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ socket.on("currentAmount") {data, ack in
socket.emit("update", ["amount": cur + 2.50])
}

ack?("Got your currentAmount", "dude")
ack?.with("Got your currentAmount", "dude")
}
}

Expand All @@ -28,18 +28,18 @@ socket.connect()
```objective-c
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");
}];

[socket onObjectiveC:@"currentAmount" callback:^(NSArray* data, void (^ack)(NSArray*)) {
[socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) {
double cur = [[data objectAtIndex:0] floatValue];

[socket emitWithAck:@"canUpdate" withItems:@[@(cur)]](0, ^(NSArray* data) {
[socket emit:@"update" withItems:@[@{@"amount": @(cur + 2.50)}]];
});

ack(@[@"Got your currentAmount, ", @"dude"]);
[ack with:@[@"Got your currentAmount, ", @"dude"]];
}];

[socket connect];
Expand Down Expand Up @@ -128,8 +128,8 @@ Options

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.
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.
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. `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.
4. `emit(event: String, _ items: AnyObject...)` - Sends a message. Can send multiple items.
5. `emit(event: String, withItems items: [AnyObject])` - `emit` for Objective-C
Expand All @@ -141,8 +141,6 @@ Methods
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.
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
------
Expand Down
22 changes: 18 additions & 4 deletions Socket.IO-Client-Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
74781D5B1B7E83930042CACA /* 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 */; };
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 */; };
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
Expand Down Expand Up @@ -162,6 +168,7 @@
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>"; };
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>"; };
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>"; };
Expand Down Expand Up @@ -268,16 +275,16 @@
572EF2281B51F16C00EEBB58 /* SocketIO-iOSTests */ = {
isa = PBXGroup;
children = (
945B65421B63D9DB0081E995 /* SocketEmitTest.swift */,
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */,
94ADAC4A1B6632DD00FD79AE /* SocketAcknowledgementTest.swift */,
945B65421B63D9DB0081E995 /* SocketEmitTest.swift */,
94ADAC481B652D3300FD79AE /* SocketNamespaceEmitTest.swift */,
94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */,
941A4AB91B67A56C00C42318 /* TestKind.swift */,
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */,
94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */,
94CB8F0C1B6E66E60019ED53 /* AbstractSocketTest.swift */,
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */,
941A4AB91B67A56C00C42318 /* TestKind.swift */,
572EF2291B51F16C00EEBB58 /* Supporting Files */,
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */,
);
path = "SocketIO-iOSTests";
sourceTree = "<group>";
Expand Down Expand Up @@ -327,6 +334,7 @@
5764DF7B1B51F24A004FF46E /* Source */ = {
isa = PBXGroup;
children = (
749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */,
5764DF7C1B51F254004FF46E /* SocketAckManager.swift */,
5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */,
5764DF7E1B51F254004FF46E /* SocketEngine.swift */,
Expand Down Expand Up @@ -582,6 +590,7 @@
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */,
5764DF8D1B51F254004FF46E /* SocketEngine.swift in Sources */,
5764DF9B1B51F254004FF46E /* SocketParser.swift in Sources */,
749A7F8B1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
5764DF9D1B51F254004FF46E /* SocketTypes.swift in Sources */,
5764DF8F1B51F254004FF46E /* SocketEngineClient.swift in Sources */,
5764DF911B51F254004FF46E /* SocketEventHandler.swift in Sources */,
Expand All @@ -607,6 +616,7 @@
945B653A1B5FCEEA0081E995 /* SocketFixUTF8.swift in Sources */,
945B65391B5FCEEA0081E995 /* SocketEventHandler.swift in Sources */,
94CB8F0B1B6E48B90019ED53 /* SocketTestCases.swift in Sources */,
749A7F8C1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
945B65371B5FCEEA0081E995 /* SocketEngine.swift in Sources */,
945B65351B5FCEEA0081E995 /* SocketAckManager.swift in Sources */,
941A4ABA1B67A56C00C42318 /* TestKind.swift in Sources */,
Expand Down Expand Up @@ -635,6 +645,7 @@
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */,
5764DF8E1B51F254004FF46E /* SocketEngine.swift in Sources */,
5764DF9C1B51F254004FF46E /* SocketParser.swift in Sources */,
749A7F8F1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
5764DF9E1B51F254004FF46E /* SocketTypes.swift in Sources */,
5764DF901B51F254004FF46E /* SocketEngineClient.swift in Sources */,
5764DF921B51F254004FF46E /* SocketEventHandler.swift in Sources */,
Expand All @@ -654,6 +665,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
749A7F901BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
572EF24A1B51F18A00EEBB58 /* SocketIO_MacTests.swift in Sources */,
74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */,
);
Expand All @@ -666,6 +678,7 @@
57425F9C1BA3A46000BDAAC1 /* SocketStringReader.swift in Sources */,
57425F9D1BA3A46000BDAAC1 /* SocketEngine.swift in Sources */,
57425F9E1BA3A46000BDAAC1 /* SocketParser.swift in Sources */,
749A7F8D1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
57425F9F1BA3A46000BDAAC1 /* SocketTypes.swift in Sources */,
57425FA01BA3A46000BDAAC1 /* SocketEngineClient.swift in Sources */,
57425FA11BA3A46000BDAAC1 /* SocketEventHandler.swift in Sources */,
Expand All @@ -691,6 +704,7 @@
57425FDF1BA3A4F100BDAAC1 /* SocketFixUTF8.swift in Sources */,
57425FE01BA3A4F100BDAAC1 /* SocketEventHandler.swift in Sources */,
57425FE11BA3A4F100BDAAC1 /* SocketTestCases.swift in Sources */,
749A7F8E1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
57425FE21BA3A4F100BDAAC1 /* SocketEngine.swift in Sources */,
57425FE31BA3A4F100BDAAC1 /* SocketAckManager.swift in Sources */,
57425FE41BA3A4F100BDAAC1 /* TestKind.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand All @@ -85,10 +88,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
13 changes: 7 additions & 6 deletions SocketIO-iOSTests/AbstractSocketTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AbstractSocketTest: XCTestCase {
func socketMultipleEmit(testName:String, emitData:Array<AnyObject>, callback:NormalCallback){
let finalTestname = generateTestName(testName)
weak var expection = self.expectationWithDescription(finalTestname)
func didGetEmit(result:NSArray?, ack:AckEmitter?) {
func didGetEmit(result:[AnyObject], ack:SocketAckEmitter?) {
callback(result, ack)
if let expection = expection {
expection.fulfill()
Expand All @@ -61,7 +61,7 @@ class AbstractSocketTest: XCTestCase {
func socketEmit(testName:String, emitData:AnyObject?, callback:NormalCallback){
let finalTestname = generateTestName(testName)
weak var expection = self.expectationWithDescription(finalTestname)
func didGetEmit(result:NSArray?, ack:AckEmitter?) {
func didGetEmit(result:[AnyObject], ack:SocketAckEmitter?) {
callback(result, ack)
if let expection = expection {
expection.fulfill()
Expand All @@ -79,11 +79,12 @@ class AbstractSocketTest: XCTestCase {
waitForExpectationsWithTimeout(SocketEmitTest.TEST_TIMEOUT, handler: nil)
}


func socketAcknwoledgeMultiple(testName:String, Data:Array<AnyObject>, callback:NormalCallback){
let finalTestname = generateTestName(testName)
weak var expection = self.expectationWithDescription(finalTestname)
func didGetResult(result:NSArray?) {
callback(result, nil)
func didGetResult(result: [AnyObject]) {
callback(result, SocketAckEmitter(socket: AbstractSocketTest.socket, ackNum: -1))
if let expection = expection {
expection.fulfill()
}
Expand All @@ -96,8 +97,8 @@ class AbstractSocketTest: XCTestCase {
func socketAcknwoledge(testName:String, Data:AnyObject?, callback:NormalCallback){
let finalTestname = generateTestName(testName)
weak var expection = self.expectationWithDescription(finalTestname)
func didGet(result:NSArray?) {
callback(result, nil)
func didGet(result:[AnyObject]) {
callback(result, SocketAckEmitter(socket: AbstractSocketTest.socket, ackNum: -1))
if let expection = expection {
expection.fulfill()
}
Expand Down
3 changes: 1 addition & 2 deletions SocketIO-iOSTests/SocketAckManagerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ class SocketAckManagerTest: XCTestCase {
func testAddAcks() {
let callbackExpection = self.expectationWithDescription("callbackExpection")
let itemsArray = ["Hi", "ho"]
func callback(items: NSArray?) {
func callback(items: [AnyObject]) {
callbackExpection.fulfill()
items?.isEqualToArray(itemsArray)
}
ackManager.addAck(1, callback: callback)
ackManager.executeAck(1, items: itemsArray)
Expand Down
Loading