Merge master

This commit is contained in:
Erik 2015-08-05 06:12:35 -04:00
commit 514193e6ec
3 changed files with 28 additions and 19 deletions

View File

@ -122,6 +122,7 @@ Options
- `sessionDelegate: NSURLSessionDelegate` Sets an NSURLSessionDelegate for the underlying engine. Useful if you need to handle self-signed certs. Default is nil.
- `path: String` - If the server uses a custom path. ex: `"/swift"`. Default is `""`
- `extraHeaders: [String: String]?` - Adds custom headers to the initial request. Default is nil.
- `handleQueue: dispatch_queue_t` - The dispatch queue that handlers are run on. Default is the main queue.
Methods
-------

View File

@ -51,12 +51,10 @@ struct SocketEventHandler {
self.callBackObjectiveC = callback
}
func executeCallback(items: [AnyObject]? = nil, withAck ack: Int? = nil, withAckType type: Int? = nil,
withSocket socket: SocketIOClient? = nil) {
dispatch_async(dispatch_get_main_queue()) {
self.callback != nil ?
self.callback?(items, emitAckCallback(socket, num: ack))
: self.callBackObjectiveC?(items, emitAckCallbackObjectiveC(socket, num: ack))
}
func executeCallback(items:NSArray? = nil, withAck ack:Int? = nil, withAckType type:Int? = nil,
withSocket socket:SocketIOClient? = nil) {
self.callback != nil ?
self.callback?(items, emitAckCallback(socket, num: ack))
: self.callBackObjectiveC?(items, emitAckCallbackObjectiveC(socket, num: ack))
}
}

View File

@ -45,7 +45,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
public let socketURL: String
public let handleAckQueue = dispatch_queue_create("handleAckQueue", DISPATCH_QUEUE_SERIAL)
public let handleQueue = dispatch_queue_create("handleQueue", DISPATCH_QUEUE_SERIAL)
public let handleQueue: dispatch_queue_t!
public let emitQueue = dispatch_queue_create("emitQueue", DISPATCH_QUEUE_SERIAL)
public var closed: Bool {
return _closed
@ -111,6 +111,12 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
self.reconnectWait = abs(reconnectWait)
}
if let handleQueue = opts?["handleQueue"] as? dispatch_queue_t {
self.handleQueue = handleQueue
} else {
self.handleQueue = dispatch_get_main_queue()
}
super.init()
}
@ -373,16 +379,20 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
args: event, data ?? "")
if anyHandler != nil {
dispatch_async(dispatch_get_main_queue()) {[weak self] in
dispatch_async(handleQueue) {[weak self] in
self?.anyHandler?(SocketAnyEvent(event: event, items: data))
}
}
for handler in handlers where handler.event == event {
if ack != nil {
handler.executeCallback(data, withAck: ack!, withSocket: self)
dispatch_async(handleQueue) {[weak self] in
handler.executeCallback(data, withAck: ack!, withSocket: self)
}
} else {
handler.executeCallback(data)
dispatch_async(handleQueue) {
handler.executeCallback(data)
}
}
}
}
@ -436,14 +446,14 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
let handler = SocketEventHandler(event: event, callback: callback)
handlers.append(handler)
}
/**
Removes all handlers.
Can be used after disconnecting to break any potential remaining retain cycles.
*/
public func removeAllHandlers() {
handlers.removeAll(keepCapacity: false)
}
/**
Removes all handlers.
Can be used after disconnecting to break any potential remaining retain cycles.
*/
public func removeAllHandlers() {
handlers.removeAll(keepCapacity: false)
}
/**
Adds a handler that will be called on every event.