bootloader: add withResponse option

This takes advantage of new (not implemented yet) Web Bluetooth APIs to write with or without response
This commit is contained in:
David Lechner
2020-05-01 21:11:01 -05:00
parent 70e5da1b42
commit 0a50ebddd7
2 changed files with 17 additions and 3 deletions
+11 -1
View File
@@ -81,7 +81,17 @@ async function send(action: Action, dispatch: Dispatch): Promise<void> {
if (!char) {
throw Error('Not connected');
}
await char.writeValue((action as BootloaderConnectionSendAction).data);
const sendAction = action as BootloaderConnectionSendAction;
// Fall back to legacy WebBluetooth writeValue if new methods are not
// available.
const writeValue = sendAction.withResponse
? // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
char.writeValueWithResponse || char.writeValue
: // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
char.writeValueWithoutResponse || char.writeValue;
await writeValue(sendAction.data);
dispatch(didSend());
} catch (err) {
dispatch(didSend(err));