Skip to content

Commit 7bdf80d

Browse files
committed
Merge pull request #185 from socketio/api-cleanup
Api cleanup
2 parents 0233bce + 01b88f8 commit 7bdf80d

File tree

12 files changed

+136
-125
lines changed

12 files changed

+136
-125
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ socket.on("currentAmount") {data, ack in
1717
socket.emit("update", ["amount": cur + 2.50])
1818
}
1919

20-
ack?("Got your currentAmount", "dude")
20+
ack?.with("Got your currentAmount", "dude")
2121
}
2222
}
2323

@@ -28,18 +28,18 @@ socket.connect()
2828
```objective-c
2929
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" opts:nil];
3030

31-
[socket onObjectiveC:@"connect" callback:^(NSArray* data, void (^ack)(NSArray*)) {
31+
[socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
3232
NSLog(@"socket connected");
3333
}];
3434

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

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

42-
ack(@[@"Got your currentAmount, ", @"dude"]);
42+
[ack with:@[@"Got your currentAmount, ", @"dude"]];
4343
}];
4444

4545
[socket connect];
@@ -128,8 +128,8 @@ Options
128128

129129
Methods
130130
-------
131-
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.
132-
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.
131+
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.
132+
2. `once(event: String, callback: NormalCallback)` - Adds a handler that will only be executed once.
133133
3. `onAny(callback:((event: String, items: AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
134134
4. `emit(event: String, _ items: AnyObject...)` - Sends a message. Can send multiple items.
135135
5. `emit(event: String, withItems items: [AnyObject])` - `emit` for Objective-C
@@ -141,8 +141,6 @@ Methods
141141
11. `reconnect()` - Causes the client to reconnect to the server.
142142
12. `joinNamespace()` - Causes the client to join nsp. Shouldn't need to be called unless you change nsp manually.
143143
13. `leaveNamespace()` - Causes the client to leave the nsp and go back to /
144-
14. `once(event: String, callback: NormalCallback)` - Adds a handler that will only be executed once.
145-
15. `once(event event: String, callback: NormalCallbackObjectiveC)` - Adds a handler that will only be executed once.
146144

147145
Client Events
148146
------

Socket.IO-Client-Swift.xcodeproj/project.pbxproj

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@
8383
74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
8484
74781D5C1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
8585
74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
86+
749A7F8B1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
87+
749A7F8C1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
88+
749A7F8D1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
89+
749A7F8E1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
90+
749A7F8F1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
91+
749A7F901BA9D42D00782993 /* SocketAckEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */; settings = {ASSET_TAGS = (); }; };
8692
74D765621B9F0D870028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
8793
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
8894
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
@@ -162,6 +168,7 @@
162168
5764DF871B51F254004FF46E /* SwiftRegex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftRegex.swift; path = SocketIOClientSwift/SwiftRegex.swift; sourceTree = "<group>"; };
163169
5764DF881B51F254004FF46E /* WebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebSocket.swift; path = SocketIOClientSwift/WebSocket.swift; sourceTree = "<group>"; };
164170
74781D591B7E83930042CACA /* SocketIOClientStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketIOClientStatus.swift; path = SocketIOClientSwift/SocketIOClientStatus.swift; sourceTree = "<group>"; };
171+
749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketAckEmitter.swift; path = SocketIOClientSwift/SocketAckEmitter.swift; sourceTree = "<group>"; };
165172
74D765611B9F0D870028551C /* SocketStringReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SocketStringReader.swift; path = SocketIOClientSwift/SocketStringReader.swift; sourceTree = "<group>"; };
166173
941A4AB91B67A56C00C42318 /* TestKind.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestKind.swift; sourceTree = "<group>"; };
167174
94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketNamespaceAcknowledgementTest.swift; sourceTree = "<group>"; };
@@ -268,16 +275,16 @@
268275
572EF2281B51F16C00EEBB58 /* SocketIO-iOSTests */ = {
269276
isa = PBXGroup;
270277
children = (
271-
945B65421B63D9DB0081E995 /* SocketEmitTest.swift */,
278+
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */,
272279
94ADAC4A1B6632DD00FD79AE /* SocketAcknowledgementTest.swift */,
280+
945B65421B63D9DB0081E995 /* SocketEmitTest.swift */,
273281
94ADAC481B652D3300FD79AE /* SocketNamespaceEmitTest.swift */,
274282
94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */,
275-
941A4AB91B67A56C00C42318 /* TestKind.swift */,
283+
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */,
276284
94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */,
277285
94CB8F0C1B6E66E60019ED53 /* AbstractSocketTest.swift */,
278-
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */,
286+
941A4AB91B67A56C00C42318 /* TestKind.swift */,
279287
572EF2291B51F16C00EEBB58 /* Supporting Files */,
280-
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */,
281288
);
282289
path = "SocketIO-iOSTests";
283290
sourceTree = "<group>";
@@ -327,6 +334,7 @@
327334
5764DF7B1B51F24A004FF46E /* Source */ = {
328335
isa = PBXGroup;
329336
children = (
337+
749A7F8A1BA9D42D00782993 /* SocketAckEmitter.swift */,
330338
5764DF7C1B51F254004FF46E /* SocketAckManager.swift */,
331339
5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */,
332340
5764DF7E1B51F254004FF46E /* SocketEngine.swift */,
@@ -582,6 +590,7 @@
582590
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */,
583591
5764DF8D1B51F254004FF46E /* SocketEngine.swift in Sources */,
584592
5764DF9B1B51F254004FF46E /* SocketParser.swift in Sources */,
593+
749A7F8B1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
585594
5764DF9D1B51F254004FF46E /* SocketTypes.swift in Sources */,
586595
5764DF8F1B51F254004FF46E /* SocketEngineClient.swift in Sources */,
587596
5764DF911B51F254004FF46E /* SocketEventHandler.swift in Sources */,
@@ -607,6 +616,7 @@
607616
945B653A1B5FCEEA0081E995 /* SocketFixUTF8.swift in Sources */,
608617
945B65391B5FCEEA0081E995 /* SocketEventHandler.swift in Sources */,
609618
94CB8F0B1B6E48B90019ED53 /* SocketTestCases.swift in Sources */,
619+
749A7F8C1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
610620
945B65371B5FCEEA0081E995 /* SocketEngine.swift in Sources */,
611621
945B65351B5FCEEA0081E995 /* SocketAckManager.swift in Sources */,
612622
941A4ABA1B67A56C00C42318 /* TestKind.swift in Sources */,
@@ -635,6 +645,7 @@
635645
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */,
636646
5764DF8E1B51F254004FF46E /* SocketEngine.swift in Sources */,
637647
5764DF9C1B51F254004FF46E /* SocketParser.swift in Sources */,
648+
749A7F8F1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
638649
5764DF9E1B51F254004FF46E /* SocketTypes.swift in Sources */,
639650
5764DF901B51F254004FF46E /* SocketEngineClient.swift in Sources */,
640651
5764DF921B51F254004FF46E /* SocketEventHandler.swift in Sources */,
@@ -654,6 +665,7 @@
654665
isa = PBXSourcesBuildPhase;
655666
buildActionMask = 2147483647;
656667
files = (
668+
749A7F901BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
657669
572EF24A1B51F18A00EEBB58 /* SocketIO_MacTests.swift in Sources */,
658670
74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */,
659671
);
@@ -666,6 +678,7 @@
666678
57425F9C1BA3A46000BDAAC1 /* SocketStringReader.swift in Sources */,
667679
57425F9D1BA3A46000BDAAC1 /* SocketEngine.swift in Sources */,
668680
57425F9E1BA3A46000BDAAC1 /* SocketParser.swift in Sources */,
681+
749A7F8D1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
669682
57425F9F1BA3A46000BDAAC1 /* SocketTypes.swift in Sources */,
670683
57425FA01BA3A46000BDAAC1 /* SocketEngineClient.swift in Sources */,
671684
57425FA11BA3A46000BDAAC1 /* SocketEventHandler.swift in Sources */,
@@ -691,6 +704,7 @@
691704
57425FDF1BA3A4F100BDAAC1 /* SocketFixUTF8.swift in Sources */,
692705
57425FE01BA3A4F100BDAAC1 /* SocketEventHandler.swift in Sources */,
693706
57425FE11BA3A4F100BDAAC1 /* SocketTestCases.swift in Sources */,
707+
749A7F8E1BA9D42D00782993 /* SocketAckEmitter.swift in Sources */,
694708
57425FE21BA3A4F100BDAAC1 /* SocketEngine.swift in Sources */,
695709
57425FE31BA3A4F100BDAAC1 /* SocketAckManager.swift in Sources */,
696710
57425FE41BA3A4F100BDAAC1 /* TestKind.swift in Sources */,

Socket.IO-Client-Swift.xcodeproj/xcshareddata/xcschemes/SocketIO-Mac.xcscheme

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
</BuildActionEntries>
3838
</BuildAction>
3939
<TestAction
40+
buildConfiguration = "Debug"
4041
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4142
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
42-
shouldUseLaunchSchemeArgsEnv = "YES"
43-
buildConfiguration = "Debug">
43+
shouldUseLaunchSchemeArgsEnv = "YES">
4444
<Testables>
4545
<TestableReference
4646
skipped = "NO">
@@ -62,15 +62,18 @@
6262
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
6363
</BuildableReference>
6464
</MacroExpansion>
65+
<AdditionalOptions>
66+
</AdditionalOptions>
6567
</TestAction>
6668
<LaunchAction
69+
buildConfiguration = "Debug"
6770
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
6871
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
6972
launchStyle = "0"
7073
useCustomWorkingDirectory = "NO"
71-
buildConfiguration = "Debug"
7274
ignoresPersistentStateOnLaunch = "NO"
7375
debugDocumentVersioning = "YES"
76+
debugServiceExtension = "internal"
7477
allowLocationSimulation = "YES">
7578
<MacroExpansion>
7679
<BuildableReference
@@ -85,10 +88,10 @@
8588
</AdditionalOptions>
8689
</LaunchAction>
8790
<ProfileAction
91+
buildConfiguration = "Release"
8892
shouldUseLaunchSchemeArgsEnv = "YES"
8993
savedToolIdentifier = ""
9094
useCustomWorkingDirectory = "NO"
91-
buildConfiguration = "Release"
9295
debugDocumentVersioning = "YES">
9396
<MacroExpansion>
9497
<BuildableReference

SocketIO-iOSTests/AbstractSocketTest.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class AbstractSocketTest: XCTestCase {
4545
func socketMultipleEmit(testName:String, emitData:Array<AnyObject>, callback:NormalCallback){
4646
let finalTestname = generateTestName(testName)
4747
weak var expection = self.expectationWithDescription(finalTestname)
48-
func didGetEmit(result:NSArray?, ack:AckEmitter?) {
48+
func didGetEmit(result:[AnyObject], ack:SocketAckEmitter?) {
4949
callback(result, ack)
5050
if let expection = expection {
5151
expection.fulfill()
@@ -61,7 +61,7 @@ class AbstractSocketTest: XCTestCase {
6161
func socketEmit(testName:String, emitData:AnyObject?, callback:NormalCallback){
6262
let finalTestname = generateTestName(testName)
6363
weak var expection = self.expectationWithDescription(finalTestname)
64-
func didGetEmit(result:NSArray?, ack:AckEmitter?) {
64+
func didGetEmit(result:[AnyObject], ack:SocketAckEmitter?) {
6565
callback(result, ack)
6666
if let expection = expection {
6767
expection.fulfill()
@@ -79,11 +79,12 @@ class AbstractSocketTest: XCTestCase {
7979
waitForExpectationsWithTimeout(SocketEmitTest.TEST_TIMEOUT, handler: nil)
8080
}
8181

82+
8283
func socketAcknwoledgeMultiple(testName:String, Data:Array<AnyObject>, callback:NormalCallback){
8384
let finalTestname = generateTestName(testName)
8485
weak var expection = self.expectationWithDescription(finalTestname)
85-
func didGetResult(result:NSArray?) {
86-
callback(result, nil)
86+
func didGetResult(result: [AnyObject]) {
87+
callback(result, SocketAckEmitter(socket: AbstractSocketTest.socket, ackNum: -1))
8788
if let expection = expection {
8889
expection.fulfill()
8990
}
@@ -96,8 +97,8 @@ class AbstractSocketTest: XCTestCase {
9697
func socketAcknwoledge(testName:String, Data:AnyObject?, callback:NormalCallback){
9798
let finalTestname = generateTestName(testName)
9899
weak var expection = self.expectationWithDescription(finalTestname)
99-
func didGet(result:NSArray?) {
100-
callback(result, nil)
100+
func didGet(result:[AnyObject]) {
101+
callback(result, SocketAckEmitter(socket: AbstractSocketTest.socket, ackNum: -1))
101102
if let expection = expection {
102103
expection.fulfill()
103104
}

SocketIO-iOSTests/SocketAckManagerTest.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ class SocketAckManagerTest: XCTestCase {
1414
func testAddAcks() {
1515
let callbackExpection = self.expectationWithDescription("callbackExpection")
1616
let itemsArray = ["Hi", "ho"]
17-
func callback(items: NSArray?) {
17+
func callback(items: [AnyObject]) {
1818
callbackExpection.fulfill()
19-
items?.isEqualToArray(itemsArray)
2019
}
2120
ackManager.addAck(1, callback: callback)
2221
ackManager.executeAck(1, items: itemsArray)

0 commit comments

Comments
 (0)