mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
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:
@@ -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',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user