Type: {{ contactTypeToString(contact.type) }} • Last Advert: {{ contact.lastAdvert }}
-
Path: ??? (Flood)
-
Path: Direct
-
Path: {{ contact.outPathLen }} hops [{{ formatOutPath(contact) }}]
+
+
+
+
{{ contact.advName }}
+
<{{ bytesToHex(contact.publicKey) }}>
+
Type: {{ contactTypeToString(contact.type) }} • Last Advert: {{ contact.lastAdvert }}
+
+ Path: ??? (Flood)
+ Path: Direct
+ Path: {{ contact.outPathLen }} hops [{{ formatOutPath(contact) }}]
+
+
+
+
Message
+
CLI
+
Set Path
+
GetStats
+
Share (Zero Hop)
+
Export
+
Reset Path
+
Forget
-
-
Message
-
Set Path
-
GetStats
-
Share (Zero Hop)
-
Export
-
Reset Path
-
Forget
+
+
+
+
+
+
{{ cliContact.advName }}
+
+
+
+
+
+
+
+
+ > {{ cliMessage.text }}
+ {{ cliMessage.text }}
+
@@ -154,12 +177,16 @@
import Constants from "./src/constants.js";
import SerialConnection from "./src/connection/serial_connection.js";
import BleConnection from "./src/connection/ble_connection.js";
+ import BufferUtils from "./src/buffer_utils.js";
Vue.createApp({
data() {
return {
connection: null,
selfInfo: null,
contacts: [],
+ cliCommand: null,
+ cliContact: null,
+ cliMessages: [],
};
},
mounted() {
@@ -326,8 +353,28 @@
await this.connection.addOrUpdateContact(publicKey, type, flags, outPathLen, outPath, advName, lastAdvert, advLat, advLon);
},
async syncNextMessage() {
+
+ // get next message
const message = await this.connection.syncNextMessage();
console.log("syncNextMessage", message);
+
+ // check if contact message
+ if(message.contactMessage){
+
+ // check if from cli contact
+ if(BufferUtils.areBuffersEqual(message.contactMessage.pubKeyPrefix, this.cliContact.publicKey.subarray(0, 6))){
+
+ // add remote response
+ this.cliMessages.push({
+ is_incoming: true,
+ text: message.contactMessage.text,
+ });
+
+ console.log("yes");
+ }
+
+ }
+
},
async sendMessage(contact) {
@@ -341,6 +388,33 @@
const response = await this.connection.sendTextMessage(contact.publicKey, message);
console.log(response);
+ },
+ async sendCliCommand() {
+
+ // do nothing if no contact selected
+ if(!this.cliContact){
+ return;
+ }
+
+ // make sure user provided command
+ const command = this.cliCommand;
+ if(!command){
+ return;
+ }
+
+ // add local command
+ this.cliMessages.push({
+ is_outgoing: true,
+ text: command,
+ });
+
+ // clear input
+ this.cliCommand = null;
+
+ // send command
+ const response = await this.connection.sendTextMessage(this.cliContact.publicKey, command, Constants.TxtTypes.CliData);
+ console.log(response);
+
},
async sendChannelTextMessage() {
@@ -461,6 +535,19 @@
alert(`Failed to login: ${e}`);
}
+ },
+ showCommandLine(contact) {
+
+ // hide cli if clicked same contact
+ if(this.cliContact === contact){
+ this.cliContact = null;
+ return;
+ }
+
+ // update ui
+ this.cliContact = contact;
+ this.cliMessages = [];
+
},
bytesToHex(uint8Array) {
return Array.from(uint8Array).map(byte => byte.toString(16).padStart(2, '0')).join('');
diff --git a/src/connection/connection.js b/src/connection/connection.js
index 15979e5..fb27e1a 100644
--- a/src/connection/connection.js
+++ b/src/connection/connection.js
@@ -654,7 +654,7 @@ class Connection extends EventEmitter {
});
}
- sendTextMessage(contactPublicKey, text) {
+ sendTextMessage(contactPublicKey, text, type) {
return new Promise(async (resolve, reject) => {
try {
@@ -677,7 +677,7 @@ class Connection extends EventEmitter {
this.once(Constants.ResponseCodes.Err, onErr);
// compose message
- const txtType = Constants.TxtTypes.Plain;
+ const txtType = type ?? Constants.TxtTypes.Plain;
const attempt = 0;
const senderTimestamp = Math.floor(Date.now() / 1000);