reconnectRelay method
Implementation
Future<bool> reconnectRelay(String url, {bool force = false}) async {
Relay? relay = getRelay(url);
if (allowReconnectRelays) {
NostrTransport? transport = transports[cleanRelayUrl(url)];
if (transport != null) {
await transport.ready
.timeout(Duration(seconds: DEFAULT_WEB_SOCKET_CONNECT_TIMEOUT))
.onError((error, stackTrace) {
print("error connecting to relay $url: $error");
return []; // Return an empty list in case of error
});
}
if (!isWebSocketOpen(url)) {
if (relay != null &&
!force &&
!relay.wasLastConnectTryLongerThanSeconds(
FAIL_RELAY_CONNECT_TRY_AFTER_SECONDS)) {
// don't try too often
return false;
}
if (!await connectRelay(url)) {
// could not connect
return false;
}
if (!isWebSocketOpen(url)) {
// web socket is not open
return false;
}
}
}
return true;
}