[web-bluetooth] ENABLE_NOTIFICATION_VALUE - Web Bluetooth API

PaulKotlov has just created a new issue for https://github.com/WebBluetoothCG/web-bluetooth:

== ENABLE_NOTIFICATION_VALUE - Web Bluetooth API ==
Client Configuration Characteristic Descriptor (CCCD).
UUID - "00002902-0000-1000-8000-00805f9b34fb" / 'gatt.client_characteristic_configuration'.


To set CCCD in Java code for Android
we do:

`    public static final byte[] ENABLE_NOTIFICATION_VALUE = {0x01, 0x00};
    
    BluetoothGattDescriptor descriptor =    characteristic.getDescriptor("00002902-0000-1000-8000-00805f9b34fb");
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    mBluetoothGatt.writeDescriptor(descriptor);
`

How can I perform a similar configuration in JavaScript code when using the Web Bluetooth API ?

My version in JavaScript:  
`    .then(descriptors => {    
    let queue = Promise.resolve();
     descriptors.forEach(descriptor => {
            switch (descriptor.uuid) {    
              case BluetoothUUID.getDescriptor('gatt.client_characteristic_configuration'):
               queue = queue.then(_ => descriptor.readValue()).then(value => {
                  descriptorCache = descriptor;
                });
       ...
    
        var data = new Uint8Array([0x01, 0x00]);
        descriptorCache.writeValue(data);
        //descriptorCache.writeValue(new TextEncoder().encode(data));
`         

fails with a security error :-(
 
Uncaught (in promise) DOMException: writeValue() called on blocklisted object marked exclude-writes. 
https://webbluetoothcg.github.io/web-bluetooth/#attacks-on-devices

I understand the need for security.
But after all, a lot of devices require a presetting of the CCCD.


If I don't understand correctly then please forgive me. 
I didn't find another way to resolve my issue. 

Also this question is available here: https://stackoverflow.com/q/50097579/9720482




Please view or discuss this issue at https://github.com/WebBluetoothCG/web-bluetooth/issues/394 using your GitHub account

Received on Wednesday, 2 May 2018 12:53:54 UTC