workadventure/front/src/Components/MyCamera.svelte

38 lines
1.2 KiB
Svelte
Raw Normal View History

2021-05-28 15:48:58 +02:00
<script lang="typescript">
2021-12-06 16:12:37 +01:00
import { obtainedMediaConstraintStore } from "../Stores/MediaStore";
import { localStreamStore, isSilentStore } from "../Stores/MediaStore";
2021-05-28 15:48:58 +02:00
import SoundMeterWidget from "./SoundMeterWidget.svelte";
2021-12-06 16:12:37 +01:00
import { onDestroy } from "svelte";
import { srcObject } from "./Video/utils";
2022-01-21 17:06:03 +01:00
import LL from "../i18n/i18n-svelte";
2021-05-28 15:48:58 +02:00
2021-12-06 16:12:37 +01:00
let stream: MediaStream | null;
2021-05-28 15:48:58 +02:00
2021-12-06 16:12:37 +01:00
const unsubscribe = localStreamStore.subscribe((value) => {
if (value.type === "success") {
2021-05-28 15:48:58 +02:00
stream = value.stream;
} else {
stream = null;
}
});
onDestroy(unsubscribe);
let isSilent: boolean;
2021-12-06 16:12:37 +01:00
const unsubscribeIsSilent = isSilentStore.subscribe((value) => {
isSilent = value;
});
onDestroy(unsubscribeIsSilent);
2021-05-28 15:48:58 +02:00
</script>
<div>
<div class="video-container div-myCamVideo" class:hide={!$obtainedMediaConstraintStore.video || isSilent}>
{#if $localStreamStore.type === "success" && $localStreamStore.stream}
2021-12-06 16:12:37 +01:00
<video class="myCamVideo" use:srcObject={stream} autoplay muted playsinline />
<SoundMeterWidget {stream} />
2021-06-15 18:34:11 +02:00
{/if}
2021-05-28 15:48:58 +02:00
</div>
2022-01-21 17:06:03 +01:00
<div class="is-silent" class:hide={isSilent}>{$LL.camera.my.silentZone()}</div>
2021-05-28 15:48:58 +02:00
</div>