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