diff --git a/README.md b/README.md index e0bd71a..ca086e9 100644 --- a/README.md +++ b/README.md @@ -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. 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. -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 / 14. `off(event: String)` - Removes all event handlers for event. 15. `off(id id: NSUUID)` - Removes the event that corresponds to id. diff --git a/Source/SocketIOClient.swift b/Source/SocketIOClient.swift index 928203b..cffb783 100644 --- a/Source/SocketIOClient.swift +++ b/Source/SocketIOClient.swift @@ -358,22 +358,15 @@ public final class SocketIOClient: NSObject, SocketEngineClient { } /** - Joins nsp if it is not / - */ - public func joinNamespace() { - DefaultSocketLogger.Logger.log("Joining namespace", type: logType) - - if nsp != "/" { - engine?.send("0\(nsp)", withData: []) - } - } - - /** - Joins namespace / + Joins namespace */ public func joinNamespace(namespace: String) { - self.nsp = namespace - joinNamespace() + nsp = namespace + + if nsp != "/" { + DefaultSocketLogger.Logger.log("Joining namespace", type: logType) + engine?.send("0\(nsp)", withData: []) + } } /** diff --git a/Source/SocketParser.swift b/Source/SocketParser.swift index 872a5e8..4faf5d5 100644 --- a/Source/SocketParser.swift +++ b/Source/SocketParser.swift @@ -30,7 +30,7 @@ class SocketParser { private static func handleConnect(p: SocketPacket, socket: SocketIOClient) { if p.nsp == "/" && socket.nsp != "/" { - socket.joinNamespace() + socket.joinNamespace(socket.nsp) } else if p.nsp != "/" && socket.nsp == "/" { socket.didConnect() } else {