]>
Commit | Line | Data |
---|---|---|
e2da0c51 RBR |
1 | 'use strict'; |
2 | ||
3 | const internals = { | |
4 | mediaStream: null | |
5 | }; | |
6 | ||
7 | module.exports = { | |
8 | async start() { | |
9 | ||
10 | internals.mediaStream = internals.mediaStream || await navigator.mediaDevices.getUserMedia({ | |
11 | audio: true | |
12 | }); | |
13 | ||
14 | return internals.mediaStream; | |
15 | }, | |
16 | ||
17 | stop() { | |
18 | ||
19 | if (!internals.mediaStream) { | |
20 | return; | |
21 | } | |
22 | ||
23 | for (const track of internals.mediaStream.getAudioTracks()) { | |
24 | track.stop(); | |
25 | } | |
26 | ||
27 | internals.mediaStream = null; | |
28 | } | |
29 | }; |