use base class methods for disconnected event

This commit is contained in:
liamcottle 2025-02-11 23:42:58 +13:00
parent c09ad0514c
commit 09ff8771d8
3 changed files with 6 additions and 2 deletions

View file

@ -44,7 +44,7 @@ class BleConnection extends Connection {
// listen for ble disconnect
this.bleDevice.addEventListener("gattserverdisconnected", () => {
this.emit("disconnected");
this.onDisconnected();
});
// connect to gatt server

View file

@ -9,6 +9,10 @@ class Connection extends EventEmitter {
this.emit("connected");
}
onDisconnected() {
this.emit("disconnected");
}
async close() {
throw new Error("This method must be implemented by the subclass.");
}

View file

@ -17,7 +17,7 @@ class SerialConnection extends Connection {
// listen for disconnect
this.serialPort.addEventListener("disconnect", () => {
this.emit("disconnected");
this.onDisconnected();
});
// fire connected callback after constructor has returned