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

75 lines
2.1 KiB
React
Raw Normal View History

2020-06-09 11:09:46 +08:00
import React from 'react';
2018-02-17 03:18:53 +08:00
import { withTracker } from 'meteor/react-meteor-data';
2024-01-26 21:29:52 +08:00
import { useMutation } from '@apollo/client';
2018-02-17 03:18:53 +08:00
import VideoProvider from './component';
import VideoService from './service';
2023-08-09 00:05:54 +08:00
import { sortVideoStreams } from '/imports/ui/components/video-provider/stream-sorting';
2024-01-27 00:21:58 +08:00
import { CAMERA_BROADCAST_START, CAMERA_BROADCAST_STOP } from './mutations';
2023-08-09 00:05:54 +08:00
const { defaultSorting: DEFAULT_SORTING } = window.meetingClientSettings.public.kurento.cameraSortingModes;
2018-02-17 03:18:53 +08:00
2018-12-18 06:19:26 +08:00
const VideoProviderContainer = ({ children, ...props }) => {
2023-05-12 04:20:26 +08:00
const { streams, isGridEnabled } = props;
2024-01-26 21:29:52 +08:00
const [cameraBroadcastStart] = useMutation(CAMERA_BROADCAST_START);
2024-01-27 00:21:58 +08:00
const [cameraBroadcastStop] = useMutation(CAMERA_BROADCAST_STOP);
2024-01-26 21:29:52 +08:00
const sendUserShareWebcam = (cameraId) => {
cameraBroadcastStart({ variables: { cameraId } });
};
2024-01-27 00:21:58 +08:00
const sendUserUnshareWebcam = (cameraId) => {
cameraBroadcastStop({ variables: { cameraId } });
};
2024-01-26 21:29:52 +08:00
const playStart = (cameraId) => {
if (VideoService.isLocalStream(cameraId)) {
sendUserShareWebcam(cameraId);
VideoService.joinedVideo();
}
};
2024-01-27 00:21:58 +08:00
return (
!streams.length && !isGridEnabled
? null
: (
<VideoProvider
{...props}
playStart={playStart}
sendUserUnshareWebcam={sendUserUnshareWebcam}
>
{children}
</VideoProvider>
)
);
2018-12-18 06:19:26 +08:00
};
2018-02-17 03:18:53 +08:00
export default withTracker(({ swapLayout, ...rest }) => {
// getVideoStreams returns a dictionary consisting of:
// {
// streams: array of mapped streams
// totalNumberOfStreams: total number of shared streams in the server
// }
const {
streams,
2023-08-09 00:05:54 +08:00
gridUsers,
totalNumberOfStreams,
} = VideoService.getVideoStreams();
2023-08-09 00:05:54 +08:00
let usersVideo = streams;
if(gridUsers.length > 0) {
const items = usersVideo.concat(gridUsers);
usersVideo = sortVideoStreams(items, DEFAULT_SORTING);
}
return {
swapLayout,
2023-08-09 00:05:54 +08:00
streams: usersVideo,
totalNumberOfStreams,
isUserLocked: VideoService.isUserLocked(),
currentVideoPageIndex: VideoService.getCurrentVideoPageIndex(),
isMeteorConnected: Meteor.status().connected,
...rest,
};
})(VideoProviderContainer);