parseStreamEvent static method

LiveEvent? parseStreamEvent(
  1. JsonRpcNotification notification,
  2. String streamId
)

Parses a VM service streamNotify notification for streamId.

Implementation

static LiveEvent? parseStreamEvent(
  JsonRpcNotification notification,
  String streamId,
) {
  if (notification.method != 'streamNotify') return null;
  if (notification.params['streamId'] != streamId) return null;
  final Object? event = notification.params['event'];
  if (event is! Map) return null;
  final Object? kind = event['extensionKind'];
  if (kind is! String) return null;
  final Object? data = event['extensionData'];
  final Object? timestamp = event['timestamp'];
  return LiveEvent(
    kind,
    data is Map ? Map<String, Object?>.from(data) : const {},
    timestamp: timestamp is int
        ? DateTime.fromMillisecondsSinceEpoch(timestamp)
        : null,
  );
}