]> git.r.bdr.sh - rbdr/junction/blob - extension/media.js
5e83ac74900d17fe6086cd269ae511c7fa8cb19c
[rbdr/junction] / extension / media.js
1 const internals = {
2 mediaStream: null,
3 };
4
5 export default {
6 async start() {
7 internals.mediaStream =
8 internals.mediaStream ||
9 (await navigator.mediaDevices.getUserMedia({
10 audio: true,
11 }));
12
13 return internals.mediaStream;
14 },
15
16 stop() {
17 if (!internals.mediaStream) {
18 return;
19 }
20
21 for (const track of internals.mediaStream.getAudioTracks()) {
22 track.stop();
23 }
24
25 internals.mediaStream = null;
26 },
27 };