broadcast method
Broadcasts a message to all connected peers
Implementation
Future<void> broadcast({
required String destination,
required String body,
String? contentType,
Map<String, String>? headers,
}) async {
final futures = <Future<String?>>[];
for (final client in _clients.values) {
if (client.isConnected) {
futures.add(client.send(
destination: destination,
body: body,
contentType: contentType,
headers: headers,
));
}
}
await Future.wait(futures);
_logger.info('Broadcasted message to ${futures.length} peers');
}