-'use strict';
-
const internals = {
- mediaStream: null
+ mediaStream: null,
};
-module.exports = {
- async start() {
-
- internals.mediaStream = internals.mediaStream || await navigator.mediaDevices.getUserMedia({
- audio: true
- });
-
- return internals.mediaStream;
- },
-
- stop() {
+export async function startMedia() {
+ internals.mediaStream =
+ internals.mediaStream ||
+ (await navigator.mediaDevices.getUserMedia({
+ audio: true,
+ }));
- if (!internals.mediaStream) {
- return;
- }
+ return internals.mediaStream;
+}
- for (const track of internals.mediaStream.getAudioTracks()) {
- track.stop();
- }
+export async function stopMedia() {
+ if (!internals.mediaStream) {
+ return;
+ }
- internals.mediaStream = null;
+ for (const track of internals.mediaStream.getAudioTracks()) {
+ track.stop();
}
-};
+
+ internals.mediaStream = null;
+}