FIX: fixed a circular dependancy in stores by rewriting createPeerStore() and createScreenSharingPeerStore()
This commit is contained in:
parent
6cb0f14e5a
commit
ba5fa06306
9 changed files with 63 additions and 114 deletions
|
@ -1,14 +1,12 @@
|
|||
import { writable } from "svelte/store";
|
||||
import type { RemotePeer, SimplePeer } from "../WebRtc/SimplePeer";
|
||||
import { VideoPeer } from "../WebRtc/VideoPeer";
|
||||
import { ScreenSharingPeer } from "../WebRtc/ScreenSharingPeer";
|
||||
import { get, writable } from "svelte/store";
|
||||
import type { Streamable } from "./StreamableCollectionStore";
|
||||
import { peerStore } from "./PeerStore";
|
||||
|
||||
/**
|
||||
* A store that contains the peer / media that has currently the "importance" focus.
|
||||
*/
|
||||
function createVideoFocusStore() {
|
||||
const { subscribe, set, update } = writable<Streamable | null>(null);
|
||||
const { subscribe, set } = writable<Streamable | null>(null);
|
||||
|
||||
let focusedMedia: Streamable | null = null;
|
||||
|
||||
|
@ -23,27 +21,17 @@ function createVideoFocusStore() {
|
|||
set(null);
|
||||
},
|
||||
toggleFocus: (media: Streamable) => {
|
||||
if (media !== focusedMedia) {
|
||||
focusedMedia = media;
|
||||
} else {
|
||||
focusedMedia = null;
|
||||
}
|
||||
focusedMedia = media !== focusedMedia ? media : null;
|
||||
set(focusedMedia);
|
||||
},
|
||||
connectToSimplePeer: (simplePeer: SimplePeer) => {
|
||||
simplePeer.registerPeerConnectionListener({
|
||||
onConnect(peer: RemotePeer) {},
|
||||
onDisconnect(userId: number) {
|
||||
if (
|
||||
(focusedMedia instanceof VideoPeer || focusedMedia instanceof ScreenSharingPeer) &&
|
||||
focusedMedia.userId === userId
|
||||
) {
|
||||
set(null);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const videoFocusStore = createVideoFocusStore();
|
||||
|
||||
peerStore.subscribe((peers) => {
|
||||
const focusedMedia: Streamable | null = get(videoFocusStore);
|
||||
if (focusedMedia && focusedMedia.userId !== undefined && !peers.get(focusedMedia.userId)) {
|
||||
videoFocusStore.removeFocus();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue