From cf4e1ccd8348d6056df16aabda5b631bafac81c4 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sat, 15 Feb 2025 20:37:17 +1300 Subject: [PATCH] add share contact command --- index.html | 16 ++++++++++------ src/connection/connection.js | 7 +++++++ src/constants.js | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index de5e6c1..a620da6 100644 --- a/index.html +++ b/index.html @@ -104,7 +104,7 @@
-
+
{{ contact.advName }}
<{{ bytesToHex(contact.publicKey) }}>
@@ -115,9 +115,10 @@ Path: {{ contact.outPathLen }} hops [{{ formatOutPath(contact) }}]
-
+
Message
Set Path
+
Share (Zero Hop)
Reset Path
Forget
@@ -149,15 +150,15 @@ 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)); + 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)); + this.connection.on("tx", (data) => console.log("tx", data)); + this.connection.on("rx", (data) => console.log("rx", data)); }, async disconnect() { if(this.connection){ @@ -337,6 +338,9 @@ await this.loadContacts(); }, + async shareContact(contact) { + await this.connection.sendCommandShareContact(contact.publicKey); + }, async setPath(contact) { const newOutPath = [ diff --git a/src/connection/connection.js b/src/connection/connection.js index bd94102..27f984b 100644 --- a/src/connection/connection.js +++ b/src/connection/connection.js @@ -147,6 +147,13 @@ class Connection extends EventEmitter { await this.sendToRadioFrame(data.toBytes()); } + async sendCommandShareContact(pubKey) { + const data = new BufferWriter(); + data.writeByte(Constants.CommandCodes.ShareContact); + data.writeBytes(pubKey); // 32 bytes + await this.sendToRadioFrame(data.toBytes()); + } + onFrameReceived(frame) { // emit received frame diff --git a/src/constants.js b/src/constants.js index 304160b..28f3b45 100644 --- a/src/constants.js +++ b/src/constants.js @@ -27,6 +27,7 @@ class Constants { ResetPath: 13, SetAdvertLatLon: 14, RemoveContact: 15, + ShareContact: 16, } static ResponseCodes = {