connectRelay method
Future<void>
connectRelay({
- required String relay,
- HttpClient? customHttpClient,
- bool? shouldIgnoreConnectionException,
- void onConnectionSuccess(
- WebSocket webSocket
Implementation
Future<void> connectRelay({
required String relay,
HttpClient? customHttpClient,
bool? shouldIgnoreConnectionException,
void Function(WebSocket webSocket)? onConnectionSuccess,
}) async {
_client ??= _createCustomHttpClient();
WebSocket? webSocket;
try {
webSocket = await WebSocket.connect(
relay,
compression: CompressionOptions.compressionOff,
customClient: customHttpClient ?? _client!,
);
onConnectionSuccess?.call(webSocket);
} catch (e) {
NostrClientUtils.log(
"error while connecting to the relay with url: $relay",
e,
);
if (shouldIgnoreConnectionException ?? true) {
NostrClientUtils.log(
"The error related to relay: $relay is ignored, because to the ignoreConnectionException parameter is set to true.",
);
} else {
rethrow;
}
}
}