This commit is contained in:
parent
9512c8b9ac
commit
f008f116a6
@ -47,9 +47,9 @@ Methods
|
||||
-------
|
||||
1. `socket.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. `socket.onAny(callback:((event:String, items:AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
|
||||
3. `socket.emit(event:String, _ args:AnyObject...)` - Sends a message. Can send multiple args.
|
||||
3. `socket.emit(event:String, _ items:AnyObject...)` - Sends a message. Can send multiple items.
|
||||
4. `socket.emitObjc(event:String, withItems items:[AnyObject])` - `emit` for Objective-C
|
||||
5. `socket.emitWithAck(event:String, _ args:AnyObject...) -> SocketAckHandler` - Sends a message that requests an acknowledgement from the server. Returns a SocketAckHandler which you can use to add an onAck handler. See example.
|
||||
5. `socket.emitWithAck(event:String, _ items:AnyObject...) -> SocketAckHandler` - Sends a message that requests an acknowledgement from the server. Returns a SocketAckHandler which you can use to add an onAck handler. See example.
|
||||
6. `socket.emitWithAckObjc(event:String, withItems items:[AnyObject]) -> SocketAckHandler` - `emitWithAck` for Objective-C.
|
||||
7. `socket.connect()` - Establishes a connection to the server. A "connect" event is fired upon successful connection.
|
||||
8. `socket.connectWithParams(params:[String: AnyObject])` - Establishes a connection to the server passing the specified params. A "connect" event is fired upon successful connection.
|
||||
|
||||
@ -200,13 +200,13 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
||||
/**
|
||||
Send a message to the server
|
||||
*/
|
||||
public func emit(event:String, _ args:AnyObject...) {
|
||||
public func emit(event:String, _ items:AnyObject...) {
|
||||
if !self.connected {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch_async(self.emitQueue) {[weak self] in
|
||||
self?._emit(event, args)
|
||||
self?._emit(event, items)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -215,14 +215,21 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
||||
Same as emit, but meant for Objective-C
|
||||
*/
|
||||
public func emitObjc(event:String, withItems items:[AnyObject]) {
|
||||
self.emit(event, items)
|
||||
if !self.connected {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch_async(self.emitQueue) {[weak self] in
|
||||
self?._emit(event, items)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Sends a message to the server, requesting an ack. Use the onAck method of SocketAckHandler to add
|
||||
an ack.
|
||||
*/
|
||||
public func emitWithAck(event:String, _ args:AnyObject...) -> SocketAckHandler {
|
||||
public func emitWithAck(event:String, _ items:AnyObject...) -> SocketAckHandler {
|
||||
if !self.connected {
|
||||
return SocketAckHandler(event: "fail", socket: self)
|
||||
}
|
||||
@ -233,7 +240,7 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
||||
self.ackHandlers.append(ackHandler)
|
||||
|
||||
dispatch_async(self.emitQueue) {[weak self, ack = self.currentAck] in
|
||||
self?._emit(event, args, ack: ack)
|
||||
self?._emit(event, items, ack: ack)
|
||||
return
|
||||
}
|
||||
|
||||
@ -244,7 +251,21 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
||||
Same as emitWithAck, but for Objective-C
|
||||
*/
|
||||
public func emitWithAckObjc(event:String, withItems items:[AnyObject]) -> SocketAckHandler {
|
||||
return self.emitWithAck(event, items)
|
||||
if !self.connected {
|
||||
return SocketAckHandler(event: "fail", socket: self)
|
||||
}
|
||||
|
||||
self.currentAck++
|
||||
let ackHandler = SocketAckHandler(event: event,
|
||||
ackNum: self.currentAck, socket: self)
|
||||
self.ackHandlers.append(ackHandler)
|
||||
|
||||
dispatch_async(self.emitQueue) {[weak self, ack = self.currentAck] in
|
||||
self?._emit(event, items, ack: ack)
|
||||
return
|
||||
}
|
||||
|
||||
return ackHandler
|
||||
}
|
||||
|
||||
private func _emit(event:String, _ args:[AnyObject], ack:Int? = nil) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user