W3C home > Mailing lists > Public > public-web-bluetooth-log@w3.org > August 2016

Re: [web-bluetooth] Don't fire characteristicvaluechanged for Read Responses

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
Message-ID: <issue_comment.created-240330636-1471417562-sysbot+gh@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

This archive was generated by hypermail 2.3.1 : Wednesday, 17 August 2016 07:06:12 UTC