- From: François Beaufort via GitHub <sysbot+gh@w3.org>
- Date: Wed, 17 Aug 2016 07:06:04 +0000
- To: public-web-bluetooth-log@w3.org
When characteristic only supports READ GATT operations, it is actually
a cool pattern. See
https://googlechrome.github.io/samples/web-bluetooth/read-characteristic-value-changed.html
for instance.
However I understand why it is confusing... we could either:
- Add a property to the
`characteristicvaluechanged`/`characteristicvalueupdated` event:
```js
characteristic.addEventListener('characteristicvalueupdated',
handleCharacteristicValueUpdated);
function handleCharacteristicValueUpdated(event) {
console.log(event.isReadResponse) /* Returns true if stored value
comes from a read operation */
console.log(event.target.value); /* Characteristic value */
}
```
- Or add a new property to the characteristic object itself which
indicates if stored value comes from a read or a notification:
```js
characteristic.addEventListener('characteristicvalueupdated',
handleCharacteristicValueUpdated);
function handleCharacteristicValueUpdated(event) {
console.log(event.target.isRead) /* Returns true if stored value
comes from a read operation */
console.log(event.target.value); /* Characteristic value */
}
```
I would lean towards first option personally.
--
GitHub Notification of comment by beaufortfrancois
Please view or discuss this issue at
https://github.com/WebBluetoothCG/web-bluetooth/issues/274#issuecomment-240330636
using your GitHub account
Received on Wednesday, 17 August 2016 07:06:11 UTC