]>
Commit | Line | Data |
---|---|---|
e2da0c51 RBR |
1 | const internals = { |
2 | peers: {}, | |
3 | ||
4 | createAudioElement(source) { | |
5 | ||
6 | const audioElement = document.createElement('audio'); | |
7 | audioElement.setAttribute('class', 'junction-call-audio'); | |
e2da0c51 | 8 | audioElement.autoplay = 'autoplay'; |
d38261f1 RBR |
9 | |
10 | // WE WILL NOT LOSE TADA SUPPORT | |
11 | if (typeof source === 'string') { | |
12 | audioElement.src = source; | |
13 | } | |
14 | else { | |
80172072 | 15 | audioElement.srcObject = source; |
d38261f1 RBR |
16 | } |
17 | ||
e2da0c51 RBR |
18 | document.querySelector('body').appendChild(audioElement); |
19 | ||
20 | return audioElement; | |
21 | } | |
22 | }; | |
23 | ||
80172072 | 24 | export default { |
d38261f1 | 25 | add(id, source) { |
e2da0c51 RBR |
26 | |
27 | internals.peers[id] && this.remove(id); | |
d38261f1 | 28 | internals.peers[id] = internals.createAudioElement(source) |
e2da0c51 RBR |
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 | }; |