Skip to content

Commit 5b3e07f

Browse files
committed
autoreconnect should work only in case of errors
1 parent 791f54a commit 5b3e07f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Source/PusherWebsocketDelegate.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,20 @@ extension PusherConnection: WebSocketDelegate {
3131
- parameter error: The error, if one exists, when disconnected
3232
*/
3333
public func websocketDidDisconnect(ws: WebSocket, error: NSError?) {
34-
if let error = error {
35-
print("Websocket is disconnected: \(error.localizedDescription)")
36-
}
3734

3835
updateConnectionState(.Disconnected)
3936
for (_, channel) in self.channels.channels {
4037
channel.subscribed = false
4138
}
42-
39+
40+
// Handle error (if any)
41+
guard let error = error else {
42+
return
43+
}
44+
45+
print("Websocket is disconnected. Error: \(error.localizedDescription)")
46+
47+
// Reconnect if possible
4348
if let reconnect = self.options.autoReconnect where reconnect {
4449
if let reachability = self.reachability where reachability.isReachable() {
4550
let operation = NSBlockOperation {

0 commit comments

Comments
 (0)