2021-06-15 14:45:01 +02:00
|
|
|
import {writable} from "svelte/store";
|
|
|
|
import type {RemotePeer, SimplePeer} from "../WebRtc/SimplePeer";
|
|
|
|
import {VideoPeer} from "../WebRtc/VideoPeer";
|
|
|
|
import {ScreenSharingPeer} from "../WebRtc/ScreenSharingPeer";
|
2021-06-21 14:43:10 +02:00
|
|
|
import type {Streamable} from "./StreamableCollectionStore";
|
2021-06-15 14:45:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A store that contains the peer / media that has currently the "importance" focus.
|
|
|
|
*/
|
|
|
|
function createVideoFocusStore() {
|
2021-06-21 14:43:10 +02:00
|
|
|
const { subscribe, set, update } = writable<Streamable | null>(null);
|
2021-06-15 14:45:01 +02:00
|
|
|
|
2021-06-21 14:43:10 +02:00
|
|
|
let focusedMedia: Streamable | null = null;
|
2021-06-15 14:45:01 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
subscribe,
|
2021-06-21 14:43:10 +02:00
|
|
|
focus: (media: Streamable) => {
|
2021-06-15 14:45:01 +02:00
|
|
|
focusedMedia = media;
|
|
|
|
set(media);
|
|
|
|
},
|
|
|
|
removeFocus: () => {
|
|
|
|
focusedMedia = null;
|
|
|
|
set(null);
|
|
|
|
},
|
2021-06-21 14:43:10 +02:00
|
|
|
toggleFocus: (media: Streamable) => {
|
2021-06-15 14:45:01 +02:00
|
|
|
if (media !== focusedMedia) {
|
|
|
|
focusedMedia = media;
|
|
|
|
} else {
|
|
|
|
focusedMedia = 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();
|