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