clean up some internal apis
This commit is contained in:
parent
cf14eb27a3
commit
b35004ef60
@ -24,23 +24,16 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
private func emitAckCallback(socket: SocketIOClient, num: Int?) -> SocketAckEmitter? {
|
private func emitAckCallback(socket: SocketIOClient, num: Int) -> SocketAckEmitter? {
|
||||||
return num != nil ? SocketAckEmitter(socket: socket, ackNum: num!) : nil
|
return num != -1 ? SocketAckEmitter(socket: socket, ackNum: num) : nil
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SocketEventHandler {
|
struct SocketEventHandler {
|
||||||
let event: String
|
let event: String
|
||||||
let callback: NormalCallback
|
|
||||||
let id: NSUUID
|
let id: NSUUID
|
||||||
|
let callback: NormalCallback
|
||||||
|
|
||||||
init(event: String, id: NSUUID = NSUUID(), callback: NormalCallback) {
|
func executeCallback(items: [AnyObject], withAck ack: Int = -1, withSocket socket: SocketIOClient) {
|
||||||
self.event = event
|
|
||||||
self.id = id
|
|
||||||
self.callback = callback
|
|
||||||
}
|
|
||||||
|
|
||||||
func executeCallback(items: [AnyObject], withAck ack: Int? = nil, withAckType type: Int? = nil,
|
|
||||||
withSocket socket: SocketIOClient) {
|
|
||||||
self.callback(items, emitAckCallback(socket, num: ack))
|
self.callback(items, emitAckCallback(socket, num: ack))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -341,7 +341,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
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,
|
||||||
withAck ack: Int? = nil) {
|
withAck ack: Int = -1) {
|
||||||
guard status == .Connected || isInternalMessage else {
|
guard status == .Connected || isInternalMessage else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -352,11 +352,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
self.anyHandler?(SocketAnyEvent(event: event, items: data))
|
self.anyHandler?(SocketAnyEvent(event: event, items: data))
|
||||||
|
|
||||||
for handler in self.handlers where handler.event == event {
|
for handler in self.handlers where handler.event == event {
|
||||||
if let ack = ack {
|
handler.executeCallback(data, withAck: ack, withSocket: self)
|
||||||
handler.executeCallback(data, withAck: ack, withSocket: self)
|
|
||||||
} else {
|
|
||||||
handler.executeCallback(data, withAck: ack, withSocket: self)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,7 +402,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
public func on(event: String, callback: NormalCallback) {
|
public func on(event: String, callback: NormalCallback) {
|
||||||
DefaultSocketLogger.Logger.log("Adding handler for event: %@", type: logType, args: event)
|
DefaultSocketLogger.Logger.log("Adding handler for event: %@", type: logType, args: event)
|
||||||
|
|
||||||
let handler = SocketEventHandler(event: event, callback: callback)
|
let handler = SocketEventHandler(event: event, id: NSUUID(), callback: callback)
|
||||||
handlers.append(handler)
|
handlers.append(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user