add leavenamepsace method, expose joinNamespace
This commit is contained in:
parent
f54153f3d4
commit
bb3d7fbded
@ -118,6 +118,8 @@ Methods
|
|||||||
8. `connect(#timeoutAfter:Int, withTimeoutHandler handler:(() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called.
|
8. `connect(#timeoutAfter:Int, withTimeoutHandler handler:(() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called.
|
||||||
9. `close(#fast:Bool)` - Closes the socket. Once a socket is closed it should not be reopened. Pass true to fast if you're closing from a background task.
|
9. `close(#fast:Bool)` - Closes the socket. Once a socket is closed it should not be reopened. Pass true to fast if you're closing from a background task.
|
||||||
10. `reconnect()` - Causes the client to reconnect to the server.
|
10. `reconnect()` - Causes the client to reconnect to the server.
|
||||||
|
11. `joinNamespace()` - Causes the client to join nsp. Shouldn't need to be called unless you change nsp manually.
|
||||||
|
12. `leaveNamespace()` - Causes the client to leave the nsp and go back to /
|
||||||
|
|
||||||
Client Events
|
Client Events
|
||||||
------
|
------
|
||||||
|
|||||||
@ -34,6 +34,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
|||||||
private typealias Probe = (msg:String, type:PacketType, data:ContiguousArray<NSData>?)
|
private typealias Probe = (msg:String, type:PacketType, data:ContiguousArray<NSData>?)
|
||||||
private typealias ProbeWaitQueue = [Probe]
|
private typealias ProbeWaitQueue = [Probe]
|
||||||
|
|
||||||
|
private let allowedCharacterSet = NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[]\" {}").invertedSet
|
||||||
private let workQueue = NSOperationQueue()
|
private let workQueue = NSOperationQueue()
|
||||||
private let emitQueue = dispatch_queue_create("engineEmitQueue", DISPATCH_QUEUE_SERIAL)
|
private let emitQueue = dispatch_queue_create("engineEmitQueue", DISPATCH_QUEUE_SERIAL)
|
||||||
private let parseQueue = dispatch_queue_create("engineParseQueue", DISPATCH_QUEUE_SERIAL)
|
private let parseQueue = dispatch_queue_create("engineParseQueue", DISPATCH_QUEUE_SERIAL)
|
||||||
@ -167,17 +168,16 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if params != nil {
|
if params != nil {
|
||||||
let allowedCharacterSet = NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[]\" {}").invertedSet
|
|
||||||
|
|
||||||
for (key, value) in params! {
|
for (key, value) in params! {
|
||||||
let keyEsc = key.stringByAddingPercentEncodingWithAllowedCharacters(
|
let keyEsc = key.stringByAddingPercentEncodingWithAllowedCharacters(
|
||||||
allowedCharacterSet)!
|
self.allowedCharacterSet)!
|
||||||
urlPolling += "&\(keyEsc)="
|
urlPolling += "&\(keyEsc)="
|
||||||
urlWebSocket += "&\(keyEsc)="
|
urlWebSocket += "&\(keyEsc)="
|
||||||
|
|
||||||
if value is String {
|
if value is String {
|
||||||
let valueEsc = (value as! String).stringByAddingPercentEncodingWithAllowedCharacters(
|
let valueEsc = (value as! String).stringByAddingPercentEncodingWithAllowedCharacters(
|
||||||
allowedCharacterSet)!
|
self.allowedCharacterSet)!
|
||||||
urlPolling += "\(valueEsc)"
|
urlPolling += "\(valueEsc)"
|
||||||
urlWebSocket += "\(valueEsc)"
|
urlWebSocket += "\(valueEsc)"
|
||||||
} else {
|
} else {
|
||||||
@ -219,7 +219,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
|||||||
if self.websocket || self.waitingForPoll || !self.connected {
|
if self.websocket || self.waitingForPoll || !self.connected {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
self.waitingForPoll = true
|
self.waitingForPoll = true
|
||||||
let req = NSMutableURLRequest(URL: NSURL(string: self.urlPolling! + "&sid=\(self.sid)&b64=1")!)
|
let req = NSMutableURLRequest(URL: NSURL(string: self.urlPolling! + "&sid=\(self.sid)&b64=1")!)
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
|||||||
if this.polling {
|
if this.polling {
|
||||||
this.handlePollingFailed(err.localizedDescription)
|
this.handlePollingFailed(err.localizedDescription)
|
||||||
} else {
|
} else {
|
||||||
NSLog(err.localizedDescription)
|
SocketLogger.err(err.localizedDescription, client: this)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -263,7 +263,6 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
|||||||
|
|
||||||
if this.fastUpgrade {
|
if this.fastUpgrade {
|
||||||
this.doFastUpgrade()
|
this.doFastUpgrade()
|
||||||
return
|
|
||||||
} else if !this.closed && this.polling {
|
} else if !this.closed && this.polling {
|
||||||
this.doPoll()
|
this.doPoll()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -404,7 +404,20 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func joinNamespace() {
|
/**
|
||||||
|
Leaves nsp and goes back to /
|
||||||
|
*/
|
||||||
|
public func leaveNamespace() {
|
||||||
|
if self.nsp != "/" {
|
||||||
|
self.engine?.send("1/\(self.nsp)", withData: nil)
|
||||||
|
self.nsp = "/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Joins nsp if it is not /
|
||||||
|
*/
|
||||||
|
public func joinNamespace() {
|
||||||
SocketLogger.log("Joining namespace", client: self)
|
SocketLogger.log("Joining namespace", client: self)
|
||||||
|
|
||||||
if self.nsp != "/" {
|
if self.nsp != "/" {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user