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

69 lines
1.4 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';
2024-06-08 04:41:36 +08:00
import type { ConnectingStream, Stream } from './types';
2024-04-20 04:34:43 +08:00
const [useVideoState, setVideoState, videoState] = createUseLocalState({
isConnecting: false,
isConnected: false,
currentVideoPageIndex: 0,
numberOfPages: 0,
pageSize: 0,
userId: null,
});
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
const streams = makeVar<Stream[]>([]);
const setStreams = (vs: Stream[]) => {
streams(vs);
};
const getStreams = () => streams();
2024-04-20 04:34:43 +08:00
export {
useVideoState,
setVideoState,
getVideoState,
useConnectingStream,
getConnectingStream,
2024-04-20 04:34:43 +08:00
setConnectingStream,
setStreams,
getStreams,
2024-04-20 04:34:43 +08:00
streams,
};
export default {
useVideoState,
setVideoState,
getVideoState,
useConnectingStream,
getConnectingStream,
2024-04-20 04:34:43 +08:00
setConnectingStream,
setStreams,
getStreams,
2024-04-20 04:34:43 +08:00
streams,
};