Skip to content

Commit

Permalink
Sync reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-lsvk committed Aug 1, 2023
1 parent 9bf5903 commit 41cd205
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Sources/WalletConnectRelay/WebSocketClient/WebSocketClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ extension WebSocketClient: URLSessionWebSocketDelegate {
}

func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didCloseWith closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) {
isConnected = false
logger.debug("[WebSocketClient]: Did close with code: \(closeCode)")
onDisconnect?(WebSocketClientError.errorWithCode(closeCode))
if isConnected {
isConnected = false
logger.debug("[WebSocketClient]: Did close with code: \(closeCode)")
onDisconnect?(WebSocketClientError.errorWithCode(closeCode))
}
}

func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
Expand All @@ -113,8 +115,10 @@ extension WebSocketClient: URLSessionWebSocketDelegate {
self.logger.debug("[WebSocketClient]: Error receiving: \(error)")
let nsError = error as NSError
if nsError.code == 57 && nsError.domain == "NSPOSIXErrorDomain" {
self.isConnected = false
self.reconnect()
if self.isConnected {
self.isConnected = false
self.reconnect()
}
}

case .success(let message):
Expand Down

0 comments on commit 41cd205

Please sign in to comment.