add send text message function

This commit is contained in:
liamcottle 2025-02-12 23:00:07 +13:00
parent 8dc58d60c4
commit 272ece07e8
2 changed files with 27 additions and 9 deletions

View file

@ -291,15 +291,9 @@
return;
}
// compose message
const txtType = Constants.TxtTypes.Plain;
const attempt = 0;
const senderTimestamp = Math.floor(Date.now() / 1000);
const pubKeyPrefix = contact.publicKey;
const text = message;
// send message
await this.connection.sendCommandSendTxtMsg(txtType, attempt, senderTimestamp, pubKeyPrefix, text);
const response = await this.connection.sendTextMessage(contact.publicKey, message);
console.log(response);
},
async resetPath(contact) {

View file

@ -229,7 +229,8 @@ class Connection extends EventEmitter {
onSentResponse(bufferReader) {
this.emit(Constants.ResponseCodes.Sent, {
expectedAckCrc: bufferReader.readUInt32LE(),
estTimeout: bufferReader.readUInt32LE(),
});
}
@ -310,6 +311,29 @@ class Connection extends EventEmitter {
});
}
sendTextMessage(contactPublicKey, text) {
return new Promise(async (resolve, reject) => {
try {
// resolve with the first sent response
this.once(Constants.ResponseCodes.Sent, (response) => {
resolve(response);
});
// compose message
const txtType = Constants.TxtTypes.Plain;
const attempt = 0;
const senderTimestamp = Math.floor(Date.now() / 1000);
// send message
await this.sendCommandSendTxtMsg(txtType, attempt, senderTimestamp, contactPublicKey, text);
} catch(e) {
reject(e);
}
});
}
}
export default Connection;