emit method

void emit(
  1. String event,
  2. dynamic message, {
  3. List<String> exclude = const <String>[],
})

set message to everyone in the room

emitter.emit('event', message);

Implementation

void emit(String event, dynamic message,
    {List<String> exclude = const <String>[]}) {
  String payload = jsonEncode(<String, dynamic>{
    'event': event,
    'message': message,
  });
  if (roomId == null) {
    DoxLogger.warn('set a room to emit');
    return;
  }
  List<String> members = _storage.getWebSocketIdsOfTheRoom(roomId!);
  for (String socketId in members) {
    if (!exclude.contains(socketId)) {
      WebSocketInfo? info = _storage.getWebSocketInfo(socketId);
      if (info != null) {
        WebSocket websocket = info.websocket;
        websocket.add(payload);
      }
    }
  }
}