mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
add ability to send next message
This commit is contained in:
parent
85a3c36fbc
commit
1afba5b726
1 changed files with 27 additions and 0 deletions
|
|
@ -343,6 +343,33 @@ class Connection extends EventEmitter {
|
|||
});
|
||||
}
|
||||
|
||||
syncNextMessage() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
// resolve promise when we receive the message
|
||||
const onContactMessageReceived = (message) => {
|
||||
this.off(Constants.ResponseCodes.ContactMsgRecv, onContactMessageReceived);
|
||||
this.off(Constants.ResponseCodes.NoMoreMessages, onNoMoreMessagesReceived);
|
||||
resolve(message);
|
||||
}
|
||||
|
||||
// resolve promise when we have no more messages to receive
|
||||
const onNoMoreMessagesReceived = () => {
|
||||
this.off(Constants.ResponseCodes.ContactMsgRecv, onContactMessageReceived);
|
||||
this.off(Constants.ResponseCodes.NoMoreMessages, onNoMoreMessagesReceived);
|
||||
resolve(null);
|
||||
}
|
||||
|
||||
// listen for events
|
||||
this.once(Constants.ResponseCodes.ContactMsgRecv, onContactMessageReceived);
|
||||
this.once(Constants.ResponseCodes.NoMoreMessages, onNoMoreMessagesReceived);
|
||||
|
||||
// sync next message from device
|
||||
await this.sendCommandSyncNextMessage();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Connection;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue