mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
detect serial disconnect
This commit is contained in:
parent
995e740347
commit
af6403bf6a
2 changed files with 12 additions and 0 deletions
|
|
@ -142,18 +142,21 @@
|
|||
async askForSerialPort() {
|
||||
this.connection = await SerialConnection.open();
|
||||
this.connection.on("connected", () => this.onConnected());
|
||||
this.connection.on("disconnected", () => this.onDisconnected());
|
||||
// this.connection.on("tx", (data) => console.log("tx", data));
|
||||
// this.connection.on("rx", (data) => console.log("rx", data));
|
||||
},
|
||||
async askForBleDevice() {
|
||||
this.connection = await BleConnection.open();
|
||||
this.connection.on("connected", () => this.onConnected());
|
||||
this.connection.on("disconnected", () => this.onDisconnected());
|
||||
// this.connection.on("tx", (data) => console.log("tx", data));
|
||||
// this.connection.on("rx", (data) => console.log("rx", data));
|
||||
},
|
||||
async disconnect() {
|
||||
if(this.connection){
|
||||
await this.connection.close();
|
||||
this.onDisconnected();
|
||||
this.connection = null;
|
||||
}
|
||||
},
|
||||
|
|
@ -166,6 +169,10 @@
|
|||
await this.loadContacts();
|
||||
});
|
||||
},
|
||||
onDisconnected() {
|
||||
console.log("disconnected");
|
||||
this.connection = null;
|
||||
},
|
||||
async loadSelfInfo() {
|
||||
this.selfInfo = await this.connection.getSelfInfo();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ class SerialConnection extends Connection {
|
|||
this.readBuffer = [];
|
||||
this.readLoop();
|
||||
|
||||
// listen for disconnect
|
||||
this.serialPort.addEventListener("disconnect", () => {
|
||||
this.emit("disconnected");
|
||||
});
|
||||
|
||||
// fire connected callback after constructor has returned
|
||||
setTimeout(() => {
|
||||
this.onConnected();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue