bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/video-provider/video-provider-graphql/state.ts

80 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-04-20 04:34:43 +08:00
import { makeVar, useReactiveVar } from '@apollo/client';
import createUseLocalState from '/imports/ui/core/local-states/createUseLocalState';
const [useVideoState, setVideoState, videoState] = createUseLocalState({
isConnecting: false,
isConnected: false,
currentVideoPageIndex: 0,
numberOfPages: 0,
pageSize: 0,
userId: null,
});
const getVideoState = () => videoState();
export type ConnectingStream = {
2024-04-20 04:34:43 +08:00
stream: string;
name: string;
userId: string;
type: 'connecting';
2024-04-20 04:34:43 +08:00
} | null;
const connectingStream = makeVar<ConnectingStream>(null);
const useConnectingStream = (streams?: Stream[]) => {
2024-04-20 04:34:43 +08:00
const connecting = useReactiveVar(connectingStream);
if (!connecting) return null;
const hasStream = streams && streams.find((s) => s.stream === connecting.stream);
2024-04-20 04:34:43 +08:00
if (hasStream) {
return null;
}
return connecting;
};
const setConnectingStream = (stream: ConnectingStream) => {
connectingStream(stream);
};
2024-04-26 01:44:41 +08:00
export type Stream = {
2024-04-20 04:34:43 +08:00
stream: string;
deviceId: string;
userId: string;
name: string;
sortName: string;
pin: boolean;
floor: boolean;
lastFloorTime: string;
isModerator: boolean;
type: 'stream';
2024-04-20 04:34:43 +08:00
}
const streams = makeVar<Stream[]>([]);
const setStreams = (vs: Stream[]) => {
streams(vs);
};
export {
useVideoState,
setVideoState,
getVideoState,
useConnectingStream,
setConnectingStream,
setStreams,
streams,
};
export default {
useVideoState,
setVideoState,
getVideoState,
useConnectingStream,
setConnectingStream,
setStreams,
streams,
};