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

72 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-04-20 04:34:43 +08:00
import { makeVar, useReactiveVar } from '@apollo/client';
2024-06-08 04:41:36 +08:00
import type { ConnectingStream, Stream } from './types';
2024-04-20 04:34:43 +08:00
interface State {
isConnecting: boolean;
isConnected: boolean;
currentVideoPageIndex: number;
numberOfPages: number;
pageSize: number;
userId: string | null;
}
const videoState = makeVar<State>({
2024-04-20 04:34:43 +08:00
isConnecting: false,
isConnected: false,
currentVideoPageIndex: 0,
numberOfPages: 0,
pageSize: 0,
userId: null,
});
const useVideoState = () => useReactiveVar(videoState);
const setVideoState = (state: Partial<State>) => {
videoState({
...videoState(),
...state,
});
};
2024-04-20 04:34:43 +08:00
const getVideoState = () => videoState();
const connectingStream = makeVar<ConnectingStream | null>(null);
2024-04-20 04:34:43 +08:00
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 | null) => {
2024-04-20 04:34:43 +08:00
connectingStream(stream);
};
const getConnectingStream = () => connectingStream();
2024-04-20 04:34:43 +08:00
export {
useVideoState,
setVideoState,
getVideoState,
useConnectingStream,
getConnectingStream,
2024-04-20 04:34:43 +08:00
setConnectingStream,
};
export default {
useVideoState,
setVideoState,
getVideoState,
useConnectingStream,
getConnectingStream,
2024-04-20 04:34:43 +08:00
setConnectingStream,
};