add polyfill for new Web Bluetooth methods

This commit is contained in:
David Lechner
2020-05-01 21:37:45 -05:00
parent 0a50ebddd7
commit 9d545f8f5c
3 changed files with 49 additions and 15 deletions
+27
View File
@@ -0,0 +1,27 @@
/**
* Current definition of BluetoothRemoteGATTCharacteristic doesn't include
* new Web Bluetooth APIs.
*/
export interface PolyfillBluetoothRemoteGATTCharacteristic
extends BluetoothRemoteGATTCharacteristic {
writeValueWithResponse(value: BufferSource): Promise<void>;
writeValueWithoutResponse(value: BufferSource): Promise<void>;
}
/**
* Fills in writeValueWithResponse and writeValueWithoutResponse for backward
* compatibility.
* @param char a remote GATT characteristic object
*/
export function polyfillBluetoothRemoteGATTCharacteristic(
char: BluetoothRemoteGATTCharacteristic,
): PolyfillBluetoothRemoteGATTCharacteristic {
const polyfill = (char as unknown) as PolyfillBluetoothRemoteGATTCharacteristic;
if (!polyfill.writeValueWithResponse) {
polyfill.writeValueWithResponse = char.writeValue;
}
if (!polyfill.writeValueWithoutResponse) {
polyfill.writeValueWithoutResponse = char.writeValue;
}
return polyfill;
}