--- /dev/null
+'use strict';
+
+const internals = {
+ mediaStream: null
+};
+
+module.exports = {
+ async start() {
+
+ internals.mediaStream = internals.mediaStream || await navigator.mediaDevices.getUserMedia({
+ audio: true
+ });
+
+ return internals.mediaStream;
+ },
+
+ stop() {
+
+ if (!internals.mediaStream) {
+ return;
+ }
+
+ for (const track of internals.mediaStream.getAudioTracks()) {
+ track.stop();
+ }
+
+ internals.mediaStream = null;
+ }
+};
--- /dev/null
+'use strict';
+
+const internals = {
+ peers: {},
+
+ createAudioElement(source) {
+
+ const audioElement = document.createElement('audio');
+ audioElement.setAttribute('class', 'junction-call-audio');
+ audioElement.src = source;
+ audioElement.autoplay = 'autoplay';
+ document.querySelector('body').appendChild(audioElement);
+
+ return audioElement;
+ }
+};
+
+module.exports = {
+ add(id, url) {
+
+ internals.peers[id] && this.remove(id);
+ internals.peers[id] = internals.createAudioElement(url)
+ },
+
+ remove(id) {
+
+ internals.peers[id] && internals.peers[id].remove();
+ delete internals.peers[id];
+ },
+
+ count() {
+
+ return Object.keys(internals.peers).length;
+ },
+
+ reset() {
+
+ internals.peers = {};
+ document.querySelectorAll('.junction-call-audio').forEach((audioElement) => audioElement.remove());
+ }
+};