2018-11-07 07:10:56 +08:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
2019-03-29 05:53:42 +08:00
|
|
|
import {
|
|
|
|
defineMessages, injectIntl, intlShape, FormattedMessage,
|
|
|
|
} from 'react-intl';
|
2018-11-07 07:10:56 +08:00
|
|
|
import Button from '/imports/ui/components/button/component';
|
2019-04-09 06:07:26 +08:00
|
|
|
// import { notify } from '/imports/ui/services/notification';
|
2018-11-17 01:59:15 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2018-12-03 14:01:19 +08:00
|
|
|
import Modal from '/imports/ui/components/modal/simple/component';
|
2019-12-19 01:44:56 +08:00
|
|
|
import VideoService from '../video-provider/service';
|
2019-03-29 05:53:42 +08:00
|
|
|
import browser from 'browser-detect';
|
2018-11-07 07:10:56 +08:00
|
|
|
import { styles } from './styles';
|
|
|
|
|
2019-04-09 06:07:26 +08:00
|
|
|
const CAMERA_PROFILES = Meteor.settings.public.kurento.cameraProfiles;
|
2018-11-15 05:12:02 +08:00
|
|
|
|
2019-09-27 02:28:37 +08:00
|
|
|
const VIEW_STATES = {
|
|
|
|
finding: 'finding',
|
|
|
|
found: 'found',
|
|
|
|
error: 'error',
|
|
|
|
};
|
|
|
|
|
2018-11-07 07:10:56 +08:00
|
|
|
const propTypes = {
|
|
|
|
intl: intlShape.isRequired,
|
|
|
|
closeModal: PropTypes.func.isRequired,
|
|
|
|
startSharing: PropTypes.func.isRequired,
|
2019-12-19 01:50:16 +08:00
|
|
|
stopSharing: PropTypes.func.isRequired,
|
2018-11-07 07:10:56 +08:00
|
|
|
changeWebcam: PropTypes.func.isRequired,
|
2019-04-09 06:07:26 +08:00
|
|
|
changeProfile: PropTypes.func.isRequired,
|
2019-07-24 06:24:31 +08:00
|
|
|
resolve: PropTypes.func,
|
2019-12-19 01:50:16 +08:00
|
|
|
skipVideoPreview: PropTypes.bool.isRequired,
|
2019-06-28 00:02:42 +08:00
|
|
|
hasMediaDevices: PropTypes.bool.isRequired,
|
2019-07-27 00:48:51 +08:00
|
|
|
webcamDeviceId: PropTypes.string,
|
2019-11-29 04:28:41 +08:00
|
|
|
sharedDevices: PropTypes.arrayOf(PropTypes.string),
|
2018-11-07 07:10:56 +08:00
|
|
|
};
|
|
|
|
|
2019-07-24 06:24:31 +08:00
|
|
|
const defaultProps = {
|
|
|
|
resolve: null,
|
2019-07-27 00:48:51 +08:00
|
|
|
webcamDeviceId: null,
|
2019-12-19 01:50:16 +08:00
|
|
|
sharedDevices: [],
|
2019-07-24 06:24:31 +08:00
|
|
|
};
|
|
|
|
|
2018-11-07 07:10:56 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
webcamSettingsTitle: {
|
|
|
|
id: 'app.videoPreview.webcamSettingsTitle',
|
|
|
|
description: 'Title for the video preview modal',
|
|
|
|
},
|
|
|
|
closeLabel: {
|
|
|
|
id: 'app.videoPreview.closeLabel',
|
|
|
|
description: 'Close button label',
|
|
|
|
},
|
|
|
|
webcamPreviewLabel: {
|
|
|
|
id: 'app.videoPreview.webcamPreviewLabel',
|
|
|
|
description: 'Webcam preview label',
|
|
|
|
},
|
|
|
|
cameraLabel: {
|
|
|
|
id: 'app.videoPreview.cameraLabel',
|
|
|
|
description: 'Camera dropdown label',
|
|
|
|
},
|
2019-05-01 06:29:30 +08:00
|
|
|
qualityLabel: {
|
|
|
|
id: 'app.videoPreview.profileLabel',
|
|
|
|
description: 'Quality dropdown label',
|
|
|
|
},
|
2018-11-07 07:10:56 +08:00
|
|
|
cancelLabel: {
|
|
|
|
id: 'app.videoPreview.cancelLabel',
|
|
|
|
description: 'Cancel button label',
|
|
|
|
},
|
|
|
|
startSharingLabel: {
|
|
|
|
id: 'app.videoPreview.startSharingLabel',
|
2019-12-19 01:44:56 +08:00
|
|
|
description: 'Start sharing button label',
|
|
|
|
},
|
|
|
|
stopSharingLabel: {
|
|
|
|
id: 'app.videoPreview.stopSharingLabel',
|
|
|
|
description: 'Stop sharing button label',
|
|
|
|
},
|
|
|
|
sharedCameraLabel: {
|
|
|
|
id: 'app.videoPreview.sharedCameraLabel',
|
|
|
|
description: 'Already Shared camera label',
|
2018-11-07 07:10:56 +08:00
|
|
|
},
|
2019-09-27 02:28:37 +08:00
|
|
|
findingWebcamsLabel: {
|
|
|
|
id: 'app.videoPreview.findingWebcamsLabel',
|
|
|
|
description: 'Finding webcams label',
|
|
|
|
},
|
2018-11-07 07:10:56 +08:00
|
|
|
webcamOptionLabel: {
|
|
|
|
id: 'app.videoPreview.webcamOptionLabel',
|
|
|
|
description: 'Default webcam option label',
|
|
|
|
},
|
|
|
|
webcamNotFoundLabel: {
|
|
|
|
id: 'app.videoPreview.webcamNotFoundLabel',
|
|
|
|
description: 'Webcam not found label',
|
|
|
|
},
|
2019-05-01 06:29:30 +08:00
|
|
|
profileNotFoundLabel: {
|
|
|
|
id: 'app.videoPreview.profileNotFoundLabel',
|
|
|
|
description: 'Profile not found label',
|
|
|
|
},
|
2018-12-18 01:45:57 +08:00
|
|
|
permissionError: {
|
|
|
|
id: 'app.video.permissionError',
|
|
|
|
description: 'Error message for webcam permission',
|
|
|
|
},
|
|
|
|
NotFoundError: {
|
|
|
|
id: 'app.video.notFoundError',
|
|
|
|
description: 'error message when can not get webcam video',
|
|
|
|
},
|
|
|
|
NotAllowedError: {
|
|
|
|
id: 'app.video.notAllowed',
|
|
|
|
description: 'error message when webcam had permission denied',
|
|
|
|
},
|
|
|
|
NotSupportedError: {
|
|
|
|
id: 'app.video.notSupportedError',
|
|
|
|
description: 'error message when origin do not have ssl valid',
|
|
|
|
},
|
|
|
|
NotReadableError: {
|
|
|
|
id: 'app.video.notReadableError',
|
|
|
|
description: 'error message When the webcam is being used by other software',
|
2018-11-16 04:00:11 +08:00
|
|
|
},
|
2019-06-28 00:02:42 +08:00
|
|
|
iOSError: {
|
|
|
|
id: 'app.audioModal.iOSBrowser',
|
|
|
|
description: 'Audio/Video Not supported warning',
|
|
|
|
},
|
|
|
|
iOSErrorDescription: {
|
|
|
|
id: 'app.audioModal.iOSErrorDescription',
|
|
|
|
description: 'Audio/Video not supported description',
|
|
|
|
},
|
|
|
|
iOSErrorRecommendation: {
|
|
|
|
id: 'app.audioModal.iOSErrorRecommendation',
|
|
|
|
description: 'Audio/Video recommended action',
|
|
|
|
},
|
2018-11-07 07:10:56 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
class VideoPreview extends Component {
|
2019-09-27 02:28:37 +08:00
|
|
|
static handleGUMError(error) {
|
|
|
|
// logger.error(error);
|
|
|
|
// logger.error(error.id);
|
|
|
|
// logger.error(error.name);
|
|
|
|
// console.log(error);
|
|
|
|
// console.log(error.name)
|
|
|
|
// console.log(error.message)
|
|
|
|
|
|
|
|
// let convertedError;
|
|
|
|
|
|
|
|
/* switch (error.name) {
|
|
|
|
case 'SourceUnavailableError':
|
|
|
|
case 'NotReadableError':
|
|
|
|
// hardware failure with the device
|
|
|
|
// NotReadableError: Could not start video source
|
|
|
|
break;
|
|
|
|
case 'NotAllowedError':
|
|
|
|
// media was disallowed
|
|
|
|
// NotAllowedError: Permission denied
|
|
|
|
convertedError = intlMessages.NotAllowedError;
|
|
|
|
break;
|
|
|
|
case 'AbortError':
|
|
|
|
// generic error occured
|
|
|
|
// AbortError: Starting video failed (FF when there's a hardware failure)
|
|
|
|
break;
|
|
|
|
case 'NotFoundError':
|
|
|
|
// no webcam found
|
|
|
|
// NotFoundError: The object can not be found here.
|
|
|
|
// NotFoundError: Requested device not found
|
|
|
|
convertedError = intlMessages.NotFoundError;
|
|
|
|
break;
|
|
|
|
case 'SecurityError':
|
|
|
|
// user media support is disabled on the document
|
|
|
|
break;
|
|
|
|
case 'TypeError':
|
|
|
|
// issue with constraints or maybe Chrome with HTTP
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// default error message handling
|
|
|
|
break;
|
|
|
|
} */
|
|
|
|
|
|
|
|
return `${error.name}: ${error.message}`;
|
|
|
|
}
|
|
|
|
|
2018-11-07 07:10:56 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
const {
|
2018-11-17 02:56:39 +08:00
|
|
|
webcamDeviceId,
|
2018-11-07 07:10:56 +08:00
|
|
|
} = props;
|
|
|
|
|
2018-11-16 03:38:04 +08:00
|
|
|
this.handleProceed = this.handleProceed.bind(this);
|
|
|
|
this.handleStartSharing = this.handleStartSharing.bind(this);
|
2019-11-29 04:28:41 +08:00
|
|
|
this.handleStopSharing = this.handleStopSharing.bind(this);
|
2019-09-27 02:28:37 +08:00
|
|
|
this.handleSelectWebcam = this.handleSelectWebcam.bind(this);
|
|
|
|
this.handleSelectProfile = this.handleSelectProfile.bind(this);
|
2018-11-08 05:16:36 +08:00
|
|
|
|
|
|
|
this.deviceStream = null;
|
2018-11-17 02:56:39 +08:00
|
|
|
|
2019-04-09 06:07:26 +08:00
|
|
|
this._isMounted = false;
|
|
|
|
|
2018-11-17 02:56:39 +08:00
|
|
|
this.state = {
|
2019-01-18 00:33:43 +08:00
|
|
|
webcamDeviceId,
|
2018-11-17 02:56:39 +08:00
|
|
|
availableWebcams: null,
|
2019-04-09 06:07:26 +08:00
|
|
|
availableProfiles: {},
|
|
|
|
selectedProfile: null,
|
|
|
|
isStartSharingDisabled: true,
|
2019-09-27 02:28:37 +08:00
|
|
|
viewState: VIEW_STATES.finding,
|
2019-11-21 01:17:42 +08:00
|
|
|
deviceError: null,
|
|
|
|
previewError: null,
|
2018-11-17 02:56:39 +08:00
|
|
|
};
|
2019-12-19 01:44:56 +08:00
|
|
|
|
|
|
|
this.userParameterProfile = VideoService.getUserParameterProfile();
|
2018-11-08 05:16:36 +08:00
|
|
|
}
|
|
|
|
|
2019-06-28 00:02:42 +08:00
|
|
|
componentDidMount() {
|
2019-11-21 02:35:16 +08:00
|
|
|
const {
|
|
|
|
webcamDeviceId,
|
|
|
|
hasMediaDevices,
|
|
|
|
skipVideoPreview,
|
|
|
|
} = this.props;
|
2019-06-28 00:02:42 +08:00
|
|
|
|
|
|
|
this._isMounted = true;
|
|
|
|
|
|
|
|
// Have to request any device to get past checks before finding devices. If this is
|
|
|
|
// skipped then we get devices with no labels
|
|
|
|
if (hasMediaDevices) {
|
|
|
|
try {
|
2019-09-27 02:28:37 +08:00
|
|
|
navigator.mediaDevices.getUserMedia({ audio: false, video: { facingMode: 'user' } })
|
|
|
|
.then((stream) => {
|
2019-06-28 00:02:42 +08:00
|
|
|
if (!this._isMounted) return;
|
2019-09-27 02:28:37 +08:00
|
|
|
this.deviceStream = stream;
|
|
|
|
// try and get the deviceId for the initial stream
|
|
|
|
let firstAllowedDeviceId;
|
|
|
|
if (stream.getVideoTracks) {
|
|
|
|
const videoTracks = stream.getVideoTracks();
|
|
|
|
if (videoTracks.length > 0 && videoTracks[0].getSettings) {
|
|
|
|
const trackSettings = videoTracks[0].getSettings();
|
|
|
|
firstAllowedDeviceId = trackSettings.deviceId;
|
|
|
|
}
|
|
|
|
}
|
2019-06-28 00:02:42 +08:00
|
|
|
|
2019-09-27 02:28:37 +08:00
|
|
|
navigator.mediaDevices.enumerateDevices().then((devices) => {
|
|
|
|
const webcams = [];
|
|
|
|
let initialDeviceId;
|
|
|
|
|
|
|
|
if (!this._isMounted) return;
|
|
|
|
|
|
|
|
// set webcam
|
|
|
|
devices.forEach((device) => {
|
2019-12-21 03:47:30 +08:00
|
|
|
// Avoid duplicated devices
|
|
|
|
const found = webcams.find(d => d.deviceId === device.deviceId);
|
|
|
|
if (device.kind === 'videoinput' && !found) {
|
2019-09-27 02:28:37 +08:00
|
|
|
webcams.push(device);
|
|
|
|
if (!initialDeviceId
|
|
|
|
|| (webcamDeviceId && webcamDeviceId === device.deviceId)
|
|
|
|
|| device.deviceId === firstAllowedDeviceId) {
|
|
|
|
initialDeviceId = device.deviceId;
|
|
|
|
}
|
2019-06-28 00:02:42 +08:00
|
|
|
}
|
2019-09-27 02:28:37 +08:00
|
|
|
});
|
2019-06-28 00:02:42 +08:00
|
|
|
|
2019-09-27 02:28:37 +08:00
|
|
|
logger.debug({
|
|
|
|
logCode: 'video_preview_enumerate_devices',
|
|
|
|
extraInfo: {
|
|
|
|
devices,
|
|
|
|
webcams,
|
|
|
|
},
|
|
|
|
}, `Enumerate devices came back. There are ${devices.length} devices and ${webcams.length} are video inputs`);
|
2019-07-05 02:37:40 +08:00
|
|
|
|
2019-06-28 00:02:42 +08:00
|
|
|
|
2019-09-27 02:28:37 +08:00
|
|
|
if (initialDeviceId) {
|
|
|
|
this.setState({
|
|
|
|
availableWebcams: webcams,
|
|
|
|
});
|
|
|
|
this.displayInitialPreview(initialDeviceId);
|
|
|
|
}
|
2019-11-21 02:35:16 +08:00
|
|
|
if (!skipVideoPreview) {
|
|
|
|
this.setState({
|
|
|
|
viewState: VIEW_STATES.found,
|
|
|
|
});
|
|
|
|
}
|
2019-09-27 02:28:37 +08:00
|
|
|
}).catch((error) => {
|
|
|
|
logger.warn({
|
|
|
|
logCode: 'video_preview_enumerate_error',
|
|
|
|
extraInfo: {
|
|
|
|
errorName: error.name,
|
|
|
|
errorMessage: error.message,
|
|
|
|
},
|
|
|
|
}, 'Error enumerating devices');
|
|
|
|
this.setState({
|
|
|
|
viewState: VIEW_STATES.error,
|
|
|
|
deviceError: VideoPreview.handleGUMError(error),
|
|
|
|
});
|
|
|
|
});
|
2019-06-28 00:02:42 +08:00
|
|
|
}).catch((error) => {
|
2019-07-05 02:37:40 +08:00
|
|
|
logger.warn({
|
2019-09-27 02:28:37 +08:00
|
|
|
logCode: 'video_preview_initial_device_error',
|
2019-07-05 02:37:40 +08:00
|
|
|
extraInfo: {
|
2019-09-27 02:28:37 +08:00
|
|
|
errorName: error.name,
|
|
|
|
errorMessage: error.message,
|
2019-07-05 02:37:40 +08:00
|
|
|
},
|
2019-09-27 02:28:37 +08:00
|
|
|
}, 'Error getting initial device');
|
|
|
|
this.setState({
|
|
|
|
viewState: VIEW_STATES.error,
|
|
|
|
deviceError: VideoPreview.handleGUMError(error),
|
|
|
|
});
|
2019-06-28 00:02:42 +08:00
|
|
|
});
|
|
|
|
} catch (error) {
|
2019-07-05 02:37:40 +08:00
|
|
|
logger.warn({
|
|
|
|
logCode: 'video_preview_grabbing_error',
|
|
|
|
extraInfo: {
|
2019-09-27 02:28:37 +08:00
|
|
|
errorName: error.name,
|
|
|
|
errorMessage: error.message,
|
2019-07-05 02:37:40 +08:00
|
|
|
},
|
|
|
|
}, 'Error grabbing initial video stream');
|
2019-09-27 02:28:37 +08:00
|
|
|
this.setState({
|
|
|
|
viewState: VIEW_STATES.error,
|
|
|
|
deviceError: VideoPreview.handleGUMError(error),
|
|
|
|
});
|
2019-06-28 00:02:42 +08:00
|
|
|
}
|
2019-09-27 02:28:37 +08:00
|
|
|
} else {
|
|
|
|
// TODO: Add an error message when media is globablly disabled
|
2019-06-28 00:02:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
// console.log("unmounting video preview");
|
|
|
|
this.stopTracks();
|
|
|
|
this.deviceStream = null;
|
|
|
|
if (this.video) {
|
|
|
|
// console.log("clear video srcObject");
|
|
|
|
this.video.srcObject = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._isMounted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-08 05:16:36 +08:00
|
|
|
stopTracks() {
|
2019-04-09 06:07:26 +08:00
|
|
|
// console.log("in stop tracks");
|
2018-11-08 05:16:36 +08:00
|
|
|
if (this.deviceStream) {
|
2019-04-09 06:07:26 +08:00
|
|
|
// console.log("stopping tracks");
|
2018-11-08 05:16:36 +08:00
|
|
|
this.deviceStream.getTracks().forEach((track) => {
|
2019-04-09 06:07:26 +08:00
|
|
|
// console.log("found track to stop");
|
2018-11-08 05:16:36 +08:00
|
|
|
track.stop();
|
|
|
|
});
|
|
|
|
}
|
2018-11-07 07:10:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handleSelectWebcam(event) {
|
|
|
|
const webcamValue = event.target.value;
|
2019-04-09 06:07:26 +08:00
|
|
|
|
2019-09-27 02:28:37 +08:00
|
|
|
this.displayInitialPreview(webcamValue);
|
2019-04-09 06:07:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handleSelectProfile(event) {
|
|
|
|
const profileValue = event.target.value;
|
|
|
|
const { webcamDeviceId } = this.state;
|
|
|
|
|
|
|
|
const selectedProfile = CAMERA_PROFILES.find(profile => profile.id === profileValue);
|
|
|
|
|
|
|
|
this.displayPreview(webcamDeviceId, selectedProfile);
|
2018-11-07 07:10:56 +08:00
|
|
|
}
|
|
|
|
|
2018-11-08 05:16:36 +08:00
|
|
|
handleStartSharing() {
|
2019-01-18 00:33:43 +08:00
|
|
|
const { resolve, startSharing } = this.props;
|
2019-11-28 00:19:09 +08:00
|
|
|
const { webcamDeviceId } = this.state;
|
2018-11-08 05:16:36 +08:00
|
|
|
this.stopTracks();
|
2019-11-28 00:19:09 +08:00
|
|
|
startSharing(webcamDeviceId);
|
2018-11-16 03:38:04 +08:00
|
|
|
if (resolve) resolve();
|
|
|
|
}
|
|
|
|
|
2019-12-19 01:44:56 +08:00
|
|
|
handleStopSharing() {
|
2019-11-29 04:28:41 +08:00
|
|
|
const { resolve, stopSharing } = this.props;
|
2019-12-19 01:44:56 +08:00
|
|
|
const { webcamDeviceId } = this.state;
|
2019-11-29 04:28:41 +08:00
|
|
|
this.stopTracks();
|
2019-12-19 01:44:56 +08:00
|
|
|
stopSharing(webcamDeviceId);
|
2019-11-29 04:28:41 +08:00
|
|
|
if (resolve) resolve();
|
|
|
|
}
|
|
|
|
|
2018-11-16 03:38:04 +08:00
|
|
|
handleProceed() {
|
2019-01-18 00:33:43 +08:00
|
|
|
const { resolve, closeModal } = this.props;
|
2019-03-06 02:13:50 +08:00
|
|
|
this.stopTracks();
|
2019-01-18 00:33:43 +08:00
|
|
|
closeModal();
|
2018-11-16 03:38:04 +08:00
|
|
|
if (resolve) resolve();
|
2018-11-08 05:16:36 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 02:28:37 +08:00
|
|
|
displayInitialPreview(deviceId) {
|
2019-12-19 01:44:56 +08:00
|
|
|
const { changeWebcam } = this.props;
|
2019-09-27 02:28:37 +08:00
|
|
|
const availableProfiles = CAMERA_PROFILES;
|
2019-04-09 06:07:26 +08:00
|
|
|
|
|
|
|
this.setState({
|
2019-09-27 02:28:37 +08:00
|
|
|
webcamDeviceId: deviceId,
|
2019-04-09 06:07:26 +08:00
|
|
|
isStartSharingDisabled: true,
|
2019-09-27 02:28:37 +08:00
|
|
|
availableProfiles,
|
2019-04-09 06:07:26 +08:00
|
|
|
});
|
2019-09-27 02:28:37 +08:00
|
|
|
changeWebcam(deviceId);
|
2019-04-09 06:07:26 +08:00
|
|
|
|
2019-09-27 02:28:37 +08:00
|
|
|
if (availableProfiles.length > 0) {
|
2019-12-19 01:44:56 +08:00
|
|
|
const defaultProfile = availableProfiles.find(profile => profile.id === this.userParameterProfile)
|
2019-11-06 04:23:13 +08:00
|
|
|
|| availableProfiles.find(profile => profile.default)
|
2019-09-27 02:28:37 +08:00
|
|
|
|| availableProfiles[0];
|
|
|
|
this.displayPreview(deviceId, defaultProfile);
|
|
|
|
}
|
2019-04-09 06:07:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
doGUM(deviceId, profile) {
|
|
|
|
const constraints = {
|
|
|
|
audio: false,
|
|
|
|
video: { ...profile.constraints },
|
|
|
|
};
|
|
|
|
constraints.video.deviceId = { exact: deviceId };
|
|
|
|
|
|
|
|
this.stopTracks();
|
2019-09-27 02:28:37 +08:00
|
|
|
if (this.video) {
|
|
|
|
this.video.srcObject = null;
|
|
|
|
}
|
2019-04-09 06:07:26 +08:00
|
|
|
this.deviceStream = null;
|
|
|
|
|
|
|
|
return navigator.mediaDevices.getUserMedia(constraints);
|
|
|
|
}
|
|
|
|
|
|
|
|
displayPreview(deviceId, profile) {
|
2019-11-21 01:17:42 +08:00
|
|
|
const {
|
|
|
|
changeProfile,
|
|
|
|
skipVideoPreview,
|
|
|
|
} = this.props;
|
2019-04-09 06:07:26 +08:00
|
|
|
|
2019-09-27 02:28:37 +08:00
|
|
|
this.setState({
|
|
|
|
selectedProfile: profile.id,
|
|
|
|
isStartSharingDisabled: true,
|
|
|
|
previewError: undefined,
|
|
|
|
});
|
2019-04-09 06:07:26 +08:00
|
|
|
changeProfile(profile.id);
|
2019-11-21 03:51:14 +08:00
|
|
|
if (skipVideoPreview) return this.handleStartSharing();
|
2019-04-09 06:07:26 +08:00
|
|
|
|
|
|
|
this.doGUM(deviceId, profile).then((stream) => {
|
|
|
|
if (!this._isMounted) return;
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
isStartSharingDisabled: false,
|
|
|
|
});
|
|
|
|
this.video.srcObject = stream;
|
|
|
|
this.deviceStream = stream;
|
2019-11-21 01:17:42 +08:00
|
|
|
|
2019-04-09 06:07:26 +08:00
|
|
|
}).catch((error) => {
|
2019-07-03 00:54:10 +08:00
|
|
|
logger.warn({
|
2019-06-29 05:45:50 +08:00
|
|
|
logCode: 'video_preview_do_gum_preview_error',
|
|
|
|
extraInfo: {
|
2019-09-27 02:28:37 +08:00
|
|
|
errorName: error.name,
|
|
|
|
errorMessage: error.message,
|
2019-06-29 05:45:50 +08:00
|
|
|
},
|
|
|
|
}, 'Error displaying final selection.');
|
2019-09-27 02:28:37 +08:00
|
|
|
this.setState({ previewError: VideoPreview.handleGUMError(error) });
|
2019-04-09 06:07:26 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-28 00:02:42 +08:00
|
|
|
supportWarning() {
|
|
|
|
const { intl } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div className={styles.warning}>!</div>
|
|
|
|
<h4 className={styles.main}>{intl.formatMessage(intlMessages.iOSError)}</h4>
|
|
|
|
<div className={styles.text}>{intl.formatMessage(intlMessages.iOSErrorDescription)}</div>
|
|
|
|
<div className={styles.text}>
|
|
|
|
{intl.formatMessage(intlMessages.iOSErrorRecommendation)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-27 02:28:37 +08:00
|
|
|
renderDeviceSelectors() {
|
2018-11-07 07:10:56 +08:00
|
|
|
const {
|
|
|
|
intl,
|
2019-12-19 01:44:56 +08:00
|
|
|
skipVideoPreview,
|
|
|
|
sharedDevices
|
2018-11-07 07:10:56 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2019-01-18 00:33:43 +08:00
|
|
|
const {
|
|
|
|
webcamDeviceId,
|
|
|
|
availableWebcams,
|
2019-04-09 06:07:26 +08:00
|
|
|
availableProfiles,
|
|
|
|
selectedProfile,
|
2019-09-27 02:28:37 +08:00
|
|
|
} = this.state;
|
|
|
|
|
2019-12-19 01:44:56 +08:00
|
|
|
const shared = sharedDevices.includes(webcamDeviceId);
|
|
|
|
|
2019-09-27 02:28:37 +08:00
|
|
|
return (
|
|
|
|
<div className={styles.col}>
|
|
|
|
<label className={styles.label} htmlFor="setCam">
|
|
|
|
{intl.formatMessage(intlMessages.cameraLabel)}
|
|
|
|
</label>
|
2019-12-19 01:44:56 +08:00
|
|
|
{ availableWebcams && availableWebcams.length > 0
|
|
|
|
? (
|
|
|
|
<select
|
|
|
|
id="setCam"
|
|
|
|
value={webcamDeviceId || ''}
|
|
|
|
className={styles.select}
|
|
|
|
onChange={this.handleSelectWebcam}
|
|
|
|
disabled={skipVideoPreview}
|
|
|
|
>
|
|
|
|
{availableWebcams.map(webcam => (
|
|
|
|
<option key={webcam.deviceId} value={webcam.deviceId}>
|
|
|
|
{webcam.label}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
)
|
|
|
|
: (
|
|
|
|
<span>
|
|
|
|
{intl.formatMessage(intlMessages.webcamNotFoundLabel)}
|
|
|
|
</span>
|
|
|
|
)
|
2019-09-27 02:28:37 +08:00
|
|
|
}
|
2019-12-19 01:44:56 +08:00
|
|
|
{ shared
|
|
|
|
? (
|
|
|
|
<span className={styles.label}>
|
|
|
|
{intl.formatMessage(intlMessages.sharedCameraLabel)}
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
: (
|
|
|
|
<span>
|
|
|
|
<label className={styles.label} htmlFor="setQuality">
|
|
|
|
{intl.formatMessage(intlMessages.qualityLabel)}
|
|
|
|
</label>
|
|
|
|
{ availableProfiles && availableProfiles.length > 0
|
|
|
|
? (
|
|
|
|
<select
|
|
|
|
id="setQuality"
|
|
|
|
value={selectedProfile || ''}
|
|
|
|
className={styles.select}
|
|
|
|
onChange={this.handleSelectProfile}
|
|
|
|
disabled={skipVideoPreview}
|
|
|
|
>
|
|
|
|
{availableProfiles.map(profile => (
|
|
|
|
<option key={profile.id} value={profile.id}>
|
|
|
|
{profile.name}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
)
|
|
|
|
: (
|
|
|
|
<span>
|
|
|
|
{intl.formatMessage(intlMessages.profileNotFoundLabel)}
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</span>
|
|
|
|
)
|
2019-09-27 02:28:37 +08:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderContent() {
|
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const {
|
|
|
|
viewState,
|
|
|
|
deviceError,
|
|
|
|
previewError,
|
|
|
|
} = this.state;
|
|
|
|
|
|
|
|
switch (viewState) {
|
|
|
|
case VIEW_STATES.finding:
|
|
|
|
return (
|
|
|
|
<div className={styles.content}>
|
|
|
|
<div className={styles.videoCol}>
|
|
|
|
<div>
|
|
|
|
<span>{intl.formatMessage(intlMessages.findingWebcamsLabel)}</span>
|
|
|
|
<span className={styles.fetchingAnimation} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
case VIEW_STATES.error:
|
|
|
|
return (
|
|
|
|
<div className={styles.content}>
|
|
|
|
<div className={styles.videoCol}><div>{deviceError}</div></div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
case VIEW_STATES.found:
|
|
|
|
default:
|
|
|
|
return (
|
|
|
|
<div className={styles.content}>
|
|
|
|
<div className={styles.videoCol}>
|
|
|
|
{
|
|
|
|
previewError
|
|
|
|
? (
|
|
|
|
<div>{previewError}</div>
|
|
|
|
)
|
|
|
|
: (
|
|
|
|
<video
|
|
|
|
id="preview"
|
2020-03-05 03:00:45 +08:00
|
|
|
data-test="videoPreview"
|
2019-09-27 02:28:37 +08:00
|
|
|
className={styles.preview}
|
|
|
|
ref={(ref) => { this.video = ref; }}
|
|
|
|
autoPlay
|
|
|
|
playsInline
|
|
|
|
muted
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
{this.renderDeviceSelectors()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderModalContent() {
|
|
|
|
const {
|
|
|
|
intl,
|
2019-11-21 01:17:42 +08:00
|
|
|
skipVideoPreview,
|
2019-12-19 01:44:56 +08:00
|
|
|
sharedDevices,
|
2019-09-27 02:28:37 +08:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const {
|
2019-01-18 00:33:43 +08:00
|
|
|
isStartSharingDisabled,
|
2019-12-19 01:44:56 +08:00
|
|
|
webcamDeviceId,
|
2019-11-21 01:17:42 +08:00
|
|
|
deviceError,
|
|
|
|
previewError,
|
2019-01-18 00:33:43 +08:00
|
|
|
} = this.state;
|
2019-11-21 01:17:42 +08:00
|
|
|
const shouldDisableButtons = skipVideoPreview && !(deviceError || previewError);
|
2019-12-19 01:44:56 +08:00
|
|
|
|
|
|
|
const shared = sharedDevices.includes(webcamDeviceId);
|
|
|
|
|
2018-11-07 07:10:56 +08:00
|
|
|
return (
|
2019-06-28 00:02:42 +08:00
|
|
|
<div>
|
2019-05-07 22:29:47 +08:00
|
|
|
{browser().name === 'edge' || browser().name === 'ie' ? (
|
|
|
|
<p className={styles.browserWarning}>
|
|
|
|
<FormattedMessage
|
|
|
|
id="app.audioModal.unsupportedBrowserLabel"
|
|
|
|
description="Warning when someone joins with a browser that isnt supported"
|
|
|
|
values={{
|
|
|
|
0: <a href="https://www.google.com/chrome/">Chrome</a>,
|
|
|
|
1: <a href="https://getfirefox.com">Firefox</a>,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</p>
|
2019-07-24 06:24:31 +08:00
|
|
|
) : null}
|
2018-12-03 14:01:19 +08:00
|
|
|
<div className={styles.title}>
|
|
|
|
{intl.formatMessage(intlMessages.webcamSettingsTitle)}
|
|
|
|
</div>
|
2019-09-27 02:28:37 +08:00
|
|
|
|
|
|
|
{this.renderContent()}
|
2019-05-07 22:29:47 +08:00
|
|
|
|
2018-12-03 14:01:19 +08:00
|
|
|
<div className={styles.footer}>
|
|
|
|
<div className={styles.actions}>
|
|
|
|
<Button
|
|
|
|
label={intl.formatMessage(intlMessages.cancelLabel)}
|
|
|
|
onClick={this.handleProceed}
|
2019-11-21 01:17:42 +08:00
|
|
|
disabled={shouldDisableButtons}
|
2018-12-03 14:01:19 +08:00
|
|
|
/>
|
|
|
|
<Button
|
2020-03-05 03:00:45 +08:00
|
|
|
data-test="startSharingWebcam"
|
2019-12-19 01:44:56 +08:00
|
|
|
color={shared ? "danger" : "primary"}
|
|
|
|
label={intl.formatMessage(shared ? intlMessages.stopSharingLabel : intlMessages.startSharingLabel)}
|
|
|
|
onClick={shared ? this.handleStopSharing : this.handleStartSharing}
|
2019-11-21 01:17:42 +08:00
|
|
|
disabled={isStartSharingDisabled || isStartSharingDisabled === null || shouldDisableButtons}
|
2018-12-03 14:01:19 +08:00
|
|
|
/>
|
2018-11-07 07:10:56 +08:00
|
|
|
</div>
|
2018-12-03 14:01:19 +08:00
|
|
|
</div>
|
2019-06-28 00:02:42 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
hasMediaDevices,
|
2019-11-21 01:17:42 +08:00
|
|
|
skipVideoPreview,
|
2019-06-28 00:02:42 +08:00
|
|
|
} = this.props;
|
2019-11-21 01:17:42 +08:00
|
|
|
const {
|
|
|
|
deviceError,
|
|
|
|
previewError,
|
|
|
|
} = this.state;
|
|
|
|
|
|
|
|
const allowCloseModal = !!(deviceError || previewError) || !skipVideoPreview;
|
2019-06-28 00:02:42 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
overlayClassName={styles.overlay}
|
|
|
|
className={styles.modal}
|
|
|
|
onRequestClose={this.handleProceed}
|
|
|
|
hideBorder
|
|
|
|
contentLabel={intl.formatMessage(intlMessages.webcamSettingsTitle)}
|
2019-11-21 01:17:42 +08:00
|
|
|
shouldShowCloseButton={allowCloseModal}
|
|
|
|
shouldCloseOnOverlayClick={allowCloseModal}
|
2019-06-28 00:02:42 +08:00
|
|
|
>
|
2019-07-24 06:24:31 +08:00
|
|
|
{hasMediaDevices
|
2019-06-28 00:02:42 +08:00
|
|
|
? this.renderModalContent()
|
|
|
|
: this.supportWarning()
|
2019-07-24 06:24:31 +08:00
|
|
|
}
|
2018-12-03 14:01:19 +08:00
|
|
|
</Modal>
|
2018-11-07 07:10:56 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoPreview.propTypes = propTypes;
|
2019-07-24 06:24:31 +08:00
|
|
|
VideoPreview.defaultProps = defaultProps;
|
2018-11-07 07:10:56 +08:00
|
|
|
|
|
|
|
export default injectIntl(VideoPreview);
|