]> git.r.bdr.sh - rbdr/junction/blobdiff - extension/media.js
Refactor content script
[rbdr/junction] / extension / media.js
index c13c6f12aeb13dd03ef3e40969a8bb4ae8d11948..416053aa7e65dda87ad70397f643224dc4378fab 100644 (file)
@@ -1,27 +1,25 @@
 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.getAudioTracks()) {
+    track.stop();
   }
-};
+
+  internals.mediaStream = null;
+}