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

[Breaking changes] BluetoothGATTCharacteristic.value now returns a DataView

From: François Beaufort 🇫🇷 <fbeaufort@google.com>
Date: Fri, 22 Jan 2016 12:30:22 +0100
Message-ID: <CAPpwU5+-nH+L9eqNsF8nRyUDdSjKxv8iyim+NrG5SZBz3XXDRA@mail.gmail.com>
To: public-web-bluetooth <public-web-bluetooth@w3.org>
As discussed in
https://github.com/WebBluetoothCG/web-bluetooth/issues/172,
BluetoothGATTCharacteristic.value will now return a DataView object
instead of an ArrayBuffer object to make it easier (most of time) to
read that value.

BEFORE:

characteristic.readValue().then(buffer => {
  let data = new DataView(buffer);
  let foo = data.getUint8(0);
  ...

NOW:

characteristic.readValue().then(value => {
  let foo = value.getUint8(0);
  // We can always access ArrayBuffer if we need to with value.buffer
  ...


We have updated our specification, demos, samples, codelabs, articles
and sent some PRs to external projects we know.

Until Chrome 50 reaches Stable channel (estimated to Apr 19th, 2016
according to https://www.chromium.org/developers/calendar), here's
what you can add in your app's code:

characteristic.readValue().then(value => {
  // TODO: Remove line below when Chrome 50 reaches Stable channel.
  value = value.buffer ? value : new DataView(value);
  let foo = value.getUint8(0);
  ...
Received on Friday, 22 January 2016 11:30:52 UTC

This archive was generated by hypermail 2.3.1 : Friday, 22 January 2016 11:30:52 UTC