Skip to content

Commit eab6969

Browse files
committed
Initial library implementation
1 parent 4251ef2 commit eab6969

File tree

3 files changed

+629
-31
lines changed

3 files changed

+629
-31
lines changed

js/workflows/ble.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {CONNTYPE} from '../constants.js';
77
import {Workflow} from './workflow.js';
88
import {GenericModal, DeviceInfoModal} from '../common/dialogs.js';
99
import {sleep} from '../common/utilities.js';
10+
import {bluetooth} from 'webbluetooth';
1011

1112
const bleNusServiceUUID = 'adaf0001-4369-7263-7569-74507974686e';
1213
const bleNusCharRXUUID = 'adaf0002-4369-7263-7569-74507974686e';
@@ -74,7 +75,7 @@ class BLEWorkflow extends Workflow {
7475
stepOne.classList.add("hidden");
7576
}
7677
try {
77-
const devices = await navigator.bluetooth.getDevices();
78+
const devices = await bluetooth.getDevices();
7879
console.log(devices);
7980
this.connectionStep(devices.length > 0 ? 2 : 1);
8081
} catch (e) {
@@ -120,7 +121,7 @@ class BLEWorkflow extends Workflow {
120121
if (!this.connectionStatus()) {
121122
try {
122123
console.log('Getting existing permitted Bluetooth devices...');
123-
const devices = await navigator.bluetooth.getDevices();
124+
const devices = await bluetooth.getDevices();
124125

125126
console.log('> Found ' + devices.length + ' Bluetooth device(s).');
126127
// These devices may not be powered on or in range, so scan for
@@ -138,7 +139,7 @@ class BLEWorkflow extends Workflow {
138139

139140
// Bring up a dialog to request a device
140141
async requestDevice() {
141-
return navigator.bluetooth.requestDevice({
142+
return bluetooth.requestDevice({
142143
filters: [{services: [0xfebb]},], // <- Prefer filters to save energy & show relevant devices.
143144
optionalServices: [0xfebb, bleNusServiceUUID]
144145
});
@@ -272,7 +273,7 @@ class BLEWorkflow extends Workflow {
272273
}
273274
// Is this a new connection?
274275
if (!this.bleDevice) {
275-
let devices = await navigator.bluetooth.getDevices();
276+
let devices = await bluetooth.getDevices();
276277
for (const device of devices) {
277278
await this.connectToBluetoothDevice(device);
278279
}

0 commit comments

Comments
 (0)