getConnectionState method

  1. @override
Stream<L2CapConnectionState> getConnectionState()
override

Implementation

@override
Stream<L2CapConnectionState> getConnectionState() {
  final stream = const EventChannel('getConnectionState').receiveBroadcastStream().cast<int>();
  return stream.asyncMap((event) {
    debugPrint('new connection state is $event');
    switch (event) {
      case 0:
        return L2CapConnectionState.disconnected;
      case 1:
        return L2CapConnectionState.connecting;
      case 2:
        return L2CapConnectionState.connected;
      case 3:
        return L2CapConnectionState.disconnecting;
      case 4:
        return L2CapConnectionState.error;
      default:
        return L2CapConnectionState.error;
    }
  });
}