mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
find channel by name or secret
This commit is contained in:
parent
2ec624c318
commit
8059fea1b4
2 changed files with 36 additions and 2 deletions
|
|
@ -14,9 +14,18 @@ connection.on("connected", async () => {
|
|||
// update clock on meshcore device
|
||||
await connection.syncDeviceTime();
|
||||
|
||||
// send message to channel 0
|
||||
// find channel
|
||||
const channel = await connection.findChannelByName("Public");
|
||||
// const channel = await connection.findChannelBySecret(Buffer.from("8b3387e9c5cdea6ac9e5edbaa115cd72", "hex"));
|
||||
if(!channel){
|
||||
console.log("Channel not found");
|
||||
await connection.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// send message to channel
|
||||
console.log("Sending message...");
|
||||
await connection.sendChannelTextMessage(0, "Hello from MeshCore.js");
|
||||
await connection.sendChannelTextMessage(channel.channelIdx, "Hello from MeshCore.js");
|
||||
|
||||
// disconnect
|
||||
await connection.close();
|
||||
|
|
|
|||
|
|
@ -1692,6 +1692,31 @@ class Connection extends EventEmitter {
|
|||
});
|
||||
}
|
||||
|
||||
async findChannelByName(name) {
|
||||
|
||||
// get channels
|
||||
const channels = await this.getChannels();
|
||||
|
||||
// find first channel matching name exactly
|
||||
return channels.find((channel) => {
|
||||
console.log(channel);
|
||||
return channel.name === name;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
async findChannelBySecret(secret) {
|
||||
|
||||
// get channels
|
||||
const channels = await this.getChannels();
|
||||
|
||||
// find first channel matching secret
|
||||
return channels.find((channel) => {
|
||||
return BufferUtils.areBuffersEqual(secret, channel.secret);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
tracePath(path) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue