2024-04-20 04:34:43 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
|
|
|
import { useMutation } from '@apollo/client';
|
|
|
|
import useMeeting from '/imports/ui/core/hooks/useMeeting';
|
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
|
|
|
|
import Settings from '/imports/ui/services/settings';
|
|
|
|
import {
|
|
|
|
useCurrentVideoPageIndex,
|
|
|
|
useExitVideo,
|
2024-05-02 03:48:12 +08:00
|
|
|
useInfo,
|
2024-04-20 04:34:43 +08:00
|
|
|
useIsUserLocked,
|
2024-05-02 03:48:12 +08:00
|
|
|
useLockUser,
|
|
|
|
useStopVideo,
|
2024-04-20 04:34:43 +08:00
|
|
|
useVideoStreams,
|
|
|
|
} from './hooks';
|
2024-05-02 03:30:29 +08:00
|
|
|
import { CAMERA_BROADCAST_START } from './mutations';
|
2024-04-20 04:34:43 +08:00
|
|
|
import VideoProvider from './component';
|
|
|
|
import VideoService from './service';
|
2024-05-02 03:48:12 +08:00
|
|
|
import { Output } from '/imports/ui/components/layout/layoutTypes';
|
|
|
|
import { VideoItem } from './types';
|
2024-04-20 04:34:43 +08:00
|
|
|
|
|
|
|
interface VideoProviderContainerGraphqlProps {
|
2024-05-02 03:48:12 +08:00
|
|
|
currentUserId: string;
|
|
|
|
focusedId: string;
|
|
|
|
swapLayout: boolean;
|
|
|
|
isGridEnabled: boolean;
|
2024-04-20 04:34:43 +08:00
|
|
|
paginationEnabled: boolean;
|
2024-05-02 03:48:12 +08:00
|
|
|
isMeteorConnected: boolean;
|
2024-04-20 04:34:43 +08:00
|
|
|
viewParticipantsWebcams: boolean;
|
2024-05-02 03:48:12 +08:00
|
|
|
cameraDock: Output['cameraDock'];
|
|
|
|
handleVideoFocus:(id: string) => void;
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
const VideoProviderContainerGraphql: React.FC<VideoProviderContainerGraphqlProps> = (props) => {
|
2024-04-20 04:34:43 +08:00
|
|
|
const {
|
2024-05-02 03:48:12 +08:00
|
|
|
currentUserId,
|
2024-04-20 04:34:43 +08:00
|
|
|
paginationEnabled,
|
|
|
|
viewParticipantsWebcams,
|
2024-05-02 03:48:12 +08:00
|
|
|
cameraDock,
|
|
|
|
focusedId,
|
|
|
|
handleVideoFocus,
|
|
|
|
isGridEnabled,
|
|
|
|
isMeteorConnected,
|
|
|
|
swapLayout,
|
2024-04-20 04:34:43 +08:00
|
|
|
} = props;
|
|
|
|
const [cameraBroadcastStart] = useMutation(CAMERA_BROADCAST_START);
|
|
|
|
|
|
|
|
const sendUserShareWebcam = (cameraId: string) => {
|
|
|
|
return cameraBroadcastStart({ variables: { cameraId } });
|
|
|
|
};
|
|
|
|
|
|
|
|
const playStart = (cameraId: string) => {
|
|
|
|
if (VideoService.isLocalStream(cameraId)) {
|
|
|
|
sendUserShareWebcam(cameraId).then(() => {
|
2024-05-07 04:05:37 +08:00
|
|
|
VideoService.joinedVideo();
|
2024-04-20 04:34:43 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const { data: currentMeeting } = useMeeting((m) => ({
|
|
|
|
usersPolicies: m.usersPolicies,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const { data: currentUser } = useCurrentUser((user) => ({
|
|
|
|
locked: user.locked,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const {
|
|
|
|
streams,
|
|
|
|
gridUsers,
|
|
|
|
totalNumberOfStreams,
|
|
|
|
users,
|
2024-05-02 03:48:12 +08:00
|
|
|
} = useVideoStreams(isGridEnabled, paginationEnabled, viewParticipantsWebcams);
|
2024-04-20 04:34:43 +08:00
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
let usersVideo: VideoItem[] = streams;
|
2024-04-20 04:34:43 +08:00
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
if (gridUsers.length > 0 && isGridEnabled) {
|
2024-04-20 04:34:43 +08:00
|
|
|
usersVideo = usersVideo.concat(gridUsers);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
currentMeeting?.usersPolicies?.webcamsOnlyForModerator
|
|
|
|
&& currentUser?.locked
|
|
|
|
) {
|
2024-05-02 01:14:10 +08:00
|
|
|
usersVideo = usersVideo.filter(
|
|
|
|
(uv) => (uv.type !== 'connecting' && uv.isModerator) || uv.userId === currentUserId,
|
|
|
|
);
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const isUserLocked = useIsUserLocked();
|
|
|
|
const currentVideoPageIndex = useCurrentVideoPageIndex();
|
|
|
|
const exitVideo = useExitVideo();
|
2024-05-02 03:48:12 +08:00
|
|
|
const lockUser = useLockUser();
|
|
|
|
const stopVideo = useStopVideo();
|
|
|
|
const info = useInfo();
|
|
|
|
|
|
|
|
if (!usersVideo.length && !isGridEnabled) return null;
|
2024-04-20 04:34:43 +08:00
|
|
|
|
|
|
|
return (
|
2024-05-02 03:48:12 +08:00
|
|
|
<VideoProvider
|
|
|
|
cameraDock={cameraDock}
|
|
|
|
focusedId={focusedId}
|
|
|
|
handleVideoFocus={handleVideoFocus}
|
2024-05-02 03:30:29 +08:00
|
|
|
isGridEnabled={isGridEnabled}
|
2024-05-02 03:48:12 +08:00
|
|
|
isMeteorConnected={isMeteorConnected}
|
|
|
|
swapLayout={swapLayout}
|
|
|
|
currentUserId={currentUserId}
|
|
|
|
paginationEnabled={paginationEnabled}
|
|
|
|
viewParticipantsWebcams={viewParticipantsWebcams}
|
|
|
|
totalNumberOfStreams={totalNumberOfStreams}
|
|
|
|
isUserLocked={isUserLocked}
|
|
|
|
currentVideoPageIndex={currentVideoPageIndex}
|
|
|
|
streams={usersVideo}
|
|
|
|
users={users}
|
|
|
|
info={info}
|
|
|
|
playStart={playStart}
|
|
|
|
exitVideo={exitVideo}
|
|
|
|
lockUser={lockUser}
|
|
|
|
stopVideo={stopVideo}
|
|
|
|
/>
|
2024-04-20 04:34:43 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
type TrackerData = {
|
|
|
|
currentUserId: string;
|
|
|
|
isMeteorConnected: boolean;
|
|
|
|
paginationEnabled: boolean;
|
|
|
|
viewParticipantsWebcams: boolean;
|
|
|
|
};
|
2024-04-20 04:34:43 +08:00
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
type TrackerProps = {
|
|
|
|
swapLayout: boolean;
|
|
|
|
cameraDock: Output['cameraDock'];
|
|
|
|
focusedId: string;
|
|
|
|
handleVideoFocus:(id: string) => void;
|
|
|
|
isGridEnabled: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withTracker<TrackerData, TrackerProps>(() => {
|
|
|
|
const currentUserId = Auth.userID ?? '';
|
|
|
|
const isMeteorConnected = Meteor.status().connected;
|
|
|
|
// @ts-expect-error -> Untyped object.
|
|
|
|
const { paginationEnabled } = Settings.application;
|
|
|
|
// @ts-expect-error -> Untyped object.
|
|
|
|
const { viewParticipantsWebcams } = Settings.dataSaving;
|
2024-04-20 04:34:43 +08:00
|
|
|
return {
|
2024-05-02 03:48:12 +08:00
|
|
|
currentUserId,
|
2024-04-20 04:34:43 +08:00
|
|
|
isMeteorConnected,
|
2024-05-02 03:48:12 +08:00
|
|
|
paginationEnabled,
|
|
|
|
viewParticipantsWebcams,
|
2024-04-20 04:34:43 +08:00
|
|
|
};
|
|
|
|
})(VideoProviderContainerGraphql);
|