diff --git a/SocketIOClientSwift/SocketEngine.swift b/SocketIOClientSwift/SocketEngine.swift index 28593da..f288d28 100644 --- a/SocketIOClientSwift/SocketEngine.swift +++ b/SocketIOClientSwift/SocketEngine.swift @@ -40,11 +40,11 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient { private var fastUpgrade = false private var forcePolling = false private var forceWebsockets = false - private var pingInterval:Int? + private var pingInterval:Double? private var pingTimer:NSTimer? - private var pingTimeout = 0 { + private var pingTimeout = 0.0 { didSet { - pongsMissedMax = pingTimeout / (pingInterval ?? 25) + pongsMissedMax = Int(pingTimeout / (pingInterval ?? 25)) } } private var pongsMissed = 0 @@ -404,9 +404,9 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient { createWebsocket(andConnect: true) } - if let pingInterval = json["pingInterval"] as? Int, pingTimeout = json["pingTimeout"] as? Int { - self.pingInterval = pingInterval / 1000 - self.pingTimeout = pingTimeout / 1000 + if let pingInterval = json["pingInterval"] as? Double, pingTimeout = json["pingTimeout"] as? Double { + self.pingInterval = pingInterval / 1000.0 + self.pingTimeout = pingTimeout / 1000.0 } } else { client?.didError("Engine failed to handshake") @@ -650,8 +650,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient { pingTimer?.invalidate() dispatch_async(dispatch_get_main_queue()) {[weak self] in if let this = self { - this.pingTimer = NSTimer.scheduledTimerWithTimeInterval(NSTimeInterval(this.pingInterval!), - target: this, + this.pingTimer = NSTimer.scheduledTimerWithTimeInterval(this.pingInterval!, target: this, selector: Selector("sendPing"), userInfo: nil, repeats: true) } }