Skip to content

Commit

Permalink
Add watchAdvertisements to fix broken reconnect after app shuts down
Browse files Browse the repository at this point in the history
  • Loading branch information
wscullen committed Mar 25, 2024
1 parent e20932e commit 25759b3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/hooks/useWebBluetooth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ const useWebBluetooth = (incomingDataEventListener: (data: string) => void) => {
const connectToExistingDevice = async (device: BluetoothDevice) => {
try {
console.log("trying to connect to existing device", device);

// Need to do this to prevent Chrome "forgetting" the device and throwing
// device out of range error
await device?.watchAdvertisements();

currentDevice.current = device;

// Add an event listener to detect when a device disconnects
Expand Down

0 comments on commit 25759b3

Please sign in to comment.