add leavenamepsace method, expose joinNamespace

This commit is contained in:
Erik 2015-05-14 13:22:25 -04:00
parent f54153f3d4
commit bb3d7fbded
3 changed files with 21 additions and 7 deletions

View File

@ -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.
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.
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
------

View File

@ -34,6 +34,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
private typealias Probe = (msg:String, type:PacketType, data:ContiguousArray<NSData>?)
private typealias ProbeWaitQueue = [Probe]
private let allowedCharacterSet = NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[]\" {}").invertedSet
private let workQueue = NSOperationQueue()
private let emitQueue = dispatch_queue_create("engineEmitQueue", 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 {
let allowedCharacterSet = NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[]\" {}").invertedSet
for (key, value) in params! {
let keyEsc = key.stringByAddingPercentEncodingWithAllowedCharacters(
allowedCharacterSet)!
self.allowedCharacterSet)!
urlPolling += "&\(keyEsc)="
urlWebSocket += "&\(keyEsc)="
if value is String {
let valueEsc = (value as! String).stringByAddingPercentEncodingWithAllowedCharacters(
allowedCharacterSet)!
self.allowedCharacterSet)!
urlPolling += "\(valueEsc)"
urlWebSocket += "\(valueEsc)"
} else {
@ -246,7 +246,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
if this.polling {
this.handlePollingFailed(err.localizedDescription)
} else {
NSLog(err.localizedDescription)
SocketLogger.err(err.localizedDescription, client: this)
}
return
}
@ -263,7 +263,6 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
if this.fastUpgrade {
this.doFastUpgrade()
return
} else if !this.closed && this.polling {
this.doPoll()
}

View File

@ -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)
if self.nsp != "/" {