2021-06-15 17:30:28 +02:00
|
|
|
import {derived, get, Readable, writable} from "svelte/store";
|
2021-06-11 11:29:36 +02:00
|
|
|
import {ScreenSharingLocalMedia, screenSharingLocalMedia} from "./ScreenSharingStore";
|
|
|
|
import { peerStore, screenSharingStreamStore} from "./PeerStore";
|
|
|
|
import type {RemotePeer} from "../WebRtc/SimplePeer";
|
2021-06-15 17:30:28 +02:00
|
|
|
import {LayoutMode} from "../WebRtc/LayoutManager";
|
2021-06-11 11:29:36 +02:00
|
|
|
|
|
|
|
export type DisplayableMedia = RemotePeer | ScreenSharingLocalMedia;
|
|
|
|
|
2021-06-15 17:30:28 +02:00
|
|
|
export const layoutModeStore = writable<LayoutMode>(LayoutMode.Presentation);
|
|
|
|
|
2021-06-11 11:29:36 +02:00
|
|
|
/**
|
|
|
|
* A store that contains the layout of the streams
|
|
|
|
*/
|
2021-06-15 17:30:28 +02:00
|
|
|
function createLayoutStore(): Readable<Map<string, DisplayableMedia>> {
|
2021-06-11 11:29:36 +02:00
|
|
|
|
|
|
|
return derived([
|
|
|
|
screenSharingStreamStore,
|
|
|
|
peerStore,
|
|
|
|
screenSharingLocalMedia,
|
|
|
|
], ([
|
|
|
|
$screenSharingStreamStore,
|
|
|
|
$peerStore,
|
|
|
|
$screenSharingLocalMedia,
|
|
|
|
], set) => {
|
|
|
|
|
2021-06-15 14:45:01 +02:00
|
|
|
const peers = new Map<string, DisplayableMedia>();
|
2021-06-11 11:29:36 +02:00
|
|
|
|
|
|
|
const addPeer = (peer: DisplayableMedia) => {
|
2021-06-15 14:45:01 +02:00
|
|
|
peers.set(peer.uniqueId, peer);
|
2021-06-11 11:29:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$screenSharingStreamStore.forEach(addPeer);
|
|
|
|
$peerStore.forEach(addPeer);
|
2021-06-15 14:45:01 +02:00
|
|
|
|
2021-06-11 11:29:36 +02:00
|
|
|
if ($screenSharingLocalMedia?.stream) {
|
|
|
|
addPeer($screenSharingLocalMedia);
|
|
|
|
}
|
|
|
|
|
|
|
|
set(peers);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export const layoutStore = createLayoutStore();
|