-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathaudio_call_parrot_incoming_link.js
More file actions
54 lines (42 loc) · 1.79 KB
/
Copy pathaudio_call_parrot_incoming_link.js
File metadata and controls
54 lines (42 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {
Reticulum,
Destination,
Identity,
TCPClientInterface,
} from "../src/reticulum.js";
// create rns instance
const rns = new Reticulum();
// add interfaces
rns.addInterface(new TCPClientInterface("localhost", "127.0.0.1", 4242));
// create test identity
// const identity = Identity.create();
const identity = Identity.fromPrivateKey(Buffer.from("9339cfce1fc75d4db4697cada620bb229de8a2164287c9302dbce840f38af39452f63722ef745fcef7bb3f90984b80c43a77ad1ff11127b88035b4ae4e670eaa", "hex"));
// create inbound audio call destination
const audioCallDestination = rns.registerDestination(identity, Destination.IN, Destination.SINGLE, "call", "audio");
// listen for announces
const announcedDestinations = {};
rns.on("announce", (data) => {
announcedDestinations[data.announce.destinationHash] = data.announce;
console.log(`${data.announce.destinationHash.toString("hex")} is now ${data.hops} hops away on interface [${data.interface_name}] public key: ${data.announce.identity.getPublicKey().toString("hex")}`);
});
// anounce self
setTimeout(() => {
console.log(`announcing ${audioCallDestination.hash.toString("hex")}`);
audioCallDestination.announce(Buffer.from("@liamcottle/rns.js"));
}, 2000);
// listen for incoming audio call link requests
audioCallDestination.on("link_request", (link) => {
// log
console.log("on link request", link);
// log when link is established
link.on("established", () => {
console.log(`link established rtt: ${link.rtt}ms`);
});
// forward all packets received over the link back to the sender over the same link
link.on("packet", (event) => {
console.log("link packet received", event.packet.packetHash.toString("hex"));
link.send(event.data);
});
// accept link from sender
link.accept();
});