[web-bluetooth] Robust handling of errors listening to 'characteristicvaluechanged' (#500)

rajsite has just created a new issue for https://github.com/WebBluetoothCG/web-bluetooth:

== Robust handling of errors listening to 'characteristicvaluechanged' ==
It's not clear to me what events / behaviors I should listen for to do robust error handling when listening to 'characteristicvaluechanged' events.

For example, I successfully request a bluetooth device, connect to a service, get a characteristic, startNotifications for the characteristic and start listening to 'characteristicvaluechanged' events.

At this point I don't have any pending promises for error states. What are the set of events I need to listen for for all the cases that will result in 'characteristicvaluechanged' failing to result in new values?

Right now 'gattserverdisconnected', 'serviceremoved' for the service associated with the characteristic, and maybe 'servicechanged' (although what if my characteristic was quickly added and remove, is the current event listener still relevant? this is unclear to me)

Are there other events I need to observe? Is it possible to guarantee these are the only ones I need to observe? Could we have an event like 'characteristicvaluechangedunavailable' or something that can be a reliable way to detect when the event listener is no longer valid?

Another way to think about it might be how can I build a robust [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#The_ReadableStream_constructor) implementation for characteristic value changes on top of the Web Bluetooth API (because that's what I'm trying to accomplish :P).

Please view or discuss this issue at https://github.com/WebBluetoothCG/web-bluetooth/issues/500 using your GitHub account

Received on Tuesday, 2 June 2020 18:01:03 UTC