fix bluetooth stuck in connecting state after cancel

This commit is contained in:
David Lechner
2020-04-17 00:07:15 -05:00
parent a67656def6
commit c7c11f0040
+12 -4
View File
@@ -80,12 +80,20 @@ export function connect(): BLEThunkAction {
return;
}
dispatch(beginConnect());
device = await navigator.bluetooth.requestDevice({
filters: [{ services: [pybricksServiceUUID] }],
optionalServices: [bleNusServiceUUID],
});
try {
device = await navigator.bluetooth.requestDevice({
filters: [{ services: [pybricksServiceUUID] }],
optionalServices: [bleNusServiceUUID],
});
} catch (err) {
// this can happen if the use cancels the dialog
console.log(err);
dispatch(endDisconnect());
return;
}
if (device.gatt === undefined) {
console.error('Device does not support GATT');
dispatch(endDisconnect());
return;
}
device.addEventListener('gattserverdisconnected', () => {