]> git.r.bdr.sh - rbdr/junction/blame_incremental - extension/peers.js
Add media and peer objects
[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.src = source;
11 audioElement.autoplay = 'autoplay';
12 document.querySelector('body').appendChild(audioElement);
13
14 return audioElement;
15 }
16};
17
18module.exports = {
19 add(id, url) {
20
21 internals.peers[id] && this.remove(id);
22 internals.peers[id] = internals.createAudioElement(url)
23 },
24
25 remove(id) {
26
27 internals.peers[id] && internals.peers[id].remove();
28 delete internals.peers[id];
29 },
30
31 count() {
32
33 return Object.keys(internals.peers).length;
34 },
35
36 reset() {
37
38 internals.peers = {};
39 document.querySelectorAll('.junction-call-audio').forEach((audioElement) => audioElement.remove());
40 }
41};