connectionEvents property

Stream<SyncConnectionEvent> get connectionEvents

Get a broadcast stream of connection state changes (connect/disconnect).

Subscribe (listen) to the stream to actually start listening to events.

Implementation

Stream<SyncConnectionEvent> get connectionEvents {
  if (_connectionEvents == null) {
    // Combine events from two C listeners: connect & disconnect.
    _connectionEvents =
        _SyncListenerGroup<SyncConnectionEvent>('sync-connection');

    _connectionEvents!.add(_SyncListenerConfig(
        (int nativePort) => C.dartc_sync_listener_connect(_ptr, nativePort),
        (dynamic _, controller) =>
            controller.add(SyncConnectionEvent.connected)));

    _connectionEvents!.add(_SyncListenerConfig(
        (int nativePort) =>
            C.dartc_sync_listener_disconnect(_ptr, nativePort),
        (dynamic _, controller) =>
            controller.add(SyncConnectionEvent.disconnected)));

    _connectionEvents!.finish();
  }
  return _connectionEvents!.stream;
}