don't lose ping precision
This commit is contained in:
parent
d8104f4bf8
commit
f6fa5b79ea
@ -123,10 +123,10 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
|
|||||||
|
|
||||||
private let url: URL
|
private let url: URL
|
||||||
|
|
||||||
private var pingInterval: Double?
|
private var pingInterval: Int?
|
||||||
private var pingTimeout = 0.0 {
|
private var pingTimeout = 0 {
|
||||||
didSet {
|
didSet {
|
||||||
pongsMissedMax = Int(pingTimeout / (pingInterval ?? 25))
|
pongsMissedMax = Int(pingTimeout / (pingInterval ?? 25000))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,9 +459,9 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
|
|||||||
upgradeWs = false
|
upgradeWs = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if let pingInterval = json["pingInterval"] as? Double, let pingTimeout = json["pingTimeout"] as? Double {
|
if let pingInterval = json["pingInterval"] as? Int, let pingTimeout = json["pingTimeout"] as? Int {
|
||||||
self.pingInterval = pingInterval / 1000.0
|
self.pingInterval = pingInterval
|
||||||
self.pingTimeout = pingTimeout / 1000.0
|
self.pingTimeout = pingTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
if !forcePolling && !forceWebsockets && upgradeWs {
|
if !forcePolling && !forceWebsockets && upgradeWs {
|
||||||
@ -550,7 +550,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func sendPing() {
|
private func sendPing() {
|
||||||
guard connected else { return }
|
guard connected, let pingInterval = pingInterval else { return }
|
||||||
|
|
||||||
// Server is not responding
|
// Server is not responding
|
||||||
if pongsMissed > pongsMissedMax {
|
if pongsMissed > pongsMissedMax {
|
||||||
@ -559,12 +559,12 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let pingInterval = pingInterval else { return }
|
|
||||||
|
|
||||||
pongsMissed += 1
|
pongsMissed += 1
|
||||||
write("", withType: .ping, withData: [])
|
write("", withType: .ping, withData: [])
|
||||||
|
|
||||||
engineQueue.asyncAfter(deadline: DispatchTime.now() + Double(pingInterval)) {[weak self] in self?.sendPing() }
|
engineQueue.asyncAfter(deadline: DispatchTime.now() + .milliseconds(pingInterval)) {[weak self] in
|
||||||
|
self?.sendPing()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Moves from long-polling to websockets
|
// Moves from long-polling to websockets
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user