2018-11-07 07:10:56 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
|
|
|
import Service from './service';
|
2024-01-20 02:40:27 +08:00
|
|
|
import { useMutation } from '@apollo/client';
|
2018-11-07 07:10:56 +08:00
|
|
|
import VideoPreview from './component';
|
2019-11-28 21:13:06 +08:00
|
|
|
import VideoService from '../video-provider/service';
|
2023-04-27 00:09:02 +08:00
|
|
|
import 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';
|
2019-11-06 04:23:13 +08:00
|
|
|
|
2021-11-20 03:03:36 +08:00
|
|
|
const VideoPreviewContainer = (props) => <VideoPreview {...props} />;
|
2020-05-10 01:19:41 +08:00
|
|
|
|
2024-01-20 02:40:27 +08:00
|
|
|
export default withTracker(({ setIsOpen, callbackToClose }) => {
|
|
|
|
const [stopExternalVideoShare] = useMutation(EXTERNAL_VIDEO_STOP);
|
2023-03-11 01:25:24 +08:00
|
|
|
|
2024-01-20 02:40:27 +08:00
|
|
|
return {
|
|
|
|
startSharing: (deviceId) => {
|
|
|
|
callbackToClose();
|
|
|
|
setIsOpen(false);
|
|
|
|
VideoService.joinVideo(deviceId);
|
|
|
|
},
|
|
|
|
startSharingCameraAsContent: (deviceId) => {
|
|
|
|
callbackToClose();
|
|
|
|
setIsOpen(false);
|
|
|
|
const handleFailure = (error) => {
|
|
|
|
const {
|
|
|
|
errorCode = SCREENSHARING_ERRORS.UNKNOWN_ERROR.errorCode,
|
|
|
|
errorMessage = error.message,
|
|
|
|
} = error;
|
2023-03-11 01:25:24 +08:00
|
|
|
|
2024-01-20 02:40:27 +08:00
|
|
|
logger.error({
|
|
|
|
logCode: 'camera_as_content_failed',
|
|
|
|
extraInfo: { errorCode, errorMessage },
|
|
|
|
}, `Sharing camera as content failed: ${errorMessage} (code=${errorCode})`);
|
|
|
|
|
|
|
|
ScreenShareService.screenshareHasEnded();
|
|
|
|
};
|
|
|
|
ScreenShareService.shareScreen(
|
|
|
|
stopExternalVideoShare,
|
|
|
|
true, handleFailure, { stream: Service.getStream(deviceId)._mediaStream }
|
|
|
|
);
|
|
|
|
ScreenShareService.setCameraAsContentDeviceId(deviceId);
|
|
|
|
},
|
|
|
|
stopSharing: (deviceId) => {
|
|
|
|
callbackToClose();
|
|
|
|
setIsOpen(false);
|
|
|
|
if (deviceId) {
|
|
|
|
const streamId = VideoService.getMyStreamId(deviceId);
|
|
|
|
if (streamId) VideoService.stopVideo(streamId);
|
|
|
|
} else {
|
|
|
|
VideoService.exitVideo();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
stopSharingCameraAsContent: () => {
|
|
|
|
callbackToClose();
|
|
|
|
setIsOpen(false);
|
2023-03-11 01:25:24 +08:00
|
|
|
ScreenShareService.screenshareHasEnded();
|
2024-01-20 02:40:27 +08:00
|
|
|
},
|
|
|
|
sharedDevices: VideoService.getSharedDevices(),
|
|
|
|
cameraAsContentDeviceId: ScreenShareService.getCameraAsContentDeviceId(),
|
|
|
|
isCamLocked: VideoService.isUserLocked(),
|
|
|
|
camCapReached: VideoService.hasCapReached(),
|
|
|
|
closeModal: () => {
|
|
|
|
callbackToClose();
|
|
|
|
setIsOpen(false);
|
|
|
|
},
|
|
|
|
webcamDeviceId: Service.webcamDeviceId(),
|
|
|
|
hasVideoStream: VideoService.hasVideoStream(),
|
|
|
|
};
|
|
|
|
})(VideoPreviewContainer);
|