move open logic to method
This commit is contained in:
parent
61b4628d3e
commit
2fdd1313a8
@ -356,6 +356,35 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
|||||||
postWait.removeAll(keepCapacity: true)
|
postWait.removeAll(keepCapacity: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func handleOpen(openData:String) {
|
||||||
|
var err:NSError?
|
||||||
|
let mesData = openData.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
|
||||||
|
|
||||||
|
if let json = NSJSONSerialization.JSONObjectWithData(mesData,
|
||||||
|
options: NSJSONReadingOptions.AllowFragments,
|
||||||
|
error: &err) as? NSDictionary, let sid = json["sid"] as? String {
|
||||||
|
self.sid = sid
|
||||||
|
_connected = true
|
||||||
|
|
||||||
|
if !forcePolling && !forceWebsockets {
|
||||||
|
createWebsocket(andConnect: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let pingInterval = json["pingInterval"] as? Int {
|
||||||
|
self.pingInterval = pingInterval / 1000
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
client?.didError("Engine failed to handshake")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
startPingTimer()
|
||||||
|
|
||||||
|
if !forceWebsockets {
|
||||||
|
doPoll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// A poll failed, tell the client about it
|
// A poll failed, tell the client about it
|
||||||
private func handlePollingFailed(reason:String) {
|
private func handlePollingFailed(reason:String) {
|
||||||
_connected = false
|
_connected = false
|
||||||
@ -498,34 +527,9 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
|||||||
upgradeTransport()
|
upgradeTransport()
|
||||||
}
|
}
|
||||||
} else if type == PacketType.OPEN {
|
} else if type == PacketType.OPEN {
|
||||||
var err:NSError?
|
|
||||||
|
|
||||||
message.removeAtIndex(message.startIndex)
|
message.removeAtIndex(message.startIndex)
|
||||||
let mesData = message.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
|
|
||||||
|
|
||||||
if let json = NSJSONSerialization.JSONObjectWithData(mesData,
|
handleOpen(message)
|
||||||
options: NSJSONReadingOptions.AllowFragments,
|
|
||||||
error: &err) as? NSDictionary, let sid = json["sid"] as? String {
|
|
||||||
self.sid = sid
|
|
||||||
_connected = true
|
|
||||||
|
|
||||||
if !forcePolling && !forceWebsockets {
|
|
||||||
createWebsocket(andConnect: true)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let pingInterval = json["pingInterval"] as? Int {
|
|
||||||
self.pingInterval = pingInterval / 1000
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
client?.didError("Engine failed to handshake")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
startPingTimer()
|
|
||||||
|
|
||||||
if !forceWebsockets {
|
|
||||||
doPoll()
|
|
||||||
}
|
|
||||||
} else if type == PacketType.CLOSE {
|
} else if type == PacketType.CLOSE {
|
||||||
if polling {
|
if polling {
|
||||||
client?.engineDidClose("Disconnect")
|
client?.engineDidClose("Disconnect")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user