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-06-04 21:40:54 +08:00
|
|
|
import { useMutation } from '@apollo/client';
|
2018-02-17 03:18:53 +08:00
|
|
|
import VideoProvider from './component';
|
2018-02-19 12:23:05 +08:00
|
|
|
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';
|
2024-02-23 23:01:53 +08:00
|
|
|
import { getVideoData, getVideoDataGrid } from './queries';
|
2024-03-12 23:22:42 +08:00
|
|
|
import useMeeting from '/imports/ui/core/hooks/useMeeting';
|
2024-03-12 21:24:37 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2024-03-12 23:22:42 +08:00
|
|
|
import useCurrentUser from '../../core/hooks/useCurrentUser';
|
2024-04-20 04:34:43 +08:00
|
|
|
import VideoProviderContainerGraphql from './video-provider-graphql/container';
|
2024-06-04 21:40:54 +08:00
|
|
|
import useDeduplicatedSubscription from '../../core/hooks/useDeduplicatedSubscription';
|
2023-08-09 00:05:54 +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
|
|
|
|
2024-04-20 04:34:43 +08:00
|
|
|
withTracker(({ swapLayout, ...rest }) => {
|
2024-02-23 23:01:53 +08:00
|
|
|
const isGridLayout = Session.get('isGridEnabled');
|
|
|
|
const graphqlQuery = isGridLayout ? getVideoDataGrid : getVideoData;
|
2024-03-12 21:24:37 +08:00
|
|
|
const currUserId = Auth.userID;
|
2024-03-12 23:22:42 +08:00
|
|
|
const { data: currentMeeting } = useMeeting((m) => ({
|
|
|
|
usersPolicies: m.usersPolicies,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const { data: currentUser } = useCurrentUser((user) => ({
|
|
|
|
locked: user.locked,
|
|
|
|
}));
|
2024-02-23 23:01:53 +08:00
|
|
|
|
|
|
|
const fetchedStreams = VideoService.fetchVideoStreams();
|
|
|
|
|
|
|
|
const variables = isGridLayout
|
|
|
|
? {}
|
|
|
|
: {
|
|
|
|
userIds: fetchedStreams.map((stream) => stream.userId) || [],
|
|
|
|
};
|
|
|
|
|
2020-08-25 02:30:24 +08:00
|
|
|
const {
|
2024-02-23 23:01:53 +08:00
|
|
|
data: videoUserSubscription,
|
2024-06-04 21:40:54 +08:00
|
|
|
} = useDeduplicatedSubscription(graphqlQuery, { variables });
|
2024-02-23 23:01:53 +08:00
|
|
|
|
|
|
|
const users = videoUserSubscription?.user || [];
|
|
|
|
|
|
|
|
let streams = [];
|
|
|
|
let gridUsers = [];
|
|
|
|
let totalNumberOfStreams = 0;
|
|
|
|
|
|
|
|
if (isGridLayout) {
|
|
|
|
streams = fetchedStreams;
|
|
|
|
gridUsers = VideoService.getGridUsers(videoUserSubscription?.user, fetchedStreams);
|
|
|
|
totalNumberOfStreams = fetchedStreams.length;
|
|
|
|
} else {
|
|
|
|
const {
|
|
|
|
streams: s,
|
|
|
|
totalNumberOfStreams: ts,
|
|
|
|
} = VideoService.getVideoStreams();
|
|
|
|
streams = s;
|
|
|
|
|
|
|
|
totalNumberOfStreams = ts;
|
|
|
|
}
|
2020-08-25 02:30:24 +08:00
|
|
|
|
2023-08-09 00:05:54 +08:00
|
|
|
let usersVideo = streams;
|
|
|
|
|
2024-05-29 21:26:11 +08:00
|
|
|
const {
|
|
|
|
defaultSorting: DEFAULT_SORTING,
|
|
|
|
} = window.meetingClientSettings.public.kurento.cameraSortingModes;
|
|
|
|
|
2024-02-23 23:01:53 +08:00
|
|
|
if (gridUsers.length > 0) {
|
2023-08-09 00:05:54 +08:00
|
|
|
const items = usersVideo.concat(gridUsers);
|
|
|
|
usersVideo = sortVideoStreams(items, DEFAULT_SORTING);
|
|
|
|
}
|
|
|
|
|
2024-03-12 23:22:42 +08:00
|
|
|
if (currentMeeting?.usersPolicies?.webcamsOnlyForModerator
|
|
|
|
&& currentUser?.locked) {
|
2024-03-12 21:24:37 +08:00
|
|
|
if (users.length > 0) {
|
|
|
|
usersVideo = usersVideo.filter((uv) => {
|
|
|
|
if (uv.userId === currUserId) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const user = users.find((u) => u.userId === uv.userId);
|
|
|
|
return user?.isModerator;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 02:30:24 +08:00
|
|
|
return {
|
2021-06-22 04:16:59 +08:00
|
|
|
swapLayout,
|
2023-08-09 00:05:54 +08:00
|
|
|
streams: usersVideo,
|
2020-08-25 02:30:24 +08:00
|
|
|
totalNumberOfStreams,
|
|
|
|
isUserLocked: VideoService.isUserLocked(),
|
|
|
|
currentVideoPageIndex: VideoService.getCurrentVideoPageIndex(),
|
2023-02-24 00:21:20 +08:00
|
|
|
isMeteorConnected: Meteor.status().connected,
|
2024-02-23 23:01:53 +08:00
|
|
|
users,
|
2021-06-22 04:16:59 +08:00
|
|
|
...rest,
|
2020-08-25 02:30:24 +08:00
|
|
|
};
|
2021-08-05 15:26:03 +08:00
|
|
|
})(VideoProviderContainer);
|
2024-04-20 04:34:43 +08:00
|
|
|
|
|
|
|
export default VideoProviderContainerGraphql;
|