broadcast method

Future<void> broadcast({
  1. required String destination,
  2. required String body,
  3. String? contentType,
  4. Map<String, String>? headers,
})

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');
}