@@ -7,7 +7,6 @@ import {CONNTYPE} from '../constants.js';
77import { Workflow } from './workflow.js' ;
88import { GenericModal , DeviceInfoModal } from '../common/dialogs.js' ;
99import { sleep } from '../common/utilities.js' ;
10- import { bluetooth } from 'webbluetooth' ;
1110
1211const bleNusServiceUUID = 'adaf0001-4369-7263-7569-74507974686e' ;
1312const bleNusCharRXUUID = 'adaf0002-4369-7263-7569-74507974686e' ;
@@ -72,8 +71,7 @@ class BLEWorkflow extends Workflow {
7271 }
7372 try {
7473 this . clearConnectStatus ( ) ;
75- const devices = await bluetooth . getDevices ( ) ;
76- console . log ( devices ) ;
74+ const devices = await navigator . bluetooth . getDevices ( ) ;
7775 this . connectionStep ( devices . length > 0 ? 2 : 1 ) ;
7876 } catch ( error ) {
7977 console . error ( error ) ;
@@ -119,7 +117,7 @@ class BLEWorkflow extends Workflow {
119117 if ( ! this . connectionStatus ( ) ) {
120118 try {
121119 console . log ( 'Getting existing permitted Bluetooth devices...' ) ;
122- const devices = await bluetooth . getDevices ( ) ;
120+ const devices = await navigator . bluetooth . getDevices ( ) ;
123121
124122 console . log ( '> Found ' + devices . length + ' Bluetooth device(s).' ) ;
125123 // These devices may not be powered on or in range, so scan for
@@ -137,7 +135,7 @@ class BLEWorkflow extends Workflow {
137135
138136 // Bring up a dialog to request a device
139137 async requestDevice ( ) {
140- return bluetooth . requestDevice ( {
138+ return navigator . bluetooth . requestDevice ( {
141139 filters : [ { services : [ 0xfebb ] } , ] , // <- Prefer filters to save energy & show relevant devices.
142140 optionalServices : [ 0xfebb , bleNusServiceUUID ]
143141 } ) ;
@@ -171,7 +169,7 @@ class BLEWorkflow extends Workflow {
171169 device . removeEventListener ( 'advertisementreceived' , onAdvertisementReceived . bind ( this ) ) ;
172170 device . addEventListener ( 'advertisementreceived' , onAdvertisementReceived . bind ( this ) ) ;
173171
174- this . debugLog ( "connecting to " + device . name ) ;
172+ this . debugLog ( "Attempting to connect to " + device . name + "..." ) ;
175173 try {
176174 this . clearConnectStatus ( ) ;
177175 console . log ( 'Watching advertisements from "' + device . name + '"...' ) ;
@@ -194,22 +192,24 @@ class BLEWorkflow extends Workflow {
194192 await this . connectToBluetoothDevice ( device ) ;
195193 }
196194
195+ async onConnected ( e ) {
196+ this . debugLog ( "Connected to " + this . bleDevice . name ) ;
197+ await super . onConnected ( e ) ;
198+ }
199+
197200 async switchToDevice ( device ) {
198- console . log ( device ) ;
199201 this . bleDevice = device ;
200202 this . bleDevice . removeEventListener ( "gattserverdisconnected" , this . onDisconnected . bind ( this ) ) ;
201203 this . bleDevice . addEventListener ( "gattserverdisconnected" , this . onDisconnected . bind ( this ) ) ;
202- //this.bleServer = this.bleDevice.gatt;
203204 console . log ( "connected" , this . bleServer ) ;
204- let services ;
205205
206- console . log ( device . gatt . connected ) ;
207- //try {
206+ try {
207+ let services ;
208208 services = await this . bleServer . getPrimaryServices ( ) ;
209- /*} catch (e) {
209+ console . log ( services ) ;
210+ } catch ( e ) {
210211 console . log ( e , e . stack ) ;
211- }*/
212- console . log ( services ) ;
212+ }
213213
214214 console . log ( 'Initializing File Transfer Client...' ) ;
215215 this . initFileClient ( new FileTransferClient ( this . bleDevice , 65536 ) ) ;
@@ -253,7 +253,7 @@ class BLEWorkflow extends Workflow {
253253 }
254254 // Is this a new connection?
255255 if ( ! this . bleDevice ) {
256- let devices = await bluetooth . getDevices ( ) ;
256+ let devices = await navigator . bluetooth . getDevices ( ) ;
257257 for ( const device of devices ) {
258258 await this . connectToBluetoothDevice ( device ) ;
259259 }
0 commit comments