Skip to content

Commit

Permalink
fix(hci): Hide require in function
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed Mar 22, 2021
1 parent 787f84c commit 02c931c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/bindings/hci/misc/Hci.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export declare class Hci extends TypedEmitter<HciEvents> {
private totalNumAclLeDataPackets;
private aclPacketQueue;
constructor(deviceId?: number, cmdTimeout?: number);
private static createSocket;
static getDeviceList(): HciDevice[];
private acquireMutex;
private isInitializing;
Expand Down
2 changes: 1 addition & 1 deletion lib/bindings/hci/misc/Hci.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions lib/bindings/hci/misc/Hci.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/bindings/hci/misc/Hci.js.map

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions src/bindings/hci/misc/Hci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { AddressType } from '../../../models';
import { HciError } from './HciError';
import { HciStatus } from './HciStatus';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const BluetoothHciSocket = require('@abandonware/bluetooth-hci-socket');

// tslint:disable: no-bitwise

const HCI_COMMAND_PKT = 0x01;
Expand Down Expand Up @@ -196,8 +193,13 @@ export class Hci extends TypedEmitter<HciEvents> {
this.currentCmd = null;
}

private static createSocket() {
// eslint-disable-next-line @typescript-eslint/no-var-requires
return new (require('@abandonware/bluetooth-hci-socket'))();
}

public static getDeviceList(): HciDevice[] {
const socket = new BluetoothHciSocket();
const socket = Hci.createSocket();
return socket.getDeviceList();
}

Expand All @@ -221,7 +223,7 @@ export class Hci extends TypedEmitter<HciEvents> {
return this.waitForInit(timeoutInSeconds);
}

this.socket = new BluetoothHciSocket();
this.socket = Hci.createSocket();
this.socket.on('data', this.onSocketData);
this.socket.on('error', this.onSocketError);

Expand Down

0 comments on commit 02c931c

Please sign in to comment.