]> git.r.bdr.sh - rbdr/junction/blobdiff - extension/media.js
Update all versions
[rbdr/junction] / extension / media.js
index 33c6feecc969e696df0e849a315cbc364f05961b..416053aa7e65dda87ad70397f643224dc4378fab 100644 (file)
@@ -1,29 +1,25 @@
-'use strict';
-
 const internals = {
-  mediaStream: null
+  mediaStream: null,
 };
 
-module.exports = {
-  async start() {
-
-    internals.mediaStream = internals.mediaStream || await navigator.mediaDevices.getUserMedia({
-      audio: true
-    });
-
-    return internals.mediaStream;
-  },
-
-  stop() {
+export async function startMedia() {
+  internals.mediaStream =
+    internals.mediaStream ||
+    (await navigator.mediaDevices.getUserMedia({
+      audio: true,
+    }));
 
-    if (!internals.mediaStream) {
-      return;
-    }
+  return internals.mediaStream;
+}
 
-    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;
+}