-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1348 from WalletConnect/networking-improvements
Networking improvements
- Loading branch information
Showing
14 changed files
with
220 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Foundation | ||
|
||
class SocketUrlFallbackHandler { | ||
private let relayUrlFactory: RelayUrlFactory | ||
private var logger: ConsoleLogging | ||
private var socket: WebSocketConnecting | ||
private let networkMonitor: NetworkMonitoring | ||
var onTryReconnect: (()->())? | ||
|
||
init( | ||
relayUrlFactory: RelayUrlFactory, | ||
logger: ConsoleLogging, | ||
socket: WebSocketConnecting, | ||
networkMonitor: NetworkMonitoring) { | ||
self.relayUrlFactory = relayUrlFactory | ||
self.logger = logger | ||
self.socket = socket | ||
self.networkMonitor = networkMonitor | ||
} | ||
|
||
func handleFallbackIfNeeded(error: NetworkError) { | ||
if error == .connectionFailed && socket.request.url?.host == NetworkConstants.defaultUrl { | ||
logger.debug("[WebSocket] - Fallback to \(NetworkConstants.fallbackUrl)") | ||
relayUrlFactory.setFallback() | ||
socket.request.url = relayUrlFactory.create() | ||
onTryReconnect?() | ||
} | ||
} | ||
} |
Oops, something went wrong.