do not subscribe to silentStore if not needed

This commit is contained in:
Piotr 'pwh' Hanusiak 2022-04-22 14:35:57 +02:00
parent 1575368e52
commit 530254e0e0
2 changed files with 13 additions and 27 deletions

View File

@ -13,7 +13,6 @@
import lockImg from "./images/lock.svg"; import lockImg from "./images/lock.svg";
import { LayoutMode } from "../WebRtc/LayoutManager"; import { LayoutMode } from "../WebRtc/LayoutManager";
import { peerStore } from "../Stores/PeerStore"; import { peerStore } from "../Stores/PeerStore";
import { onDestroy } from "svelte";
import { embedScreenLayout } from "../Stores/EmbedScreensStore"; import { embedScreenLayout } from "../Stores/EmbedScreensStore";
import { followRoleStore, followStateStore, followUsersStore } from "../Stores/FollowStore"; import { followRoleStore, followStateStore, followUsersStore } from "../Stores/FollowStore";
import { gameManager } from "../Phaser/Game/GameManager"; import { gameManager } from "../Phaser/Game/GameManager";
@ -22,7 +21,7 @@
const gameScene = gameManager.getCurrentGameScene(); const gameScene = gameManager.getCurrentGameScene();
function screenSharingClick(): void { function screenSharingClick(): void {
if (isSilent) return; if ($silentStore) return;
if ($requestedScreenSharingState === true) { if ($requestedScreenSharingState === true) {
requestedScreenSharingState.disableScreenSharing(); requestedScreenSharingState.disableScreenSharing();
} else { } else {
@ -31,7 +30,7 @@
} }
function cameraClick(): void { function cameraClick(): void {
if (isSilent) return; if ($silentStore) return;
if ($requestedCameraState === true) { if ($requestedCameraState === true) {
requestedCameraState.disableWebcam(); requestedCameraState.disableWebcam();
} else { } else {
@ -40,7 +39,7 @@
} }
function microphoneClick(): void { function microphoneClick(): void {
if (isSilent) return; if ($silentStore) return;
if ($requestedMicrophoneState === true) { if ($requestedMicrophoneState === true) {
requestedMicrophoneState.disableMicrophone(); requestedMicrophoneState.disableMicrophone();
} else { } else {
@ -75,12 +74,6 @@
function lockClick() { function lockClick() {
gameScene.connection?.emitLockGroup(!$currentPlayerGroupLockStateStore); gameScene.connection?.emitLockGroup(!$currentPlayerGroupLockStateStore);
} }
let isSilent: boolean;
const unsubscribeIsSilent = silentStore.subscribe((silent) => {
isSilent = silent;
});
onDestroy(unsubscribeIsSilent);
</script> </script>
<div class="btn-cam-action"> <div class="btn-cam-action">
@ -94,7 +87,7 @@
<div <div
class="btn-follow" class="btn-follow"
class:hide={($peerStore.size === 0 && $followStateStore === "off") || isSilent} class:hide={($peerStore.size === 0 && $followStateStore === "off") || $silentStore}
class:disabled={$followStateStore !== "off"} class:disabled={$followStateStore !== "off"}
on:click={followClick} on:click={followClick}
> >
@ -103,7 +96,7 @@
<div <div
class="btn-lock" class="btn-lock"
class:hide={$peerStore.size === 0 || isSilent} class:hide={$peerStore.size === 0 || $silentStore}
class:disabled={$currentPlayerGroupLockStateStore} class:disabled={$currentPlayerGroupLockStateStore}
on:click={lockClick} on:click={lockClick}
> >
@ -113,26 +106,26 @@
<div <div
class="btn-monitor" class="btn-monitor"
on:click={screenSharingClick} on:click={screenSharingClick}
class:hide={!$screenSharingAvailableStore || isSilent} class:hide={!$screenSharingAvailableStore || $silentStore}
class:enabled={$requestedScreenSharingState} class:enabled={$requestedScreenSharingState}
> >
{#if $requestedScreenSharingState && !isSilent} {#if $requestedScreenSharingState && !$silentStore}
<img class="noselect" src={monitorImg} alt="Start screen sharing" /> <img class="noselect" src={monitorImg} alt="Start screen sharing" />
{:else} {:else}
<img class="noselect" src={monitorCloseImg} alt="Stop screen sharing" /> <img class="noselect" src={monitorCloseImg} alt="Stop screen sharing" />
{/if} {/if}
</div> </div>
<div class="btn-video" on:click={cameraClick} class:disabled={!$requestedCameraState || isSilent}> <div class="btn-video" on:click={cameraClick} class:disabled={!$requestedCameraState || $silentStore}>
{#if $requestedCameraState && !isSilent} {#if $requestedCameraState && !$silentStore}
<img class="noselect" src={cinemaImg} alt="Turn on webcam" /> <img class="noselect" src={cinemaImg} alt="Turn on webcam" />
{:else} {:else}
<img class="noselect" src={cinemaCloseImg} alt="Turn off webcam" /> <img class="noselect" src={cinemaCloseImg} alt="Turn off webcam" />
{/if} {/if}
</div> </div>
<div class="btn-micro" on:click={microphoneClick} class:disabled={!$requestedMicrophoneState || isSilent}> <div class="btn-micro" on:click={microphoneClick} class:disabled={!$requestedMicrophoneState || $silentStore}>
{#if $requestedMicrophoneState && !isSilent} {#if $requestedMicrophoneState && !$silentStore}
<img class="noselect" src={microphoneImg} alt="Turn on microphone" /> <img class="noselect" src={microphoneImg} alt="Turn on microphone" />
{:else} {:else}
<img class="noselect" src={microphoneCloseImg} alt="Turn off microphone" /> <img class="noselect" src={microphoneCloseImg} alt="Turn off microphone" />

View File

@ -20,11 +20,6 @@
unsubscribeLocalStreamStore(); unsubscribeLocalStreamStore();
}); });
let isSilent: boolean;
const unsubscribeIsSilent = silentStore.subscribe((silent) => {
isSilent = silent;
});
let cameraContainer: HTMLDivElement; let cameraContainer: HTMLDivElement;
onMount(() => { onMount(() => {
@ -40,16 +35,14 @@
} }
}); });
}); });
onDestroy(unsubscribeIsSilent);
</script> </script>
<div <div
class="nes-container is-rounded my-cam-video-container" class="nes-container is-rounded my-cam-video-container"
class:hide={($localStreamStore.type !== "success" || !$obtainedMediaConstraintStore.video) && !isSilent} class:hide={($localStreamStore.type !== "success" || !$obtainedMediaConstraintStore.video) && !$silentStore}
bind:this={cameraContainer} bind:this={cameraContainer}
> >
{#if isSilent} {#if $silentStore}
<div class="is-silent">{$LL.camera.my.silentZone()}</div> <div class="is-silent">{$LL.camera.my.silentZone()}</div>
{:else if $localStreamStore.type === "success" && $localStreamStore.stream} {:else if $localStreamStore.type === "success" && $localStreamStore.stream}
<video class="my-cam-video" use:srcObject={stream} autoplay muted playsinline /> <video class="my-cam-video" use:srcObject={stream} autoplay muted playsinline />