Skip to content

Commit

Permalink
fix(): fix type of ScanResult
Browse files Browse the repository at this point in the history
  • Loading branch information
pwespi committed Aug 21, 2021
1 parent 848027b commit 0b1ccfe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
15 changes: 10 additions & 5 deletions src/bleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,16 @@ class BleClientClass implements BleClientInterface {
async requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void> {
await this.queue(async () => {
await this.scanListener?.remove();
this.scanListener = await BluetoothLe.addListener('onScanResult', (result: ScanResultInternal) => {
result.manufacturerData = this.convertObject(result.manufacturerData);
result.serviceData = this.convertObject(result.serviceData);
result.rawAdvertisement = result.rawAdvertisement ? this.convertValue(result.rawAdvertisement) : undefined;
callback(result as ScanResult);
this.scanListener = await BluetoothLe.addListener('onScanResult', (resultInternal: ScanResultInternal) => {
const result: ScanResult = {
...resultInternal,
manufacturerData: this.convertObject(resultInternal.manufacturerData),
serviceData: this.convertObject(resultInternal.serviceData),
rawAdvertisement: resultInternal.rawAdvertisement
? this.convertValue(resultInternal.rawAdvertisement)
: undefined,
};
callback(result);
});
await BluetoothLe.requestLEScan(options);
});
Expand Down
8 changes: 4 additions & 4 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export interface ReadResult {
export interface ScanResultInternal<T = Data> {
device: BleDevice;
localName?: string;
rssi: number;
txPower: number;
rssi?: number;
txPower?: number;
manufacturerData?: { [key: string]: T };
serviceData?: { [key: string]: T };
uuids?: string[];
Expand All @@ -131,11 +131,11 @@ export interface ScanResult {
/**
* Received Signal Strength Indication.
*/
rssi: number;
rssi?: number;
/**
* Transmit power in dBm. A value of 127 indicates that it is not available.
*/
txPower: number;
txPower?: number;
/**
* Manufacturer data, key is a company identifier and value is the data.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/web.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface BluetoothLeWithPrivate extends BluetoothLePlugin {
deviceMap: Map<string, BluetoothDevice>;
discoverdDevices: Map<string, boolean>;
scan: BluetoothLEScan | null;
onAdvertisemendReceived: (event: BluetoothAdvertisementEvent) => void;
onAdvertisemendReceived: (event: BluetoothAdvertisingEvent) => void;
onDisconnected: (event: Event) => void;
}

Expand Down
6 changes: 3 additions & 3 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class BluetoothLeWeb extends WebPlugin implements BluetoothLePlugin {
});
}

private onAdvertisemendReceived(event: BluetoothAdvertisementEvent): void {
private onAdvertisemendReceived(event: BluetoothAdvertisingEvent): void {
// do not use `this` in event listener
const deviceId = event.device.id;
BluetoothLe.deviceMap.set(deviceId, event.device);
Expand Down Expand Up @@ -196,8 +196,8 @@ export class BluetoothLeWeb extends WebPlugin implements BluetoothLePlugin {
await characteristic?.stopNotifications();
}

private getFilters(options?: RequestBleDeviceOptions): BluetoothRequestDeviceFilter[] {
const filters: BluetoothRequestDeviceFilter[] = [];
private getFilters(options?: RequestBleDeviceOptions): BluetoothLEScanFilter[] {
const filters: BluetoothLEScanFilter[] = [];
for (const service of options?.services ?? []) {
filters.push({
services: [service],
Expand Down

0 comments on commit 0b1ccfe

Please sign in to comment.