Merge branch 'development'
* development: Refactor engine. Fix infinite recursion in configuration Don't send whole packet to handleConnect
This commit is contained in:
commit
89ab458a5f
@ -359,36 +359,38 @@ public final class SocketEngine : NSObject, NSURLSessionDelegate, SocketEnginePo
|
|||||||
private func handleOpen(openData: String) {
|
private func handleOpen(openData: String) {
|
||||||
do {
|
do {
|
||||||
let json = try openData.toNSDictionary()
|
let json = try openData.toNSDictionary()
|
||||||
|
guard let sid = json[sid] as? String else {
|
||||||
if let sid = json["sid"] as? String {
|
client?.engineDidError("Open packet contained no sid")
|
||||||
let upgradeWs: Bool
|
return
|
||||||
|
|
||||||
self.sid = sid
|
|
||||||
connected = true
|
|
||||||
|
|
||||||
if let upgrades = json["upgrades"] as? [String] {
|
|
||||||
upgradeWs = upgrades.contains("websocket")
|
|
||||||
} else {
|
|
||||||
upgradeWs = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if let pingInterval = json["pingInterval"] as? Double, pingTimeout = json["pingTimeout"] as? Double {
|
|
||||||
self.pingInterval = pingInterval / 1000.0
|
|
||||||
self.pingTimeout = pingTimeout / 1000.0
|
|
||||||
}
|
|
||||||
|
|
||||||
if !forcePolling && !forceWebsockets && upgradeWs {
|
|
||||||
createWebsocketAndConnect()
|
|
||||||
}
|
|
||||||
|
|
||||||
sendPing()
|
|
||||||
|
|
||||||
if !forceWebsockets {
|
|
||||||
doPoll()
|
|
||||||
}
|
|
||||||
|
|
||||||
client?.engineDidOpen("Connect")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let upgradeWs: Bool
|
||||||
|
|
||||||
|
self.sid = sid
|
||||||
|
connected = true
|
||||||
|
|
||||||
|
if let upgrades = json["upgrades"] as? [String] {
|
||||||
|
upgradeWs = upgrades.contains("websocket")
|
||||||
|
} else {
|
||||||
|
upgradeWs = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if let pingInterval = json["pingInterval"] as? Double, pingTimeout = json["pingTimeout"] as? Double {
|
||||||
|
self.pingInterval = pingInterval / 1000.0
|
||||||
|
self.pingTimeout = pingTimeout / 1000.0
|
||||||
|
}
|
||||||
|
|
||||||
|
if !forcePolling && !forceWebsockets && upgradeWs {
|
||||||
|
createWebsocketAndConnect()
|
||||||
|
}
|
||||||
|
|
||||||
|
sendPing()
|
||||||
|
|
||||||
|
if !forceWebsockets {
|
||||||
|
doPoll()
|
||||||
|
}
|
||||||
|
|
||||||
|
client?.engineDidOpen("Connect")
|
||||||
} catch {
|
} catch {
|
||||||
didError("Error parsing open packet")
|
didError("Error parsing open packet")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,7 +97,7 @@ public struct SocketIOClientConfiguration : ArrayLiteralConvertible, CollectionT
|
|||||||
|
|
||||||
@warn_unused_result
|
@warn_unused_result
|
||||||
public func prefixThrough(position: Index) -> SubSequence {
|
public func prefixThrough(position: Index) -> SubSequence {
|
||||||
return prefixThrough(position)
|
return backingArray.prefixThrough(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
@warn_unused_result
|
@warn_unused_result
|
||||||
|
|||||||
@ -32,8 +32,8 @@ extension SocketParsable {
|
|||||||
return nsp == self.nsp
|
return nsp == self.nsp
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleConnect(p: SocketPacket) {
|
private func handleConnect(packetNamespace: String) {
|
||||||
if p.nsp == "/" && nsp != "/" {
|
if packetNamespace == "/" && nsp != "/" {
|
||||||
joinNamespace(nsp)
|
joinNamespace(nsp)
|
||||||
} else {
|
} else {
|
||||||
didConnect()
|
didConnect()
|
||||||
@ -51,7 +51,7 @@ extension SocketParsable {
|
|||||||
case .BinaryAck where isCorrectNamespace(pack.nsp):
|
case .BinaryAck where isCorrectNamespace(pack.nsp):
|
||||||
waitingPackets.append(pack)
|
waitingPackets.append(pack)
|
||||||
case .Connect:
|
case .Connect:
|
||||||
handleConnect(pack)
|
handleConnect(pack.nsp)
|
||||||
case .Disconnect:
|
case .Disconnect:
|
||||||
didDisconnect("Got Disconnect")
|
didDisconnect("Got Disconnect")
|
||||||
case .Error:
|
case .Error:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user