simplify namespace api

This commit is contained in:
Erik 2016-01-02 17:38:19 -05:00
parent 7acce7d18e
commit 8584b90d3c
3 changed files with 9 additions and 16 deletions

View File

@ -178,7 +178,7 @@ Methods
9. `connect(timeoutAfter timeoutAfter: Int, withTimeoutHandler handler: (() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called. 9. `connect(timeoutAfter timeoutAfter: Int, withTimeoutHandler handler: (() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called.
10. `close()` - Closes the socket. Once a socket is closed it should not be reopened. 10. `close()` - Closes the socket. Once a socket is closed it should not be reopened.
11. `reconnect()` - Causes the client to reconnect to the server. 11. `reconnect()` - Causes the client to reconnect to the server.
12. `joinNamespace()` - Causes the client to join nsp. Shouldn't need to be called unless you change nsp manually. 12. `joinNamespace(namespace: String)` - Causes the client to join namespace. Shouldn't need to be called unless you change namespaces manually.
13. `leaveNamespace()` - Causes the client to leave the nsp and go back to / 13. `leaveNamespace()` - Causes the client to leave the nsp and go back to /
14. `off(event: String)` - Removes all event handlers for event. 14. `off(event: String)` - Removes all event handlers for event.
15. `off(id id: NSUUID)` - Removes the event that corresponds to id. 15. `off(id id: NSUUID)` - Removes the event that corresponds to id.

View File

@ -358,22 +358,15 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
} }
/** /**
Joins nsp if it is not / Joins namespace
*/
public func joinNamespace() {
DefaultSocketLogger.Logger.log("Joining namespace", type: logType)
if nsp != "/" {
engine?.send("0\(nsp)", withData: [])
}
}
/**
Joins namespace /
*/ */
public func joinNamespace(namespace: String) { public func joinNamespace(namespace: String) {
self.nsp = namespace nsp = namespace
joinNamespace()
if nsp != "/" {
DefaultSocketLogger.Logger.log("Joining namespace", type: logType)
engine?.send("0\(nsp)", withData: [])
}
} }
/** /**

View File

@ -30,7 +30,7 @@ class SocketParser {
private static func handleConnect(p: SocketPacket, socket: SocketIOClient) { private static func handleConnect(p: SocketPacket, socket: SocketIOClient) {
if p.nsp == "/" && socket.nsp != "/" { if p.nsp == "/" && socket.nsp != "/" {
socket.joinNamespace() socket.joinNamespace(socket.nsp)
} else if p.nsp != "/" && socket.nsp == "/" { } else if p.nsp != "/" && socket.nsp == "/" {
socket.didConnect() socket.didConnect()
} else { } else {