bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/video-provider/container.tsx

146 lines
4.2 KiB
TypeScript
Raw Normal View History

2024-04-20 04:34:43 +08:00
import React from 'react';
import { useMutation } from '@apollo/client';
import useMeeting from '/imports/ui/core/hooks/useMeeting';
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
import {
useCurrentVideoPageIndex,
useExitVideo,
useInfo,
2024-04-20 04:34:43 +08:00
useIsUserLocked,
useLockUser,
2024-06-14 22:35:53 +08:00
useMyRole,
useStopVideo,
2024-04-20 04:34:43 +08:00
useVideoStreams,
} from './hooks';
import { CAMERA_BROADCAST_START } from './mutations';
2024-04-20 04:34:43 +08:00
import VideoProvider from './component';
import VideoService from './service';
import { Output } from '/imports/ui/components/layout/layoutTypes';
import { VideoItem } from './types';
import { debounce } from '/imports/utils/debounce';
import WebRtcPeer from '/imports/ui/services/webrtc-base/peer';
import useSettings from '/imports/ui/services/settings/hooks/useSettings';
import { SETTINGS } from '/imports/ui/services/settings/enums';
2024-04-20 04:34:43 +08:00
interface VideoProviderContainerProps {
focusedId: string;
swapLayout: boolean;
isGridEnabled: boolean;
cameraDock: Output['cameraDock'];
handleVideoFocus:(id: string) => void;
2024-04-20 04:34:43 +08:00
}
const VideoProviderContainer: React.FC<VideoProviderContainerProps> = (props) => {
2024-04-20 04:34:43 +08:00
const {
cameraDock,
focusedId,
handleVideoFocus,
isGridEnabled,
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 {
debounceTime: CAMERA_QUALITY_THR_DEBOUNCE = 2500,
} = window.meetingClientSettings.public.kurento.cameraQualityThresholds;
const applyCameraProfile = debounce(
VideoService.applyCameraProfile,
CAMERA_QUALITY_THR_DEBOUNCE,
{ leading: false, trailing: true },
);
2024-04-20 04:34:43 +08:00
const { data: currentMeeting } = useMeeting((m) => ({
usersPolicies: m.usersPolicies,
}));
const { data: currentUser } = useCurrentUser((user) => ({
locked: user.locked,
userId: user.userId,
2024-04-20 04:34:43 +08:00
}));
const currentUserId = currentUser?.userId ?? '';
// @ts-ignore Untyped object
const { paginationEnabled } = useSettings(SETTINGS.APPLICATION);
// @ts-ignore Untyped object
const { viewParticipantsWebcams } = useSettings(SETTINGS.DATA_SAVING);
// TODO: Remove/Replace this
const isMeteorConnected = true;
2024-04-20 04:34:43 +08:00
const {
streams,
gridUsers,
totalNumberOfStreams,
} = useVideoStreams(isGridEnabled, paginationEnabled, viewParticipantsWebcams);
2024-04-20 04:34:43 +08:00
let usersVideo: VideoItem[] = streams;
2024-04-20 04:34:43 +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
) {
usersVideo = usersVideo.filter(
2024-06-08 04:41:36 +08:00
(uv) => (
(
(uv.type === 'stream' && uv.user.isModerator)
|| (uv.type === 'grid' && uv.isModerator)
)
|| uv.userId === currentUserId
),
);
2024-04-20 04:34:43 +08:00
}
const isUserLocked = useIsUserLocked();
const currentVideoPageIndex = useCurrentVideoPageIndex();
const exitVideo = useExitVideo();
const lockUser = useLockUser();
const stopVideo = useStopVideo();
const info = useInfo();
2024-06-14 22:35:53 +08:00
const myRole = useMyRole();
if (!usersVideo.length && !isGridEnabled) return null;
2024-04-20 04:34:43 +08:00
return (
<VideoProvider
cameraDock={cameraDock}
focusedId={focusedId}
handleVideoFocus={handleVideoFocus}
isGridEnabled={isGridEnabled}
isMeteorConnected={isMeteorConnected}
swapLayout={swapLayout}
currentUserId={currentUserId}
paginationEnabled={paginationEnabled}
viewParticipantsWebcams={viewParticipantsWebcams}
totalNumberOfStreams={totalNumberOfStreams}
isUserLocked={isUserLocked}
currentVideoPageIndex={currentVideoPageIndex}
streams={usersVideo}
info={info}
playStart={playStart}
exitVideo={exitVideo}
lockUser={lockUser}
stopVideo={stopVideo}
applyCameraProfile={applyCameraProfile as (peer: WebRtcPeer, profileId: string) => void}
2024-06-14 22:35:53 +08:00
myRole={myRole}
/>
2024-04-20 04:34:43 +08:00
);
};
export default VideoProviderContainer;