Skip to content

Commit ee97b42

Browse files
alvaro-delacruz-batAlvaro De La Cruz
and
Alvaro De La Cruz
authored
Resetting connection when webSocketDidReceiveError is called by mostly all POSIX error (#414)
Co-authored-by: Alvaro De La Cruz <alvaro@flatiron.sowftware>
1 parent 413e94e commit ee97b42

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Sources/Extensions/PusherConnection+WebsocketDelegate.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,23 @@ extension PusherConnection: WebSocketConnectionDelegate {
229229
context: """
230230
Error: \(error.debugDescription)
231231
""")
232+
233+
// Resetting connection if we receive another POSIXError
234+
// than ENOTCONN (57 - Socket is not connected)
235+
if case .posix(let code) = error, code != .ENOTCONN {
236+
resetConnection()
237+
238+
guard !intentionalDisconnect else {
239+
Logger.shared.debug(for: .intentionalDisconnection)
240+
return
241+
}
242+
243+
guard reconnectAttemptsMax == nil || reconnectAttempts < reconnectAttemptsMax! else {
244+
Logger.shared.debug(for: .maxReconnectAttemptsLimitReached)
245+
return
246+
}
247+
248+
attemptReconnect()
249+
}
232250
}
233251
}

0 commit comments

Comments
 (0)