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