mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
listen for sent and err response when sending text message
This commit is contained in:
parent
428eb70b59
commit
41d607a92f
1 changed files with 16 additions and 3 deletions
|
|
@ -521,10 +521,23 @@ class Connection extends EventEmitter {
|
|||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
|
||||
// resolve with the first sent response
|
||||
this.once(Constants.ResponseCodes.Sent, (response) => {
|
||||
// resolve promise when we receive sent response
|
||||
const onSent = (response) => {
|
||||
this.off(Constants.ResponseCodes.Sent, onSent);
|
||||
this.off(Constants.ResponseCodes.Err, onErr);
|
||||
resolve(response);
|
||||
});
|
||||
}
|
||||
|
||||
// reject promise when we receive err
|
||||
const onErr = () => {
|
||||
this.off(Constants.ResponseCodes.Sent, onSent);
|
||||
this.off(Constants.ResponseCodes.Err, onErr);
|
||||
reject();
|
||||
}
|
||||
|
||||
// listen for events
|
||||
this.once(Constants.ResponseCodes.Sent, onSent);
|
||||
this.once(Constants.ResponseCodes.Err, onErr);
|
||||
|
||||
// compose message
|
||||
const txtType = Constants.TxtTypes.Plain;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue