Re: [web-bluetooth] startNotifications sometimes doesn't bind (#429)

I added a log :
```
function handleHeartRateMeasurement(heartRateMeasurement) {
console.log("HELLO");
  heartRateMeasurement.addEventListener("characteristicvaluechanged", event => {
    console.log("HELLO bis");
    var value = device.parseValue(event.target.value);
    // Use my value
  });
}
```

"HELLO" is always displayed, but sometimes, randomly "HELLO bis" is not displayed, and so I receive no value.

---

So if you would first add the event listener before receiving the first value, would you do something like this ?
```
device.connect().then(() => device._startNotifications(characteristicUuid))

_startNotifications(characteristicUuid) {
    // Get the Characteristic
    let characteristic = this._characteristics.get(characteristicUuid);
    console.log("before event listener")

    // Start to add event listener for new value for this Characteristic
    characteristic.addEventListener("characteristicvaluechanged", event => {
      var value = device.parseValue(event.target.value);
      console.log(value)
    });

    console.log("after event listener")
    // Subscribe to the notifications of this Characteristic
    return characteristic.startNotifications().then(() => characteristic);
}
```

Like this I get the `value` in my console but sometimes, it still doesn't print anything _(except "before event listener" and "after event listener")_

But I don't get how I can receive new value if I don't use `startNotifications()` of my Characteristic ?

-- 
GitHub Notification of comment by StephaneJuban
Please view or discuss this issue at https://github.com/WebBluetoothCG/web-bluetooth/issues/429#issuecomment-476689678 using your GitHub account

Received on Tuesday, 26 March 2019 15:02:03 UTC