diff --git a/examples/nodejs_get_repeater_status.js b/examples/nodejs_get_repeater_status.js index 5ddaa0f..2939741 100644 --- a/examples/nodejs_get_repeater_status.js +++ b/examples/nodejs_get_repeater_status.js @@ -10,7 +10,8 @@ connection.on("connected", async () => { console.log("Connected"); // find contact - const contact = await connection.findContactByPublicKeyPrefix([0x93, 0x5c, 0x6b, 0x69]); + // const contact = await connection.findContactByPublicKeyPrefix([0x93, 0x5c, 0x6b, 0x69]); + const contact = await connection.findContactByName("Liam's Solar Repeater"); if(!contact){ console.log("Contact not found"); return; diff --git a/src/connection/connection.js b/src/connection/connection.js index 6e97fc5..e573fc8 100644 --- a/src/connection/connection.js +++ b/src/connection/connection.js @@ -760,6 +760,18 @@ class Connection extends EventEmitter { }); } + async findContactByName(name) { + + // get contacts + const contacts = await this.getContacts(); + + // find first contact matching name exactly + return contacts.find((contact) => { + return contact.advName === name; + }); + + } + async findContactByPublicKeyPrefix(pubKeyPrefix) { // get contacts