bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/video-provider/video-button/component.jsx

118 lines
3.2 KiB
React
Raw Normal View History

import React, { memo } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
2017-09-20 11:12:10 +08:00
import Button from '/imports/ui/components/button/component';
import ButtonEmoji from '/imports/ui/components/button/button-emoji/ButtonEmoji';
2019-11-28 21:13:06 +08:00
import VideoService from '../service';
import { defineMessages, injectIntl } from 'react-intl';
import { styles } from './styles';
2019-11-28 21:13:06 +08:00
import { validIOSVersion } from '/imports/ui/components/app/service';
2021-02-10 21:29:26 +08:00
import { debounce } from 'lodash';
2017-09-20 11:12:10 +08:00
const intlMessages = defineMessages({
joinVideo: {
id: 'app.video.joinVideo',
description: 'Join video button label',
2017-09-20 11:12:10 +08:00
},
2019-12-19 01:44:56 +08:00
leaveVideo: {
id: 'app.video.leaveVideo',
description: 'Leave video button label',
},
advancedVideo: {
id: 'app.video.advancedVideo',
description: 'Open advanced video label',
},
2019-03-29 22:31:56 +08:00
videoLocked: {
id: 'app.video.videoLocked',
description: 'video disabled label',
2018-03-23 01:02:59 +08:00
},
videoConnecting: {
id: 'app.video.connecting',
description: 'video connecting label',
},
meteorDisconnected: {
2020-09-10 03:31:20 +08:00
id: 'app.video.clientDisconnected',
description: 'Meteor disconnected label',
},
iOSWarning: {
id: 'app.iOSWarning.label',
description: 'message indicating to upgrade ios version',
},
2017-09-20 11:12:10 +08:00
});
2021-02-10 21:29:26 +08:00
const JOIN_VIDEO_DELAY_MILLISECONDS = 500;
const propTypes = {
intl: PropTypes.object.isRequired,
2019-11-28 21:13:06 +08:00
hasVideoStream: PropTypes.bool.isRequired,
2019-12-19 01:44:56 +08:00
mountVideoPreview: PropTypes.func.isRequired,
};
const JoinVideoButton = ({
intl,
2019-11-28 21:13:06 +08:00
hasVideoStream,
disableReason,
2019-12-19 01:44:56 +08:00
mountVideoPreview,
}) => {
const { enableWebcamSelectorButton } = Meteor.settings.public.app;
const exitVideo = () => hasVideoStream
&& (!VideoService.isMultipleCamerasEnabled() || enableWebcamSelectorButton);
2019-12-19 01:44:56 +08:00
2021-02-10 21:29:26 +08:00
const handleOnClick = debounce(() => {
if (!validIOSVersion()) {
return VideoService.notify(intl.formatMessage(intlMessages.iOSWarning));
}
2019-12-19 01:44:56 +08:00
if (exitVideo()) {
VideoService.exitVideo();
} else {
mountVideoPreview();
}
2021-02-10 21:29:26 +08:00
}, JOIN_VIDEO_DELAY_MILLISECONDS);
const handleOpenAdvancedOptions = (e) => {
e.stopPropagation();
mountVideoPreview();
};
let label = exitVideo()
? intl.formatMessage(intlMessages.leaveVideo)
: intl.formatMessage(intlMessages.joinVideo);
if (disableReason) label = intl.formatMessage(intlMessages[disableReason]);
const shouldEnableEmojiButton = enableWebcamSelectorButton;
const renderEmojiButton = () => (
shouldEnableEmojiButton
&& (<ButtonEmoji
onClick={handleOpenAdvancedOptions}
emoji="device_list_selector"
hidden={!hasVideoStream}
label={intl.formatMessage(intlMessages.advancedVideo)}
/>
)
);
return (
<Button
label={label}
data-test={hasVideoStream ? 'leaveVideo' : 'joinVideo'}
2021-01-30 01:23:50 +08:00
className={cx(hasVideoStream || styles.btn)}
2019-11-28 21:13:06 +08:00
onClick={handleOnClick}
hideLabel
2019-11-28 21:13:06 +08:00
color={hasVideoStream ? 'primary' : 'default'}
icon={hasVideoStream ? 'video' : 'video_off'}
ghost={!hasVideoStream}
size="lg"
circle
disabled={!!disableReason}
>
{renderEmojiButton()}
</Button>
);
};
JoinVideoButton.propTypes = propTypes;
2019-12-19 01:44:56 +08:00
export default injectIntl(memo(JoinVideoButton));