refactors
This commit is contained in:
parent
31adcd4728
commit
72b6565510
@ -466,23 +466,22 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func sendPing() {
|
private func sendPing() {
|
||||||
if !connected {
|
guard connected else { return }
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//Server is not responding
|
// Server is not responding
|
||||||
if pongsMissed > pongsMissedMax {
|
if pongsMissed > pongsMissedMax {
|
||||||
client?.engineDidClose(reason: "Ping timeout")
|
client?.engineDidClose(reason: "Ping timeout")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if let pingInterval = pingInterval {
|
guard let pingInterval = pingInterval else { return }
|
||||||
pongsMissed += 1
|
|
||||||
write("", withType: .ping, withData: [])
|
pongsMissed += 1
|
||||||
|
write("", withType: .ping, withData: [])
|
||||||
let time = DispatchTime.now() + Double(Int64(pingInterval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: time) {[weak self] in self?.sendPing() }
|
let time = DispatchTime.now() + Double(Int64(pingInterval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
|
||||||
}
|
DispatchQueue.main.asyncAfter(deadline: time) {[weak self] in self?.sendPing() }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Moves from long-polling to websockets
|
// Moves from long-polling to websockets
|
||||||
@ -532,6 +531,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
|
|||||||
|
|
||||||
if closed {
|
if closed {
|
||||||
client?.engineDidClose(reason: "Disconnect")
|
client?.engineDidClose(reason: "Disconnect")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user