move connectparams to the engine
This commit is contained in:
parent
3f57c7e0a9
commit
57670ec613
@ -29,6 +29,7 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
public let handleQueue = dispatch_queue_create("com.socketio.engineHandleQueue", DISPATCH_QUEUE_SERIAL)
|
public let handleQueue = dispatch_queue_create("com.socketio.engineHandleQueue", DISPATCH_QUEUE_SERIAL)
|
||||||
public let parseQueue = dispatch_queue_create("com.socketio.engineParseQueue", DISPATCH_QUEUE_SERIAL)
|
public let parseQueue = dispatch_queue_create("com.socketio.engineParseQueue", DISPATCH_QUEUE_SERIAL)
|
||||||
|
|
||||||
|
public var connectParams: [String: AnyObject]?
|
||||||
public var postWait = [String]()
|
public var postWait = [String]()
|
||||||
public var waitingForPoll = false
|
public var waitingForPoll = false
|
||||||
public var waitingForPost = false
|
public var waitingForPost = false
|
||||||
@ -47,8 +48,8 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
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 = NSURL(string: "http://localhost?default=")!
|
public private(set) var urlPolling = NSURL()
|
||||||
public private(set) var urlWebSocket = NSURL(string: "http://localhost?default=")!
|
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?
|
||||||
|
|
||||||
@ -63,7 +64,6 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
private let logType = "SocketEngine"
|
private let logType = "SocketEngine"
|
||||||
private let url: NSURL
|
private let url: NSURL
|
||||||
|
|
||||||
private var connectParams: [String: AnyObject]?
|
|
||||||
private var pingInterval: Double?
|
private var pingInterval: Double?
|
||||||
private var pingTimeout = 0.0 {
|
private var pingTimeout = 0.0 {
|
||||||
didSet {
|
didSet {
|
||||||
@ -83,6 +83,8 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
|
|
||||||
for option in options {
|
for option in options {
|
||||||
switch option {
|
switch option {
|
||||||
|
case let .ConnectParams(params):
|
||||||
|
connectParams = params
|
||||||
case let .SessionDelegate(delegate):
|
case let .SessionDelegate(delegate):
|
||||||
sessionDelegate = delegate
|
sessionDelegate = delegate
|
||||||
case let .ForcePolling(force):
|
case let .ForcePolling(force):
|
||||||
@ -105,6 +107,10 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super.init()
|
||||||
|
|
||||||
|
(urlPolling, urlWebSocket) = createURLs()
|
||||||
}
|
}
|
||||||
|
|
||||||
public convenience init(client: SocketEngineClient, url: NSURL, options: NSDictionary?) {
|
public convenience init(client: SocketEngineClient, url: NSURL, options: NSDictionary?) {
|
||||||
@ -199,7 +205,7 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func createURLs(params: [String: AnyObject]?) -> (NSURL, NSURL) {
|
private func createURLs() -> (NSURL, NSURL) {
|
||||||
if client == nil {
|
if client == nil {
|
||||||
return (NSURL(), NSURL())
|
return (NSURL(), NSURL())
|
||||||
}
|
}
|
||||||
@ -221,8 +227,8 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
urlWebSocket.scheme = "ws"
|
urlWebSocket.scheme = "ws"
|
||||||
}
|
}
|
||||||
|
|
||||||
if params != nil {
|
if connectParams != nil {
|
||||||
for (key, value) in params! {
|
for (key, value) in connectParams! {
|
||||||
queryString += "&\(key)=\(value)"
|
queryString += "&\(key)=\(value)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -370,22 +376,18 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func open(opts: [String: AnyObject]?) {
|
public func open() {
|
||||||
if connected {
|
if connected {
|
||||||
DefaultSocketLogger.Logger.error("Engine tried opening while connected. This is probably a programming error. "
|
DefaultSocketLogger.Logger.error("Engine tried opening while connected. This is probably a programming error. "
|
||||||
+ "Abandoning open attempt", type: logType)
|
+ "Abandoning open attempt", type: logType)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
connectParams = opts
|
|
||||||
|
|
||||||
DefaultSocketLogger.Logger.log("Starting engine", type: logType)
|
DefaultSocketLogger.Logger.log("Starting engine", type: logType)
|
||||||
DefaultSocketLogger.Logger.log("Handshaking", type: logType)
|
DefaultSocketLogger.Logger.log("Handshaking", type: logType)
|
||||||
|
|
||||||
resetEngine()
|
resetEngine()
|
||||||
|
|
||||||
(urlPolling, urlWebSocket) = createURLs(opts)
|
|
||||||
|
|
||||||
if forceWebsockets {
|
if forceWebsockets {
|
||||||
polling = false
|
polling = false
|
||||||
websocket = true
|
websocket = true
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import Foundation
|
|||||||
weak var client: SocketEngineClient? { get set }
|
weak var client: SocketEngineClient? { get set }
|
||||||
var closed: Bool { get }
|
var closed: Bool { get }
|
||||||
var connected: Bool { get }
|
var connected: Bool { get }
|
||||||
|
var connectParams: [String: AnyObject]? { get set }
|
||||||
var cookies: [NSHTTPCookie]? { get }
|
var cookies: [NSHTTPCookie]? { get }
|
||||||
var extraHeaders: [String: String]? { get }
|
var extraHeaders: [String: String]? { get }
|
||||||
var fastUpgrade: Bool { get }
|
var fastUpgrade: Bool { get }
|
||||||
@ -52,7 +53,7 @@ import Foundation
|
|||||||
func didError(error: String)
|
func didError(error: String)
|
||||||
func doFastUpgrade()
|
func doFastUpgrade()
|
||||||
func flushWaitingForPostToWebSocket()
|
func flushWaitingForPostToWebSocket()
|
||||||
func open(opts: [String: AnyObject]?)
|
func open()
|
||||||
func parseEngineData(data: NSData)
|
func parseEngineData(data: NSData)
|
||||||
func parseEngineMessage(message: String, fromPolling: Bool)
|
func parseEngineMessage(message: String, fromPolling: Bool)
|
||||||
func write(msg: String, withType type: SocketEnginePacketType, withData data: [NSData])
|
func write(msg: String, withType type: SocketEnginePacketType, withData data: [NSData])
|
||||||
|
|||||||
@ -30,7 +30,6 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketParsable
|
|||||||
public private(set) var engine: SocketEngineSpec?
|
public private(set) var engine: SocketEngineSpec?
|
||||||
public private(set) var status = SocketIOClientStatus.NotConnected
|
public private(set) var status = SocketIOClientStatus.NotConnected
|
||||||
|
|
||||||
public var connectParams: [String: AnyObject]?
|
|
||||||
public var forceNew = false
|
public var forceNew = false
|
||||||
public var nsp = "/"
|
public var nsp = "/"
|
||||||
public var options: Set<SocketIOClientOption>
|
public var options: Set<SocketIOClientOption>
|
||||||
@ -69,8 +68,6 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketParsable
|
|||||||
|
|
||||||
for option in options {
|
for option in options {
|
||||||
switch option {
|
switch option {
|
||||||
case let .ConnectParams(params):
|
|
||||||
connectParams = params
|
|
||||||
case let .Reconnects(reconnects):
|
case let .Reconnects(reconnects):
|
||||||
self.reconnects = reconnects
|
self.reconnects = reconnects
|
||||||
case let .ReconnectAttempts(attempts):
|
case let .ReconnectAttempts(attempts):
|
||||||
@ -164,9 +161,9 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketParsable
|
|||||||
status = .Connecting
|
status = .Connecting
|
||||||
|
|
||||||
if engine == nil || forceNew {
|
if engine == nil || forceNew {
|
||||||
addEngine().open(connectParams)
|
addEngine().open()
|
||||||
} else {
|
} else {
|
||||||
engine?.open(connectParams)
|
engine?.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
guard timeoutAfter != 0 else { return }
|
guard timeoutAfter != 0 else { return }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user