connectionEvents property

Stream<ConnectionEvent> connectionEvents

Get a stream of ConnectionEvents.

If you want to get connection events when connecting to the eSense device, remember to start listening to this stream before attempting to connect.

For example.

    ESenseManager.connectionEvents.listen((event) => print('Connection event: $event'));
    bool success = await ESenseManager.connect(eSenseName);

Implementation

Stream<ConnectionEvent> get connectionEvents {
  if (_connectionEventStream == null) {
    _connectionEventStream = _eSenseConnectionEventChannel
        .receiveBroadcastStream()
        .map((type) => ConnectionEvent.fromString('$type'));

    // listen to the connection event in order to set the [connection] status
    _connectionEventStream?.listen((ConnectionEvent event) {
      print('$runtimeType - event: $event');

      switch (event.type) {
        case ConnectionType.connected:
          connected = true;
          break;
        case ConnectionType.disconnected:
        case ConnectionType.unknown:
        case ConnectionType.device_found:
        case ConnectionType.device_not_found:
          connected = false;
          break;
      }
    });
  }
  return _connectionEventStream!;
}