]> git.r.bdr.sh - rbdr/junction/blob - extension/media.js
c13c6f12aeb13dd03ef3e40969a8bb4ae8d11948
[rbdr/junction] / extension / media.js
1 const internals = {
2 mediaStream: null
3 };
4
5 export default {
6 async start() {
7
8 internals.mediaStream = internals.mediaStream || await navigator.mediaDevices.getUserMedia({
9 audio: true
10 });
11
12 return internals.mediaStream;
13 },
14
15 stop() {
16
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 };