File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ const { HciNoble, DbusNoble } = require ( '../lib' ) ;
2+
3+ const USAGE = `
4+ Usage:
5+ node ./tests/dispose.js <bindings>
6+ Arguments:
7+ bindings: Bindings to use: "hci" or "dbus"
8+ ` ;
9+
10+ const BINDINGS = process . argv [ 2 ] ;
11+
12+ const printUsage = ( ) => console . log ( USAGE ) ;
13+
14+ const main = async ( ) => {
15+ if ( ! BINDINGS ) {
16+ throw new Error ( printUsage ( ) ) ;
17+ }
18+
19+ console . log ( 'Initializing noble...' ) ;
20+
21+ const noble = BINDINGS === 'hci' ? new HciNoble ( ) : BINDINGS === 'dbus' ? new DbusNoble ( ) : null ;
22+ if ( ! noble ) {
23+ throw new Error ( `Could not find requested bindings ${ BINDINGS } ` ) ;
24+ }
25+
26+ console . log ( 'Getting adapters...' ) ;
27+
28+ const adapters = await noble . getAdapters ( ) ;
29+ if ( adapters . length === 0 ) {
30+ throw new Error ( 'No adapters found' ) ;
31+ }
32+
33+ console . log ( 'Using all adapters...' ) ;
34+
35+ for ( const adapter of adapters ) {
36+ await adapter . startScanning ( ) ;
37+ await adapter . stopScanning ( ) ;
38+ }
39+
40+ await noble . dispose ( ) ;
41+
42+ console . log ( 'Done' ) ;
43+ } ;
44+
45+ main ( )
46+ . then ( ( ) => process . exit ( 0 ) )
47+ . catch ( ( err ) => {
48+ console . error ( err ) ;
49+ process . exit ( 1 ) ;
50+ } ) ;
You can’t perform that action at this time.
0 commit comments