]> git.r.bdr.sh - rbdr/junction/blame_incremental - extension/peers.js
Use source and support srcObject
[rbdr/junction] / extension / peers.js
... / ...
CommitLineData
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');
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
26module.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};