on<T extends DataObject> method

void on<T extends DataObject>(
  1. void callback(
    1. T data
    )
)

Registers a callback for when a DataObject of type T is received.

Implementation

void on<T extends DataObject>(void Function(T data) callback) {
  _subscriptions.add(
    packets
        .where((packet) => packet.data is T)
        .map((packet) => packet.data as T)
        .listen(callback),
  );
}