move websocketurl plus sid to computed property

This commit is contained in:
Erik 2016-01-26 14:17:11 -05:00
parent 228c0c7c9b
commit d71f81745e
3 changed files with 9 additions and 5 deletions

View File

@ -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!)

View File

@ -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<NSData, String> {
if websocket {
var byteArray = [UInt8](count: 1, repeatedValue: 0x4)

View File

@ -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)
}