on method

  1. @override
Stream on(
  1. String eventName
)
override

Listens to events broadcast under eventName, delivering the event's first argument.

This is the right choice for the usual hub shape, where the server sends one object: Clients.All.SendAsync("ReceiveMessage", dto). The stream yields dto. An event sent with no arguments yields null.

For a hub method with several parameters, use onArgs — this stream would hand you only the first one.

The returned stream is broadcast and stays open across reconnects. Cancel your own StreamSubscription to stop listening; off closes the event for every listener.

Implementation

@override
Stream<dynamic> on(String eventName) {
  return onArgs(eventName).map((args) => args.isEmpty ? null : args.first);
}