Merge branch 'swift-2' of https://github.com/socketio/socket.io-client-swift into swift-2
This commit is contained in:
commit
f46629f850
@ -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.
|
- `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 `""`
|
- `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.
|
- `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
|
Methods
|
||||||
-------
|
-------
|
||||||
|
|||||||
@ -51,12 +51,10 @@ struct SocketEventHandler {
|
|||||||
self.callBackObjectiveC = callback
|
self.callBackObjectiveC = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeCallback(items: [AnyObject]? = nil, withAck ack: Int? = nil, withAckType type: Int? = nil,
|
func executeCallback(items:NSArray? = nil, withAck ack:Int? = nil, withAckType type:Int? = nil,
|
||||||
withSocket socket: SocketIOClient? = nil) {
|
withSocket socket:SocketIOClient? = nil) {
|
||||||
dispatch_async(dispatch_get_main_queue()) {
|
self.callback != nil ?
|
||||||
self.callback != nil ?
|
self.callback?(items, emitAckCallback(socket, num: ack))
|
||||||
self.callback?(items, emitAckCallback(socket, num: ack))
|
: self.callBackObjectiveC?(items, emitAckCallbackObjectiveC(socket, num: ack))
|
||||||
: self.callBackObjectiveC?(items, emitAckCallbackObjectiveC(socket, num: ack))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
|
|||||||
|
|
||||||
public let socketURL: String
|
public let socketURL: String
|
||||||
public let handleAckQueue = dispatch_queue_create("handleAckQueue", DISPATCH_QUEUE_SERIAL)
|
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 let emitQueue = dispatch_queue_create("emitQueue", DISPATCH_QUEUE_SERIAL)
|
||||||
public var closed: Bool {
|
public var closed: Bool {
|
||||||
return _closed
|
return _closed
|
||||||
@ -111,6 +111,12 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
|
|||||||
self.reconnectWait = abs(reconnectWait)
|
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()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,16 +379,20 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
|
|||||||
args: event, data ?? "")
|
args: event, data ?? "")
|
||||||
|
|
||||||
if anyHandler != nil {
|
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))
|
self?.anyHandler?(SocketAnyEvent(event: event, items: data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for handler in handlers where handler.event == event {
|
for handler in handlers where handler.event == event {
|
||||||
if ack != nil {
|
if ack != nil {
|
||||||
handler.executeCallback(data, withAck: ack!, withSocket: self)
|
dispatch_async(handleQueue) {[weak self] in
|
||||||
|
handler.executeCallback(data, withAck: ack!, withSocket: self)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
handler.executeCallback(data)
|
dispatch_async(handleQueue) {
|
||||||
|
handler.executeCallback(data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -427,6 +437,9 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
|
|||||||
handlers.append(handler)
|
handlers.append(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Adds a handler for an event.
|
||||||
|
*/
|
||||||
public func onObjectiveC(event: String, callback: NormalCallbackObjectiveC) {
|
public func onObjectiveC(event: String, callback: NormalCallbackObjectiveC) {
|
||||||
SocketLogger.log("Adding handler for event: %@", client: self, args: event)
|
SocketLogger.log("Adding handler for event: %@", client: self, args: event)
|
||||||
|
|
||||||
@ -434,13 +447,13 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
|
|||||||
handlers.append(handler)
|
handlers.append(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Removes all handlers.
|
Removes all handlers.
|
||||||
Can be used after disconnecting to break any potential remaining retain cycles.
|
Can be used after disconnecting to break any potential remaining retain cycles.
|
||||||
*/
|
*/
|
||||||
public func removeAllHandlers() {
|
public func removeAllHandlers() {
|
||||||
handlers.removeAll(keepCapacity: false)
|
handlers.removeAll(keepCapacity: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Adds a handler that will be called on every event.
|
Adds a handler that will be called on every event.
|
||||||
|
|||||||
@ -388,7 +388,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
|||||||
|
|
||||||
///validates the HTTP is a 101 as per the RFC spec
|
///validates the HTTP is a 101 as per the RFC spec
|
||||||
private func validateResponse(buffer: UnsafePointer<UInt8>, bufferLen: Int) -> Bool {
|
private func validateResponse(buffer: UnsafePointer<UInt8>, bufferLen: Int) -> Bool {
|
||||||
let response = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, 0).takeRetainedValue()
|
let response = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, false).takeRetainedValue()
|
||||||
CFHTTPMessageAppendBytes(response, buffer, bufferLen)
|
CFHTTPMessageAppendBytes(response, buffer, bufferLen)
|
||||||
if CFHTTPMessageGetResponseStatusCode(response) != 101 {
|
if CFHTTPMessageGetResponseStatusCode(response) != 101 {
|
||||||
return false
|
return false
|
||||||
@ -854,7 +854,7 @@ public class Security {
|
|||||||
}
|
}
|
||||||
var policy: SecPolicyRef
|
var policy: SecPolicyRef
|
||||||
if self.validatedDN {
|
if self.validatedDN {
|
||||||
policy = SecPolicyCreateSSL(1, domain)
|
policy = SecPolicyCreateSSL(true, domain)
|
||||||
} else {
|
} else {
|
||||||
policy = SecPolicyCreateBasicX509()
|
policy = SecPolicyCreateBasicX509()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user