update readme. This api is probably going to change again
This commit is contained in:
parent
67afbcbd56
commit
f889d37e9b
13
README.md
13
README.md
@ -12,12 +12,12 @@ socket.on("connect") {data, ack in
|
|||||||
}
|
}
|
||||||
|
|
||||||
socket.on("currentAmount") {data, ack in
|
socket.on("currentAmount") {data, ack in
|
||||||
if let cur = data?[0] as? Double {
|
if let cur = data[0] as? Double {
|
||||||
socket.emitWithAck("canUpdate", cur)(timeoutAfter: 0) {data in
|
socket.emitWithAck("canUpdate", cur)(timeoutAfter: 0) {data in
|
||||||
socket.emit("update", ["amount": cur + 2.50])
|
socket.emit("update", ["amount": cur + 2.50])
|
||||||
}
|
}
|
||||||
|
|
||||||
ack?("Got your currentAmount", "dude")
|
ack?["Got your currentAmount", "dude"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,18 +28,18 @@ socket.connect()
|
|||||||
```objective-c
|
```objective-c
|
||||||
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" options:nil];
|
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" options:nil];
|
||||||
|
|
||||||
[socket onEvent:@"connect" callback:^(NSArray* data, void (^ack)(NSArray*)) {
|
[socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
|
||||||
NSLog(@"socket connected");
|
NSLog(@"socket connected");
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[socket onEvent:@"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[@[@"Got your currentAmount, ", @"dude"]];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[socket connect];
|
[socket connect];
|
||||||
@ -130,8 +130,7 @@ Options
|
|||||||
|
|
||||||
Methods
|
Methods
|
||||||
-------
|
-------
|
||||||
1. `on(event: 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: ((data: [AnyObject], ack: SocketAckEmitter?) -> 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. `on(event event: 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.
|
|
||||||
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user