mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
add share contact command
This commit is contained in:
parent
28c7f14e74
commit
cf4e1ccd83
3 changed files with 18 additions and 6 deletions
16
index.html
16
index.html
|
|
@ -104,7 +104,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="divide-y">
|
||||
<div v-for="contact of contacts" class="flex px-2 py-1">
|
||||
<div v-for="contact of contacts" class="px-2 py-1">
|
||||
<div class="my-auto mr-auto">
|
||||
<div class="font-semibold">{{ contact.advName }}</div>
|
||||
<div class="text-sm text-gray-500"><{{ bytesToHex(contact.publicKey) }}></div>
|
||||
|
|
@ -115,9 +115,10 @@
|
|||
<span v-else>Path: {{ contact.outPathLen }} hops [{{ formatOutPath(contact) }}]</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex my-auto ml-2 space-x-2">
|
||||
<div class="flex my-auto space-x-2">
|
||||
<div @click="sendMessage(contact)" class="hover:underline cursor-pointer">Message</div>
|
||||
<div @click="setPath(contact)" class="hover:underline cursor-pointer">Set Path</div>
|
||||
<div @click="shareContact(contact)" class="hover:underline cursor-pointer">Share (Zero Hop)</div>
|
||||
<div @click="resetPath(contact)" class="hover:underline cursor-pointer">Reset Path</div>
|
||||
<div @click="removeContact(contact)" class="hover:underline cursor-pointer">Forget</div>
|
||||
</div>
|
||||
|
|
@ -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 = [
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ class Constants {
|
|||
ResetPath: 13,
|
||||
SetAdvertLatLon: 14,
|
||||
RemoveContact: 15,
|
||||
ShareContact: 16,
|
||||
}
|
||||
|
||||
static ResponseCodes = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue