diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 1ea5e461..9a46991a 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -27,7 +27,6 @@ import { import { TextureError } from "../../Exception/TextureError"; import type { UserMovedMessage } from "../../Messages/generated/messages_pb"; import { ProtobufClientUtils } from "../../Network/ProtobufClientUtils"; -import { peerStore } from "../../Stores/PeerStore"; import { touchScreenManager } from "../../Touch/TouchScreenManager"; import { urlManager } from "../../Url/UrlManager"; import { audioManager } from "../../WebRtc/AudioManager"; @@ -94,7 +93,7 @@ import type { HasPlayerMovedEvent } from '../../Api/Events/HasPlayerMovedEvent'; import AnimatedTiles from "phaser-animated-tiles"; import {soundManager} from "./SoundManager"; -import {screenSharingPeerStore} from "../../Stores/PeerStore"; +import {peerStore, screenSharingPeerStore} from "../../Stores/PeerStore"; import {videoFocusStore} from "../../Stores/VideoFocusStore"; import {biggestAvailableAreaStore} from "../../Stores/BiggestAvailableAreaStore"; diff --git a/front/src/Stores/MediaStore.ts b/front/src/Stores/MediaStore.ts index b2cd9f42..6cb9f75c 100644 --- a/front/src/Stores/MediaStore.ts +++ b/front/src/Stores/MediaStore.ts @@ -1,5 +1,4 @@ import {derived, get, Readable, readable, writable, Writable} from "svelte/store"; -import {peerStore} from "./PeerStore"; import {localUserStore} from "../Connexion/LocalUserStore"; import {userMovingStore} from "./GameStore"; import {HtmlUtils} from "../WebRtc/HtmlUtils"; @@ -8,6 +7,8 @@ import {errorStore} from "./ErrorStore"; import {isIOS} from "../WebRtc/DeviceUtils"; import {WebviewOnOldIOS} from "./Errors/WebviewOnOldIOS"; import {gameOverlayVisibilityStore} from "./GameOverlayStoreVisibility"; +import {peerStore} from "./PeerStore"; +import {privacyShutdownStore} from "./PrivacyShutdownStore"; /** * A store that contains the camera state requested by the user (on or off). @@ -35,21 +36,6 @@ function createRequestedMicrophoneState() { }; } -/** - * A store containing whether the current page is visible or not. - */ -export const visibilityStore = readable(document.visibilityState === 'visible', function start(set) { - const onVisibilityChange = () => { - set(document.visibilityState === 'visible'); - }; - - document.addEventListener('visibilitychange', onVisibilityChange); - - return function stop() { - document.removeEventListener('visibilitychange', onVisibilityChange); - }; -}); - /** * A store that contains whether the EnableCameraScene is shown or not. */ @@ -67,41 +53,6 @@ export const requestedCameraState = createRequestedCameraState(); export const requestedMicrophoneState = createRequestedMicrophoneState(); export const enableCameraSceneVisibilityStore = createEnableCameraSceneVisibilityStore(); -/** - * A store that contains "true" if the webcam should be stopped for privacy reasons - i.e. if the the user left the the page while not in a discussion. - */ -function createPrivacyShutdownStore() { - let privacyEnabled = false; - - const { subscribe, set, update } = writable(privacyEnabled); - - visibilityStore.subscribe((isVisible) => { - if (!isVisible && get(peerStore).size === 0) { - privacyEnabled = true; - set(true); - } - if (isVisible) { - privacyEnabled = false; - set(false); - } - }); - - peerStore.subscribe((peers) => { - if (peers.size === 0 && get(visibilityStore) === false) { - privacyEnabled = true; - set(true); - } - }); - - - return { - subscribe, - }; -} - -export const privacyShutdownStore = createPrivacyShutdownStore(); - - /** * A store containing whether the webcam was enabled in the last 10 seconds */ diff --git a/front/src/Stores/PeerStore.ts b/front/src/Stores/PeerStore.ts index b3690595..725c8940 100644 --- a/front/src/Stores/PeerStore.ts +++ b/front/src/Stores/PeerStore.ts @@ -1,4 +1,4 @@ -import {derived, get, readable, writable} from "svelte/store"; +import {readable, writable} from "svelte/store"; import type {RemotePeer, SimplePeer} from "../WebRtc/SimplePeer"; import {VideoPeer} from "../WebRtc/VideoPeer"; import {ScreenSharingPeer} from "../WebRtc/ScreenSharingPeer"; diff --git a/front/src/Stores/PrivacyShutdownStore.ts b/front/src/Stores/PrivacyShutdownStore.ts new file mode 100644 index 00000000..cd9cb1b9 --- /dev/null +++ b/front/src/Stores/PrivacyShutdownStore.ts @@ -0,0 +1,37 @@ +import {get, writable} from "svelte/store"; +import {peerStore} from "./PeerStore"; +import {visibilityStore} from "./VisibilityStore"; + +/** + * A store that contains "true" if the webcam should be stopped for privacy reasons - i.e. if the the user left the the page while not in a discussion. + */ +function createPrivacyShutdownStore() { + let privacyEnabled = false; + + const { subscribe, set, update } = writable(privacyEnabled); + + visibilityStore.subscribe((isVisible) => { + if (!isVisible && get(peerStore).size === 0) { + privacyEnabled = true; + set(true); + } + if (isVisible) { + privacyEnabled = false; + set(false); + } + }); + + peerStore.subscribe((peers) => { + if (peers.size === 0 && get(visibilityStore) === false) { + privacyEnabled = true; + set(true); + } + }); + + + return { + subscribe, + }; +} + +export const privacyShutdownStore = createPrivacyShutdownStore(); diff --git a/front/src/Stores/VisibilityStore.ts b/front/src/Stores/VisibilityStore.ts new file mode 100644 index 00000000..4a13ffae --- /dev/null +++ b/front/src/Stores/VisibilityStore.ts @@ -0,0 +1,16 @@ +import {readable} from "svelte/store"; + +/** + * A store containing whether the current page is visible or not. + */ +export const visibilityStore = readable(document.visibilityState === 'visible', function start(set) { + const onVisibilityChange = () => { + set(document.visibilityState === 'visible'); + }; + + document.addEventListener('visibilitychange', onVisibilityChange); + + return function stop() { + document.removeEventListener('visibilitychange', onVisibilityChange); + }; +}); diff --git a/front/src/WebRtc/VideoPeer.ts b/front/src/WebRtc/VideoPeer.ts index 0840d6ff..5b5212b9 100644 --- a/front/src/WebRtc/VideoPeer.ts +++ b/front/src/WebRtc/VideoPeer.ts @@ -7,7 +7,6 @@ import type {Subscription} from "rxjs"; import type {UserSimplePeerInterface} from "./SimplePeer"; import {get, readable, Readable} from "svelte/store"; import {obtainedMediaConstraintStore} from "../Stores/MediaStore"; -import {DivImportance} from "./LayoutManager"; import {discussionManager} from "./DiscussionManager"; const Peer: SimplePeerNamespace.SimplePeer = require('simple-peer');