mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
add helper function for exporting contact
This commit is contained in:
parent
54a3d00d7e
commit
fdc83c2f78
2 changed files with 37 additions and 1 deletions
|
|
@ -757,6 +757,37 @@ class Connection extends EventEmitter {
|
|||
});
|
||||
}
|
||||
|
||||
exportContact(pubKey = null) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
|
||||
// resolve promise when we receive export contact response
|
||||
const onExportContact = (response) => {
|
||||
this.off(Constants.ResponseCodes.ExportContact, onExportContact);
|
||||
this.off(Constants.ResponseCodes.Err, onErr);
|
||||
resolve(response);
|
||||
}
|
||||
|
||||
// reject promise when we receive err
|
||||
const onErr = () => {
|
||||
this.off(Constants.ResponseCodes.ExportContact, onExportContact);
|
||||
this.off(Constants.ResponseCodes.Err, onErr);
|
||||
reject();
|
||||
}
|
||||
|
||||
// listen for events
|
||||
this.once(Constants.ResponseCodes.ExportContact, onExportContact);
|
||||
this.once(Constants.ResponseCodes.Err, onErr);
|
||||
|
||||
// export contact
|
||||
await this.sendCommandExportContact(pubKey);
|
||||
|
||||
} catch(e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Connection;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue