89 lines
2.3 KiB
JavaScript
Executable File
89 lines
2.3 KiB
JavaScript
Executable File
import React, { memo } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import VideoService from '../service';
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
import Styled from './styles';
|
|
import { validIOSVersion } from '/imports/ui/components/app/service';
|
|
import { debounce } from 'lodash';
|
|
|
|
const intlMessages = defineMessages({
|
|
joinVideo: {
|
|
id: 'app.video.joinVideo',
|
|
description: 'Join video button label',
|
|
},
|
|
leaveVideo: {
|
|
id: 'app.video.leaveVideo',
|
|
description: 'Leave video button label',
|
|
},
|
|
videoLocked: {
|
|
id: 'app.video.videoLocked',
|
|
description: 'video disabled label',
|
|
},
|
|
videoConnecting: {
|
|
id: 'app.video.connecting',
|
|
description: 'video connecting label',
|
|
},
|
|
meteorDisconnected: {
|
|
id: 'app.video.clientDisconnected',
|
|
description: 'Meteor disconnected label',
|
|
},
|
|
iOSWarning: {
|
|
id: 'app.iOSWarning.label',
|
|
description: 'message indicating to upgrade ios version',
|
|
},
|
|
});
|
|
|
|
const JOIN_VIDEO_DELAY_MILLISECONDS = 500;
|
|
|
|
const propTypes = {
|
|
intl: PropTypes.object.isRequired,
|
|
hasVideoStream: PropTypes.bool.isRequired,
|
|
mountVideoPreview: PropTypes.func.isRequired,
|
|
};
|
|
|
|
const JoinVideoButton = ({
|
|
intl,
|
|
hasVideoStream,
|
|
disableReason,
|
|
mountVideoPreview,
|
|
}) => {
|
|
const exitVideo = () => hasVideoStream && !VideoService.isMultipleCamerasEnabled();
|
|
|
|
const handleOnClick = debounce(() => {
|
|
if (!validIOSVersion()) {
|
|
return VideoService.notify(intl.formatMessage(intlMessages.iOSWarning));
|
|
}
|
|
|
|
if (exitVideo()) {
|
|
VideoService.exitVideo();
|
|
} else {
|
|
mountVideoPreview();
|
|
}
|
|
}, JOIN_VIDEO_DELAY_MILLISECONDS);
|
|
|
|
let label = exitVideo()
|
|
? intl.formatMessage(intlMessages.leaveVideo)
|
|
: intl.formatMessage(intlMessages.joinVideo);
|
|
|
|
if (disableReason) label = intl.formatMessage(intlMessages[disableReason]);
|
|
|
|
return (
|
|
<Styled.VideoButton
|
|
label={label}
|
|
data-test={hasVideoStream ? 'leaveVideo' : 'joinVideo'}
|
|
onClick={handleOnClick}
|
|
hideLabel
|
|
color={hasVideoStream ? 'primary' : 'default'}
|
|
icon={hasVideoStream ? 'video' : 'video_off'}
|
|
ghost={!hasVideoStream}
|
|
size="lg"
|
|
circle
|
|
disabled={!!disableReason}
|
|
/>
|
|
);
|
|
};
|
|
|
|
JoinVideoButton.propTypes = propTypes;
|
|
|
|
export default injectIntl(memo(JoinVideoButton));
|