broadcast method

void broadcast(
  1. dynamic message, {
  2. WebSocket? currentSocket,
  3. Iterable<String> rooms = const [],
})

Implementation

void broadcast(dynamic message,
    {WebSocket? currentSocket, Iterable<String> rooms = const []}) {
  for (var room in rooms.isEmpty ? [''] : rooms) {
    var list = _websockets.where((socket) => currentSocket != socket);
    if (room.isNotEmpty) {
      list = list.where((socket) => socket._enteredRooms.contains(room));
    }

    for (var websocket in list) {
      websocket.sink.add(message);
    }
  }
}