]> git.r.bdr.sh - rbdr/junction/blobdiff - extension/peers.js
Format extension
[rbdr/junction] / extension / peers.js
index 41155d414edac7452a91970b03ed1b4393a5e726..2b4e3d68325819430748144deff796e42069e878 100644 (file)
@@ -1,41 +1,43 @@
-'use strict';
-
 const internals = {
   peers: {},
 
   createAudioElement(source) {
+    const audioElement = document.createElement("audio");
+    audioElement.setAttribute("class", "junction-call-audio");
+    audioElement.autoplay = "autoplay";
+
+    // WE WILL NOT LOSE TADA SUPPORT
+    if (typeof source === "string") {
+      audioElement.src = source;
+    } else {
+      audioElement.srcObject = source;
+    }
 
-    const audioElement = document.createElement('audio');
-    audioElement.setAttribute('class', 'junction-call-audio');
-    audioElement.src = source;
-    audioElement.autoplay = 'autoplay';
-    document.querySelector('body').appendChild(audioElement);
+    document.querySelector("body").appendChild(audioElement);
 
     return audioElement;
-  }
+  },
 };
 
-module.exports = {
-  add(id, url) {
-
+export default {
+  add(id, source) {
     internals.peers[id] && this.remove(id);
-    internals.peers[id] = internals.createAudioElement(url)
+    internals.peers[id] = internals.createAudioElement(source);
   },
 
   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());
-  }
+    document
+      .querySelectorAll(".junction-call-audio")
+      .forEach((audioElement) => audioElement.remove());
+  },
 };