Skip to content

Commit 7090fe0

Browse files
Avoid double service init (#24)
This can result in duplicate events
1 parent 393c8d6 commit 7090fe0

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/bluetooth-device-wrapper.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,19 +379,19 @@ export class BluetoothDeviceWrapper {
379379
async startNotifications(type: TypedServiceEvent) {
380380
const serviceInfo = this.serviceInfo.find((s) => s.events.includes(type));
381381
if (serviceInfo) {
382-
// TODO: type cheat! why?
383-
const service = await this.createIfNeeded(serviceInfo as any, true);
384-
this.queueGattOperation(
385-
async () => await service?.startNotifications(type),
386-
);
382+
this.queueGattOperation(async () => {
383+
// TODO: type cheat! why?
384+
const service = await this.createIfNeeded(serviceInfo as any, true);
385+
await service?.startNotifications(type);
386+
});
387387
}
388388
}
389389

390390
async stopNotifications(type: TypedServiceEvent) {
391-
const serviceInfo = this.serviceInfo.find((s) => s.events.includes(type));
392-
this.queueGattOperation(
393-
async () => await serviceInfo?.get()?.stopNotifications(type),
394-
);
391+
this.queueGattOperation(async () => {
392+
const serviceInfo = this.serviceInfo.find((s) => s.events.includes(type));
393+
await serviceInfo?.get()?.stopNotifications(type);
394+
});
395395
}
396396

397397
private disposeServices() {

0 commit comments

Comments
 (0)