]>
Commit | Line | Data |
---|---|---|
1 | 'use strict'; | |
2 | ||
3 | const internals = { | |
4 | peers: {}, | |
5 | ||
6 | createAudioElement(source) { | |
7 | ||
8 | const audioElement = document.createElement('audio'); | |
9 | audioElement.setAttribute('class', 'junction-call-audio'); | |
10 | audioElement.autoplay = 'autoplay'; | |
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 | ||
20 | document.querySelector('body').appendChild(audioElement); | |
21 | ||
22 | return audioElement; | |
23 | } | |
24 | }; | |
25 | ||
26 | module.exports = { | |
27 | add(id, source) { | |
28 | ||
29 | internals.peers[id] && this.remove(id); | |
30 | internals.peers[id] = internals.createAudioElement(source) | |
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 | }; |