peerStore loading order caused issues. Fixed in GameScene (+ extracted a few stores in their files)

This commit is contained in:
David Négrier
2021-06-24 11:54:09 +02:00
parent 6ed8ce9af1
commit 2f282e3469
6 changed files with 57 additions and 55 deletions
+37
View File
@@ -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();