Skip to content

Commit

Permalink
check if browser supports bluetooth and serial
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcottle committed Nov 17, 2024
1 parent b5d185c commit 47b3efe
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/js/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import {BleConnection, Constants, HttpConnection, Protobuf, SerialConnection, Ty
class Connection {

static async connectViaBluetooth() {

// ensure browser supports web bluetooth
if(!navigator.bluetooth){
alert("Web Bluetooth is not supported in this browser");
return;
}

await this.connect(new BleConnection(), {
filters: [
{
Expand All @@ -13,12 +20,21 @@ class Connection {
},
],
});

}

static async connectViaSerial() {

// ensure browser supports web serial
if(!navigator.serial){
alert("Web Serial is not supported in this browser");
return null;
}

await this.connect(new SerialConnection(), {
concurrentLogOutput: true,
});

}

static async connectViaHttp(address) {
Expand Down

0 comments on commit 47b3efe

Please sign in to comment.