connectRelay method
Connects to a relay
web socket.
Trigger the onConnectionSuccess
callback if the connection is successful
Implementation
Future<void> connectRelay({
required String relay,
bool? shouldIgnoreConnectionException,
void Function(WebSocketChannel webSocket)? onConnectionSuccess,
}) async {
WebSocketChannel? webSocket;
try {
webSocket = WebSocketChannel.connect(
Uri.parse(relay),
);
await webSocket.ready;
onConnectionSuccess?.call(webSocket);
} catch (e) {
utils.log(
'error while connecting to the relay with url: $relay',
e,
);
if (shouldIgnoreConnectionException ?? true) {
utils.log(
// ignore: lines_longer_than_80_chars
'The error related to relay: $relay is ignored, because to the ignoreConnectionException parameter is set to true.',
);
} else {
rethrow;
}
}
}