add helper function for importing contact

This commit is contained in:
liamcottle 2025-02-15 22:26:58 +13:00
parent 8184f8fc4c
commit 54a3d00d7e
2 changed files with 34 additions and 3 deletions

View file

@ -726,6 +726,37 @@ class Connection extends EventEmitter {
});
}
importContact(advertPacketBytes) {
return new Promise(async (resolve, reject) => {
try {
// resolve promise when we receive ok
const onOk = (response) => {
this.off(Constants.ResponseCodes.Ok, onOk);
this.off(Constants.ResponseCodes.Err, onErr);
resolve(response);
}
// reject promise when we receive err
const onErr = () => {
this.off(Constants.ResponseCodes.Ok, onOk);
this.off(Constants.ResponseCodes.Err, onErr);
reject();
}
// listen for events
this.once(Constants.ResponseCodes.Ok, onOk);
this.once(Constants.ResponseCodes.Err, onErr);
// import contact
await this.sendCommandImportContact(advertPacketBytes);
} catch(e) {
reject(e);
}
});
}
}
export default Connection;