]> git.r.bdr.sh - rbdr/junction/blame - extension/peers.js
Format extension
[rbdr/junction] / extension / peers.js
CommitLineData
e2da0c51
RBR
1const internals = {
2 peers: {},
3
4 createAudioElement(source) {
b9a2baf2
RBR
5 const audioElement = document.createElement("audio");
6 audioElement.setAttribute("class", "junction-call-audio");
7 audioElement.autoplay = "autoplay";
d38261f1
RBR
8
9 // WE WILL NOT LOSE TADA SUPPORT
b9a2baf2 10 if (typeof source === "string") {
d38261f1 11 audioElement.src = source;
b9a2baf2 12 } else {
80172072 13 audioElement.srcObject = source;
d38261f1
RBR
14 }
15
b9a2baf2 16 document.querySelector("body").appendChild(audioElement);
e2da0c51
RBR
17
18 return audioElement;
b9a2baf2 19 },
e2da0c51
RBR
20};
21
80172072 22export default {
d38261f1 23 add(id, source) {
e2da0c51 24 internals.peers[id] && this.remove(id);
b9a2baf2 25 internals.peers[id] = internals.createAudioElement(source);
e2da0c51
RBR
26 },
27
28 remove(id) {
e2da0c51
RBR
29 internals.peers[id] && internals.peers[id].remove();
30 delete internals.peers[id];
31 },
32
33 count() {
e2da0c51
RBR
34 return Object.keys(internals.peers).length;
35 },
36
37 reset() {
e2da0c51 38 internals.peers = {};
b9a2baf2
RBR
39 document
40 .querySelectorAll(".junction-call-audio")
41 .forEach((audioElement) => audioElement.remove());
42 },
e2da0c51 43};