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