Switching MediaManager to using a Svelte store
This allows cleaner and more expressive code, especially regarding whether the webcam should be on or off.
This commit is contained in:
parent
4f4d2532b7
commit
28d78a7988
7 changed files with 458 additions and 10 deletions
32
front/src/Stores/PeerStore.ts
Normal file
32
front/src/Stores/PeerStore.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { derived, writable, Writable } from "svelte/store";
|
||||
import type {UserSimplePeerInterface} from "../WebRtc/SimplePeer";
|
||||
import type {SimplePeer} from "../WebRtc/SimplePeer";
|
||||
|
||||
/**
|
||||
* A store that contains the camera state requested by the user (on or off).
|
||||
*/
|
||||
function createPeerStore() {
|
||||
let users = new Map<number, UserSimplePeerInterface>();
|
||||
|
||||
const { subscribe, set, update } = writable(users);
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
connectToSimplePeer: (simplePeer: SimplePeer) => {
|
||||
users = new Map<number, UserSimplePeerInterface>();
|
||||
set(users);
|
||||
simplePeer.registerPeerConnectionListener({
|
||||
onConnect(user: UserSimplePeerInterface) {
|
||||
users.set(user.userId, user);
|
||||
set(users);
|
||||
},
|
||||
onDisconnect(userId: number) {
|
||||
users.delete(userId);
|
||||
set(users);
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const peerStore = createPeerStore();
|
Loading…
Add table
Add a link
Reference in a new issue