drop polyfill for chromimum < v85

This removes the polyfill for using older chrome browsers before the
writeWithResponse and writeWithoutResponse APIs were added.
This commit is contained in:
David Lechner
2020-12-21 13:05:47 -06:00
parent 9071b17637
commit ae996453e8
9 changed files with 37 additions and 153 deletions
-29
View File
@@ -1,29 +0,0 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors
import { polyfillBluetoothRemoteGATTCharacteristic } from './web-bluetooth';
describe('polyfillBluetoothRemoteGATTCharacteristic', () => {
test('old browser falls back to writeValue', () => {
const char = {} as BluetoothRemoteGATTCharacteristic;
Object.defineProperty(char, 'writeValue', { value: 'writeValue' });
expect(polyfillBluetoothRemoteGATTCharacteristic(char)).toEqual({
xWriteValueWithResponse: 'writeValue',
xWriteValueWithoutResponse: 'writeValue',
});
});
test('new browser uses writeValueWith(out)Response', () => {
const char = {} as BluetoothRemoteGATTCharacteristic;
Object.defineProperty(char, 'writeValue', { value: 'writeValue' });
Object.defineProperty(char, 'writeValueWithResponse', {
value: 'writeValueWithResponse',
});
Object.defineProperty(char, 'writeValueWithoutResponse', {
value: 'writeValueWithoutResponse',
});
expect(polyfillBluetoothRemoteGATTCharacteristic(char)).toEqual({
xWriteValueWithResponse: 'writeValueWithResponse',
xWriteValueWithoutResponse: 'writeValueWithoutResponse',
});
});
});
-35
View File
@@ -1,35 +0,0 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors
/**
* Current definition of BluetoothRemoteGATTCharacteristic doesn't include
* new Web Bluetooth APIs.
*/
export interface PolyfillBluetoothRemoteGATTCharacteristic
extends BluetoothRemoteGATTCharacteristic {
/**
* Calls writeValueWithResponse() if available otherwise falls back to writeValue()
* @param value data to send
*/
xWriteValueWithResponse(value: BufferSource): Promise<void>;
/**
* Calls writeValueWithoutResponse() if available otherwise falls back to writeValue()
* @param value data to send
*/
xWriteValueWithoutResponse(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;
polyfill.xWriteValueWithResponse = char.writeValueWithResponse || char.writeValue;
polyfill.xWriteValueWithoutResponse =
char.writeValueWithoutResponse || char.writeValue;
return polyfill;
}