listen for sent and err response when sending text message

This commit is contained in:
liamcottle 2025-02-15 22:01:20 +13:00
parent 428eb70b59
commit 41d607a92f

View file

@ -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;