broadcastLog method

void broadcastLog(
  1. Map<String, dynamic> logEntry
)

Broadcasts a new log entry to all connected WebSocket clients.

Implementation

void broadcastLog(Map<String, dynamic> logEntry) {
  if (!kDebugMode) return;
  if (_wsClients.isEmpty) return;

  try {
    // Enhance the log entry with display information
    final enhancedLog = {
      ...logEntry,
      'displayStatus': _getDisplayStatus(logEntry),
      'displayType': _getDisplayType(logEntry),
      'displayMethod': _getDisplayMethod(logEntry),
    };

    final message = jsonEncode({
      'type': 'log',
      'log': enhancedLog,
      'timestamp': DateTime.now().toIso8601String(),
    });

    for (final client in _wsClients) {
      try {
        client.add(message);
      } catch (e) {
        _wsClients.remove(client);
      }
    }
  } catch (e) {
    // Silent fail - broadcast is not critical
  }
}