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();
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
export type ConnectingStream = {
|
2024-04-20 04:34:43 +08:00
|
|
|
stream: string;
|
|
|
|
name: string;
|
|
|
|
userId: string;
|
2024-05-02 03:48:12 +08:00
|
|
|
type: 'connecting';
|
2024-04-20 04:34:43 +08:00
|
|
|
} | null;
|
|
|
|
|
|
|
|
const connectingStream = makeVar<ConnectingStream>(null);
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
const useConnectingStream = (streams?: Stream[]) => {
|
2024-04-20 04:34:43 +08:00
|
|
|
const connecting = useReactiveVar(connectingStream);
|
|
|
|
|
|
|
|
if (!connecting) return null;
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
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;
|
2024-05-02 03:48:12 +08:00
|
|
|
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,
|
|
|
|
};
|