Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
datagutt committed Dec 20, 2024
1 parent e91f466 commit 6a3d6bf
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ export class DjiDevice {
if (peripheral.id !== this.deviceId) {
return;
}
if (this.state !== DjiDeviceState.discovering) {
return;
}
const manufacturerData = peripheral.advertisement.manufacturerData;
if (!manufacturerData) {
return;
Expand All @@ -224,12 +227,17 @@ export class DjiDevice {

if (peripheral.state !== 'connected') {
console.info('dj-device: Try to connect asynchronously');
await peripheral.connectAsync().catch((error) => {
if (error) {
console.error('dji-device: Connection error', error);
isError = true;
}
});
await peripheral
.connectAsync()
.then(() => {
console.info('dji-device: Connected');
})
.catch((error) => {
if (error) {
console.error('dji-device: Connection error', error);
isError = true;
}
});
} else {
console.info('dji-device: Already connected');
}
Expand All @@ -238,7 +246,6 @@ export class DjiDevice {
return;
}

console.info('dji-device: Connected');
peripheral.discoverServices([], this.onDiscoverServices.bind(this));
this.startStartStreamingTimer();
this.setState(DjiDeviceState.connecting);
Expand Down

0 comments on commit 6a3d6bf

Please sign in to comment.