2018-11-07 07:10:56 +08:00
|
|
|
import React from 'react';
|
2024-02-17 04:32:14 +08:00
|
|
|
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';
|
2024-05-24 22:44:36 +08:00
|
|
|
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';
|
2024-01-20 02:40:27 +08:00
|
|
|
import { EXTERNAL_VIDEO_STOP } from '../external-video-player/mutations';
|
2024-04-20 04:34:43 +08:00
|
|
|
import {
|
|
|
|
useSharedDevices, useHasVideoStream, useHasCapReached, useIsUserLocked, useStreams,
|
|
|
|
useExitVideo,
|
2024-05-02 03:48:12 +08:00
|
|
|
useStopVideo,
|
2024-04-20 04:34:43 +08:00
|
|
|
} from '/imports/ui/components/video-provider/video-provider-graphql/hooks';
|
2024-06-06 21:50:03 +08:00
|
|
|
import { useStorageKey } from '../../services/storage/hooks';
|
2019-11-06 04:23:13 +08:00
|
|
|
|
2024-02-17 04:32:14 +08:00
|
|
|
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();
|
2024-01-20 02:40:27 +08:00
|
|
|
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();
|
2024-05-02 03:48:12 +08:00
|
|
|
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();
|
2024-06-06 21:50:03 +08:00
|
|
|
const webcamDeviceId = useStorageKey('WebcamDeviceId');
|
2023-03-11 01:25:24 +08:00
|
|
|
|
2024-05-07 21:12:04 +08:00
|
|
|
const stopSharing = (deviceId) => {
|
2024-02-17 04:32:14 +08:00
|
|
|
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) => {
|
2024-02-17 04:32:14 +08:00
|
|
|
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})`);
|
2024-01-20 02:40:27 +08:00
|
|
|
|
2023-03-11 01:25:24 +08:00
|
|
|
ScreenShareService.screenshareHasEnded();
|
2024-02-17 04:32:14 +08:00
|
|
|
};
|
|
|
|
ScreenShareService.shareScreen(
|
|
|
|
stopExternalVideoShare,
|
2024-04-20 04:34:43 +08:00
|
|
|
true, handleFailure, { stream: Service.getStream(deviceId)._mediaStream },
|
2024-02-17 04:32:14 +08:00
|
|
|
);
|
|
|
|
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,
|
2024-06-06 21:50:03 +08:00
|
|
|
webcamDeviceId,
|
2024-05-07 21:12:04 +08:00
|
|
|
...props,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-06-11 22:55:00 +08:00
|
|
|
export default VideoPreviewContainer;
|