X-Git-Url: https://git.r.bdr.sh/rbdr/junction/blobdiff_plain/e2da0c51692b64318a0f1b8d888536ee632c53d6..30295bf26ceb753bda98b0808c98021dc2b5901b:/extension/media.js?ds=sidebyside diff --git a/extension/media.js b/extension/media.js index 33c6fee..416053a 100644 --- a/extension/media.js +++ b/extension/media.js @@ -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; +}