@@ -7,7 +7,6 @@ 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' ;
11
10
12
11
const bleNusServiceUUID = 'adaf0001-4369-7263-7569-74507974686e' ;
13
12
const bleNusCharRXUUID = 'adaf0002-4369-7263-7569-74507974686e' ;
@@ -72,8 +71,7 @@ class BLEWorkflow extends Workflow {
72
71
}
73
72
try {
74
73
this . clearConnectStatus ( ) ;
75
- const devices = await bluetooth . getDevices ( ) ;
76
- console . log ( devices ) ;
74
+ const devices = await navigator . bluetooth . getDevices ( ) ;
77
75
this . connectionStep ( devices . length > 0 ? 2 : 1 ) ;
78
76
} catch ( error ) {
79
77
console . error ( error ) ;
@@ -119,7 +117,7 @@ class BLEWorkflow extends Workflow {
119
117
if ( ! this . connectionStatus ( ) ) {
120
118
try {
121
119
console . log ( 'Getting existing permitted Bluetooth devices...' ) ;
122
- const devices = await bluetooth . getDevices ( ) ;
120
+ const devices = await navigator . bluetooth . getDevices ( ) ;
123
121
124
122
console . log ( '> Found ' + devices . length + ' Bluetooth device(s).' ) ;
125
123
// These devices may not be powered on or in range, so scan for
@@ -137,7 +135,7 @@ class BLEWorkflow extends Workflow {
137
135
138
136
// Bring up a dialog to request a device
139
137
async requestDevice ( ) {
140
- return bluetooth . requestDevice ( {
138
+ return navigator . bluetooth . requestDevice ( {
141
139
filters : [ { services : [ 0xfebb ] } , ] , // <- Prefer filters to save energy & show relevant devices.
142
140
optionalServices : [ 0xfebb , bleNusServiceUUID ]
143
141
} ) ;
@@ -171,11 +169,11 @@ class BLEWorkflow extends Workflow {
171
169
device . removeEventListener ( 'advertisementreceived' , onAdvertisementReceived . bind ( this ) ) ;
172
170
device . addEventListener ( 'advertisementreceived' , onAdvertisementReceived . bind ( this ) ) ;
173
171
174
- this . debugLog ( "connecting to " + device . name ) ;
172
+ this . debugLog ( "Attempting to connect to " + device . name + "..." ) ;
175
173
try {
176
174
this . clearConnectStatus ( ) ;
177
175
console . log ( 'Watching advertisements from "' + device . name + '"...' ) ;
178
- console . log ( 'If no advertisements are received, make sure the device is powered on and in range. You can also try resetting the device' ) ;
176
+ console . log ( 'If no advertisements are received, make sure the device is powered on and in range. You can also try resetting the device. ' ) ;
179
177
await device . watchAdvertisements ( { signal : abortController . signal } ) ;
180
178
}
181
179
catch ( error ) {
@@ -194,22 +192,24 @@ class BLEWorkflow extends Workflow {
194
192
await this . connectToBluetoothDevice ( device ) ;
195
193
}
196
194
195
+ async onConnected ( e ) {
196
+ this . debugLog ( "Connected to " + this . bleDevice . name ) ;
197
+ await super . onConnected ( e ) ;
198
+ }
199
+
197
200
async switchToDevice ( device ) {
198
- console . log ( device ) ;
199
201
this . bleDevice = device ;
200
202
this . bleDevice . removeEventListener ( "gattserverdisconnected" , this . onDisconnected . bind ( this ) ) ;
201
203
this . bleDevice . addEventListener ( "gattserverdisconnected" , this . onDisconnected . bind ( this ) ) ;
202
- //this.bleServer = this.bleDevice.gatt;
203
204
console . log ( "connected" , this . bleServer ) ;
204
- let services ;
205
205
206
- console . log ( device . gatt . connected ) ;
207
- //try {
206
+ try {
207
+ let services ;
208
208
services = await this . bleServer . getPrimaryServices ( ) ;
209
- /*} catch (e) {
209
+ console . log ( services ) ;
210
+ } catch ( e ) {
210
211
console . log ( e , e . stack ) ;
211
- }*/
212
- console . log ( services ) ;
212
+ }
213
213
214
214
console . log ( 'Initializing File Transfer Client...' ) ;
215
215
this . initFileClient ( new FileTransferClient ( this . bleDevice , 65536 ) ) ;
@@ -253,7 +253,7 @@ class BLEWorkflow extends Workflow {
253
253
}
254
254
// Is this a new connection?
255
255
if ( ! this . bleDevice ) {
256
- let devices = await bluetooth . getDevices ( ) ;
256
+ let devices = await navigator . bluetooth . getDevices ( ) ;
257
257
for ( const device of devices ) {
258
258
await this . connectToBluetoothDevice ( device ) ;
259
259
}
0 commit comments