refactor
This commit is contained in:
parent
f5cf2b8de5
commit
c7d75b6b83
@ -356,43 +356,43 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func handleOpen(openData: String) {
|
private func handleOpen(openData: String) {
|
||||||
do {
|
guard let json = try? openData.toNSDictionary() else {
|
||||||
let json = try openData.toNSDictionary()
|
|
||||||
guard let sid = json["sid"] as? String else {
|
|
||||||
client?.engineDidError(reason: "Open packet contained no sid")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
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, let 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(reason: "Connect")
|
|
||||||
} catch {
|
|
||||||
didError(reason: "Error parsing open packet")
|
didError(reason: "Error parsing open packet")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guard let sid = json["sid"] as? String else {
|
||||||
|
didError(reason: "Open packet contained no sid")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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, let 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(reason: "Connect")
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handlePong(with message: String) {
|
private func handlePong(with message: String) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user