]> git.r.bdr.sh - rbdr/junction/blobdiff - extension/media.js
Ensure connections are closed
[rbdr/junction] / extension / media.js
index c13c6f12aeb13dd03ef3e40969a8bb4ae8d11948..ae60ec905c7f3bda3a311ea3a7766ec63e381a16 100644 (file)
@@ -1,27 +1,25 @@
 const internals = {
 const internals = {
-  mediaStream: null
+  mediaStream: null,
 };
 
 };
 
-export default {
-  async start() {
+export async function startMedia() {
+  internals.mediaStream =
+    internals.mediaStream ||
+    (await navigator.mediaDevices.getUserMedia({
+      audio: true,
+    }));
 
 
-    internals.mediaStream = internals.mediaStream || await navigator.mediaDevices.getUserMedia({
-      audio: true
-    });
+  return internals.mediaStream;
+}
 
 
-    return internals.mediaStream;
-  },
-
-  stop() {
-
-    if (!internals.mediaStream) {
-      return;
-    }
-
-    for (const track of internals.mediaStream.getAudioTracks()) {
-      track.stop();
-    }
+export async function stopMedia() {
+  if (!internals.mediaStream) {
+    return;
+  }
 
 
-    internals.mediaStream = null;
+  for (const track of internals.mediaStream.getTracks()) {
+    track.stop();
   }
   }
-};
+
+  internals.mediaStream = null;
+}