disconnectFromRelays method
Future<bool>
disconnectFromRelays(
{ - int closeCode(
- String relayUrl
)?,
- String closeReason(
- String relayUrl
)?,
- void onRelayDisconnect(
- String relayUrl,
- WebSocketChannel relayWebSOcket,
- dynamic webSocketDisconnectionMessage
)?,
})
Implementation
Future<bool> disconnectFromRelays({
int Function(String relayUrl)? closeCode,
String Function(String relayUrl)? closeReason,
void Function(
String relayUrl,
WebSocketChannel relayWebSOcket,
dynamic webSocketDisconnectionMessage,
)? onRelayDisconnect,
}) async {
final webSockets = nostrRegistry.relaysWebSocketsRegistry;
for (var index = 0; index < webSockets.length; index++) {
final current = webSockets.entries.elementAt(index);
final relayUrl = current.key;
final relayWebSocket = current.value;
final returnedMessage = await relayWebSocket.sink.close(
closeCode?.call(relayUrl),
closeReason?.call(relayUrl),
);
onRelayDisconnect?.call(relayUrl, relayWebSocket, returnedMessage);
}
nostrRegistry.clearWebSocketsRegistry();
relaysList = [];
return true;
}