engine websocket url to nsurl
This commit is contained in:
parent
c9ac69f408
commit
d912796fa5
@ -46,9 +46,9 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
public private(set) var probing = false
|
public private(set) var probing = false
|
||||||
public private(set) var session: NSURLSession?
|
public private(set) var session: NSURLSession?
|
||||||
public private(set) var sid = ""
|
public private(set) var sid = ""
|
||||||
public private(set) var socketPath = "/engine.io"
|
public private(set) var socketPath = "/engine.io/"
|
||||||
public private(set) var urlPolling = ""
|
public private(set) var urlPolling = ""
|
||||||
public private(set) var urlWebSocket = ""
|
public private(set) var urlWebSocket = NSURL()
|
||||||
public private(set) var websocket = false
|
public private(set) var websocket = false
|
||||||
public private(set) var ws: WebSocket?
|
public private(set) var ws: WebSocket?
|
||||||
|
|
||||||
@ -199,9 +199,9 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func createURLs(params: [String: AnyObject]?) -> (String, String) {
|
private func createURLs(params: [String: AnyObject]?) -> (String, NSURL) {
|
||||||
if client == nil {
|
if client == nil {
|
||||||
return ("", "")
|
return ("", NSURL())
|
||||||
}
|
}
|
||||||
|
|
||||||
let absURL = url.absoluteString["https?://"] <~ ""
|
let absURL = url.absoluteString["https?://"] <~ ""
|
||||||
@ -215,14 +215,17 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
|
|
||||||
let socketURL = "\(baseURL)\(socketPath)/?transport="
|
let socketURL = "\(baseURL)\(socketPath)/?transport="
|
||||||
var urlPolling: String
|
var urlPolling: String
|
||||||
var urlWebSocket: String
|
var queryString = "transport=websocket"
|
||||||
|
let urlWebSocket = NSURLComponents(string: url.absoluteString)!
|
||||||
|
|
||||||
|
urlWebSocket.path = socketPath
|
||||||
|
|
||||||
if secure {
|
if secure {
|
||||||
urlPolling = "https://" + socketURL + "polling"
|
urlPolling = "https://" + socketURL + "polling"
|
||||||
urlWebSocket = "wss://" + socketURL + "websocket"
|
urlWebSocket.scheme = "wss"
|
||||||
} else {
|
} else {
|
||||||
urlPolling = "http://" + socketURL + "polling"
|
urlPolling = "http://" + socketURL + "polling"
|
||||||
urlWebSocket = "ws://" + socketURL + "websocket"
|
urlWebSocket.scheme = "ws"
|
||||||
}
|
}
|
||||||
|
|
||||||
if params != nil {
|
if params != nil {
|
||||||
@ -230,27 +233,29 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
let keyEsc = key.stringByAddingPercentEncodingWithAllowedCharacters(
|
let keyEsc = key.stringByAddingPercentEncodingWithAllowedCharacters(
|
||||||
allowedCharacterSet)!
|
allowedCharacterSet)!
|
||||||
urlPolling += "&\(keyEsc)="
|
urlPolling += "&\(keyEsc)="
|
||||||
urlWebSocket += "&\(keyEsc)="
|
queryString += "&\(keyEsc)="
|
||||||
|
|
||||||
if value is String {
|
if value is String {
|
||||||
let valueEsc = (value as! String).stringByAddingPercentEncodingWithAllowedCharacters(
|
let valueEsc = (value as! String).stringByAddingPercentEncodingWithAllowedCharacters(
|
||||||
allowedCharacterSet)!
|
allowedCharacterSet)!
|
||||||
urlPolling += "\(valueEsc)"
|
urlPolling += String(valueEsc)
|
||||||
urlWebSocket += "\(valueEsc)"
|
queryString += String(value)
|
||||||
} else {
|
} else {
|
||||||
urlPolling += "\(value)"
|
urlPolling += String(value)
|
||||||
urlWebSocket += "\(value)"
|
queryString += String(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (urlPolling, urlWebSocket)
|
urlWebSocket.query = queryString
|
||||||
|
return (urlPolling, urlWebSocket.URL!)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func createWebsocketAndConnect() {
|
private func createWebsocketAndConnect() {
|
||||||
let wsUrl = urlWebSocket + (sid == "" ? "" : "&sid=\(sid)")
|
let component = NSURLComponents(URL: urlWebSocket, resolvingAgainstBaseURL: false)!
|
||||||
|
component.query = component.query! + (sid == "" ? "" : "&sid=\(sid)")
|
||||||
|
|
||||||
ws = WebSocket(url: NSURL(string: wsUrl)!)
|
ws = WebSocket(url: component.URL!)
|
||||||
|
|
||||||
if cookies != nil {
|
if cookies != nil {
|
||||||
let headers = NSHTTPCookie.requestHeaderFieldsWithCookies(cookies!)
|
let headers = NSHTTPCookie.requestHeaderFieldsWithCookies(cookies!)
|
||||||
|
|||||||
@ -43,7 +43,7 @@ import Foundation
|
|||||||
var sid: String { get }
|
var sid: String { get }
|
||||||
var socketPath: String { get }
|
var socketPath: String { get }
|
||||||
var urlPolling: String { get }
|
var urlPolling: String { get }
|
||||||
var urlWebSocket: String { get }
|
var urlWebSocket: NSURL { get }
|
||||||
var websocket: Bool { get }
|
var websocket: Bool { get }
|
||||||
|
|
||||||
init(client: SocketEngineClient, url: NSURL, options: NSDictionary?)
|
init(client: SocketEngineClient, url: NSURL, options: NSDictionary?)
|
||||||
|
|||||||
@ -92,7 +92,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketParsable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.options.insertIgnore(.Path("/socket.io"))
|
self.options.insertIgnore(.Path("/socket.io/"))
|
||||||
|
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user