@@ -7,6 +7,7 @@ import {CONNTYPE} from '../constants.js';
7
7
import { Workflow } from './workflow.js' ;
8
8
import { GenericModal , DeviceInfoModal } from '../common/dialogs.js' ;
9
9
import { sleep } from '../common/utilities.js' ;
10
+ import { bluetooth } from 'webbluetooth' ;
10
11
11
12
const bleNusServiceUUID = 'adaf0001-4369-7263-7569-74507974686e' ;
12
13
const bleNusCharRXUUID = 'adaf0002-4369-7263-7569-74507974686e' ;
@@ -74,7 +75,7 @@ class BLEWorkflow extends Workflow {
74
75
stepOne . classList . add ( "hidden" ) ;
75
76
}
76
77
try {
77
- const devices = await navigator . bluetooth . getDevices ( ) ;
78
+ const devices = await bluetooth . getDevices ( ) ;
78
79
console . log ( devices ) ;
79
80
this . connectionStep ( devices . length > 0 ? 2 : 1 ) ;
80
81
} catch ( e ) {
@@ -120,7 +121,7 @@ class BLEWorkflow extends Workflow {
120
121
if ( ! this . connectionStatus ( ) ) {
121
122
try {
122
123
console . log ( 'Getting existing permitted Bluetooth devices...' ) ;
123
- const devices = await navigator . bluetooth . getDevices ( ) ;
124
+ const devices = await bluetooth . getDevices ( ) ;
124
125
125
126
console . log ( '> Found ' + devices . length + ' Bluetooth device(s).' ) ;
126
127
// These devices may not be powered on or in range, so scan for
@@ -138,7 +139,7 @@ class BLEWorkflow extends Workflow {
138
139
139
140
// Bring up a dialog to request a device
140
141
async requestDevice ( ) {
141
- return navigator . bluetooth . requestDevice ( {
142
+ return bluetooth . requestDevice ( {
142
143
filters : [ { services : [ 0xfebb ] } , ] , // <- Prefer filters to save energy & show relevant devices.
143
144
optionalServices : [ 0xfebb , bleNusServiceUUID ]
144
145
} ) ;
@@ -272,7 +273,7 @@ class BLEWorkflow extends Workflow {
272
273
}
273
274
// Is this a new connection?
274
275
if ( ! this . bleDevice ) {
275
- let devices = await navigator . bluetooth . getDevices ( ) ;
276
+ let devices = await bluetooth . getDevices ( ) ;
276
277
for ( const device of devices ) {
277
278
await this . connectToBluetoothDevice ( device ) ;
278
279
}
0 commit comments