NOtherDev / whatwebcando

An overview of the device integration HTML5 APIs
https://whatwebcando.today/
MIT License
836 stars 61 forks source link

bluetooth: In Chrome 50+, a DataView is returned instead of an ArrayBuffer #11

Closed beaufortfrancois closed 8 years ago

beaufortfrancois commented 8 years ago

In Live demo code of Bluetooth sample, it should be:

    .then(function(value) {
      // In Chrome 50+, a DataView is returned instead of an ArrayBuffer.
      value = value.buffer ? value : new DataView(value);
      $target.innerHTML = 'Battery percentage is <b>' + value.getUint8(0) + '</b>.';
    })

or simply:

    .then(function(value) {
      $target.innerHTML = 'Battery percentage is <b>' + value.getUint8(0) + '</b>.';
    })

instead of:

    .then(function(buffer) {
      var data = new DataView(buffer);
      $target.innerHTML = 'Battery percentage is <b>' + data.getUint8(0) + '</b>.';
    })
NOtherDev commented 8 years ago

Thanks, fixed!