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