diff --git a/Source/SocketEngine.swift b/Source/SocketEngine.swift index 99f5b43..54ede87 100644 --- a/Source/SocketEngine.swift +++ b/Source/SocketEngine.swift @@ -243,10 +243,7 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb } private func createWebsocketAndConnect() { - let component = NSURLComponents(URL: urlWebSocket, resolvingAgainstBaseURL: false)! - component.query = component.query! + (sid == "" ? "" : "&sid=\(sid)") - - ws = WebSocket(url: component.URL!) + ws = WebSocket(url: urlWebSocketWithSid) if cookies != nil { let headers = NSHTTPCookie.requestHeaderFieldsWithCookies(cookies!) diff --git a/Source/SocketEngineSpec.swift b/Source/SocketEngineSpec.swift index 1703d98..691c151 100644 --- a/Source/SocketEngineSpec.swift +++ b/Source/SocketEngineSpec.swift @@ -67,6 +67,13 @@ extension SocketEngineSpec { return com.URL! } + var urlWebSocketWithSid: NSURL { + let com = NSURLComponents(URL: urlWebSocket, resolvingAgainstBaseURL: false)! + com.query = com.query! + (sid == "" ? "" : "&sid=\(sid)") + + return com.URL! + } + func createBinaryDataForSend(data: NSData) -> Either { if websocket { var byteArray = [UInt8](count: 1, repeatedValue: 0x4) diff --git a/Source/SocketIOClient.swift b/Source/SocketIOClient.swift index c349202..abc0ec8 100644 --- a/Source/SocketIOClient.swift +++ b/Source/SocketIOClient.swift @@ -413,7 +413,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketParsable let id = NSUUID() let handler = SocketEventHandler(event: event, id: id) {[weak self] data, ack in - guard let this = self else {return} + guard let this = self else { return } this.off(id: id) callback(data, ack) }