manekinekko / angular-web-bluetooth

The missing Web Bluetooth module for Angular
https://manekinekko.github.io/angular-web-bluetooth/
MIT License
195 stars 56 forks source link

Add a method that converts a characteristic into an observable of values #7

Closed urish closed 7 years ago

urish commented 7 years ago

sketch for a possible implementation:

  notifications$(char: BluetoothRemoteGATTCharacteristic) {  
    char.startNotifications();
    const disconnected = Observable.fromEvent(char.service.device as any, 'gattserverdisconnected');
    return Observable.fromEvent(char as any, 'characteristicvaluechanged').takeUntil(disconnected).map(event => event.target.value as DataView);
  }

You'd still need to stop the notifications when everybody unsubscribes, but I guess this can be added later.