sendEventToFrontend method
Implementation
void sendEventToFrontend(InspectorEvent event) {
final bool hasConnections = _connections.isNotEmpty;
// Notify test listeners when there are no websocket clients
if (!hasConnections) {
try {
for (final tap in _testEventListeners) {
tap(event);
}
} catch (_) {}
}
// Maintain known-node bookkeeping for incremental DOM coherence
try {
if (event is DOMSetChildNodesEvent) {
final ids = <int>[];
for (final n in event.nodes) {
final v = n['nodeId'];
if (v is int) ids.add(v);
}
if (ids.isNotEmpty) _markNodesKnown(ids);
} else if (event is DOMChildNodeInsertedEvent) {
final id = event.node.ownerView.forDevtoolsNodeId(event.node);
_markNodeKnown(id);
} else if (event is DOMChildNodeRemovedEvent) {
final id = event.node.ownerView.forDevtoolsNodeId(event.node);
_unmarkNodeKnown(id);
} else if (event is DOMClearEvent || event is DOMUpdatedEvent) {
_knownNodeIds.clear();
_seededParentIds.clear();
}
} catch (_) {}
// If there are active websocket clients, also mirror events to test listeners
if (hasConnections) {
try {
for (final tap in _testEventListeners) {
tap(event);
}
} catch (_) {}
}
// Broadcast to websocket clients
if (hasConnections) {
final message = jsonEncode(event.toJson());
for (final connection in _connections.values) {
try {
connection.sink.add(message);
} catch (e) {
print('Error sending event: $e');
}
}
}
}