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

107 lines
3.1 KiB
React
Raw Normal View History

2018-11-07 07:10:56 +08:00
import React from 'react';
import { useMutation } from '@apollo/client';
2018-11-07 07:10:56 +08:00
import { withTracker } from 'meteor/react-meteor-data';
import Service from './service';
import VideoPreview from './component';
2024-04-20 04:34:43 +08:00
import VideoService from '../video-provider/video-provider-graphql/service';
import * as ScreenShareService from '/imports/ui/components/screenshare/service';
2023-03-11 01:25:24 +08:00
import logger from '/imports/startup/client/logger';
import { SCREENSHARING_ERRORS } from '/imports/api/screenshare/client/bridge/errors';
import { EXTERNAL_VIDEO_STOP } from '../external-video-player/mutations';
2024-04-20 04:34:43 +08:00
import {
useSharedDevices, useHasVideoStream, useHasCapReached, useIsUserLocked, useStreams,
useExitVideo,
useStopVideo,
2024-04-20 04:34:43 +08:00
} from '/imports/ui/components/video-provider/video-provider-graphql/hooks';
import { useStorageKey } from '../../services/storage/hooks';
const VideoPreviewContainer = (props) => {
2024-04-20 04:34:43 +08:00
const {
2024-05-07 21:12:04 +08:00
callbackToClose,
setIsOpen,
2024-04-20 04:34:43 +08:00
} = props;
2024-06-11 22:55:00 +08:00
const cameraAsContentDeviceId = ScreenShareService.useCameraAsContentDeviceIdType();
const [stopExternalVideoShare] = useMutation(EXTERNAL_VIDEO_STOP);
2023-03-11 01:25:24 +08:00
2024-04-20 04:34:43 +08:00
const { streams } = useStreams();
const exitVideo = useExitVideo();
const stopVideo = useStopVideo();
2024-04-20 04:34:43 +08:00
const sharedDevices = useSharedDevices();
const hasVideoStream = useHasVideoStream();
const camCapReached = useHasCapReached();
const isCamLocked = useIsUserLocked();
const webcamDeviceId = useStorageKey('WebcamDeviceId');
2023-03-11 01:25:24 +08:00
2024-05-07 21:12:04 +08:00
const stopSharing = (deviceId) => {
callbackToClose();
setIsOpen(false);
2024-05-07 21:12:04 +08:00
if (deviceId) {
const streamId = VideoService.getMyStreamId(deviceId, streams);
if (streamId) stopVideo(streamId);
} else {
exitVideo();
}
};
const startSharingCameraAsContent = (deviceId) => {
callbackToClose();
setIsOpen(false);
const handleFailure = (error) => {
const {
errorCode = SCREENSHARING_ERRORS.UNKNOWN_ERROR.errorCode,
errorMessage = error.message,
} = error;
logger.error({
logCode: 'camera_as_content_failed',
extraInfo: { errorCode, errorMessage },
}, `Sharing camera as content failed: ${errorMessage} (code=${errorCode})`);
2023-03-11 01:25:24 +08:00
ScreenShareService.screenshareHasEnded();
};
ScreenShareService.shareScreen(
stopExternalVideoShare,
2024-04-20 04:34:43 +08:00
true, handleFailure, { stream: Service.getStream(deviceId)._mediaStream },
);
ScreenShareService.setCameraAsContentDeviceId(deviceId);
2024-05-07 21:12:04 +08:00
};
2024-06-11 22:55:00 +08:00
const startSharing = (deviceId) => {
callbackToClose();
setIsOpen(false);
VideoService.joinVideo(deviceId);
};
const stopSharingCameraAsContent = () => {
callbackToClose();
setIsOpen(false);
ScreenShareService.screenshareHasEnded();
};
const closeModal = () => {
callbackToClose();
setIsOpen(false);
};
2024-05-07 21:12:04 +08:00
return (
<VideoPreview
{...{
2024-06-11 22:55:00 +08:00
stopSharingCameraAsContent,
closeModal,
startSharing,
cameraAsContentDeviceId,
2024-05-07 21:12:04 +08:00
startSharingCameraAsContent,
stopSharing,
sharedDevices,
hasVideoStream,
camCapReached,
isCamLocked,
webcamDeviceId,
2024-05-07 21:12:04 +08:00
...props,
}}
/>
);
};
2024-06-11 22:55:00 +08:00
export default VideoPreviewContainer;