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

243 lines
7.1 KiB
React
Raw Normal View History

import React, { memo, useEffect, useState } from 'react';
import PropTypes from 'prop-types';
2022-02-15 04:20:50 +08:00
import ButtonEmoji from '/imports/ui/components/common/button/button-emoji/ButtonEmoji';
2019-11-28 21:13:06 +08:00
import VideoService from '../service';
import { defineMessages, injectIntl } from 'react-intl';
import Styled from './styles';
import deviceInfo from '/imports/utils/deviceInfo';
2023-08-10 00:26:42 +08:00
import { debounce } from '/imports/utils/debounce';
import BBBMenu from '/imports/ui/components/common/menu/component';
2022-08-26 22:50:46 +08:00
import { isVirtualBackgroundsEnabled } from '/imports/ui/services/features';
2022-06-17 03:59:01 +08:00
import Button from '/imports/ui/components/common/button/component';
import VideoPreviewContainer from '/imports/ui/components/video-preview/container';
import Settings from '/imports/ui/services/settings';
2017-09-20 11:12:10 +08:00
const ENABLE_WEBCAM_SELECTOR_BUTTON = Meteor.settings.public.app.enableWebcamSelectorButton;
2022-08-26 22:50:46 +08:00
const ENABLE_CAMERA_BRIGHTNESS = Meteor.settings.public.app.enableCameraBrightness;
2017-09-20 11:12:10 +08:00
const intlMessages = defineMessages({
videoSettings: {
id: 'app.video.videoSettings',
description: 'Open video settings',
},
visualEffects: {
id: 'app.video.visualEffects',
description: 'Visual effects label',
},
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',
},
camCapReached: {
id: 'app.video.meetingCamCapReached',
description: 'meeting camera cap label',
},
meteorDisconnected: {
2020-09-10 03:31:20 +08:00
id: 'app.video.clientDisconnected',
description: 'Meteor disconnected label',
},
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,
status: PropTypes.string.isRequired,
};
const JoinVideoButton = ({
intl,
2019-11-28 21:13:06 +08:00
hasVideoStream,
status,
disableReason,
updateSettings,
}) => {
const { isMobile } = deviceInfo;
const isMobileSharingCamera = hasVideoStream && isMobile;
const isDesktopSharingCamera = hasVideoStream && !isMobile;
const shouldEnableWebcamSelectorButton = ENABLE_WEBCAM_SELECTOR_BUTTON
&& isDesktopSharingCamera;
const shouldEnableWebcamVisualEffectsButton = (isVirtualBackgroundsEnabled()
|| ENABLE_CAMERA_BRIGHTNESS)
&& hasVideoStream
&& !isMobile;
const exitVideo = () => isDesktopSharingCamera && (!VideoService.isMultipleCamerasEnabled()
|| shouldEnableWebcamSelectorButton);
2019-12-19 01:44:56 +08:00
const [propsToPassModal, setPropsToPassModal] = useState({});
const [forceOpen, setForceOpen] = useState(false);
const [isVideoPreviewModalOpen, setVideoPreviewModalIsOpen] = useState(false);
const [wasSelfViewDisabled, setWasSelfViewDisabled] = useState(false);
useEffect(() => {
2023-05-30 02:02:29 +08:00
const isSelfViewDisabled = Settings.application.selfViewDisable;
if (isVideoPreviewModalOpen && isSelfViewDisabled) {
setWasSelfViewDisabled(true);
const obj = {
application:
{ ...Settings.application, selfViewDisable: false },
};
updateSettings(obj);
}
}, [isVideoPreviewModalOpen]);
2023-08-10 00:26:42 +08:00
const handleOnClick = debounce(() => {
switch (status) {
case 'videoConnecting':
VideoService.stopVideo();
break;
case 'connected':
default:
if (exitVideo()) {
VideoService.exitVideo();
} else {
setForceOpen(isMobileSharingCamera);
setVideoPreviewModalIsOpen(true);
}
2019-12-19 01:44:56 +08:00
}
2023-08-10 00:26:42 +08:00
}, JOIN_VIDEO_DELAY_MILLISECONDS);
const handleOpenAdvancedOptions = (callback) => {
if (callback) callback();
setForceOpen(isDesktopSharingCamera);
setVideoPreviewModalIsOpen(true);
};
const getMessageFromStatus = () => {
let statusMessage = status;
if (status !== 'videoConnecting') {
statusMessage = exitVideo() ? 'leaveVideo' : 'joinVideo';
}
return statusMessage;
};
const label = disableReason
? intl.formatMessage(intlMessages[disableReason])
: intl.formatMessage(intlMessages[getMessageFromStatus()]);
const isSharing = hasVideoStream || status === 'videoConnecting';
const renderUserActions = () => {
const actions = [];
if (shouldEnableWebcamSelectorButton) {
actions.push(
{
key: 'advancedVideo',
label: intl.formatMessage(intlMessages.advancedVideo),
onClick: () => handleOpenAdvancedOptions(),
dataTest: 'advancedVideoSettingsButton',
},
);
}
2022-08-26 22:50:46 +08:00
if (shouldEnableWebcamVisualEffectsButton) {
actions.push(
{
key: 'virtualBgSelection',
label: intl.formatMessage(intlMessages.visualEffects),
onClick: () => handleOpenAdvancedOptions((
) => setPropsToPassModal({ isVisualEffects: true })),
},
);
}
if (actions.length === 0) return null;
2022-10-25 01:20:49 +08:00
const customStyles = { top: '-3.6rem' };
return (
<BBBMenu
2022-10-25 01:20:49 +08:00
customStyles={!isMobile ? customStyles : null}
trigger={(
<ButtonEmoji
emoji="device_list_selector"
data-test="videoDropdownMenu"
hideLabel
label={intl.formatMessage(intlMessages.videoSettings)}
rotate
2022-10-04 22:21:52 +08:00
tabIndex={0}
/>
)}
actions={actions}
2022-10-25 01:20:49 +08:00
opts={{
id: 'video-dropdown-menu',
2022-10-25 01:20:49 +08:00
keepMounted: true,
transitionDuration: 0,
elevation: 3,
2023-05-10 09:31:48 +08:00
getcontentanchorel: null,
fullwidth: 'true',
2022-10-25 01:20:49 +08:00
anchorOrigin: { vertical: 'top', horizontal: 'center' },
transformOrigin: { vertical: 'top', horizontal: 'center' },
}}
/>
);
};
return (
<>
<Styled.OffsetBottom>
<Button
label={label}
data-test={hasVideoStream ? 'leaveVideo' : 'joinVideo'}
onClick={handleOnClick}
hideLabel
color={isSharing ? 'primary' : 'default'}
icon={isSharing ? 'video' : 'video_off'}
ghost={!isSharing}
size="lg"
circle
disabled={!!disableReason}
/>
{renderUserActions()}
</Styled.OffsetBottom>
2023-05-26 21:19:29 +08:00
{isVideoPreviewModalOpen ? (
<VideoPreviewContainer
{...{
callbackToClose: () => {
if (wasSelfViewDisabled) {
2023-05-30 02:02:29 +08:00
setTimeout(() => {
const obj = {
application:
{ ...Settings.application, selfViewDisable: true },
};
updateSettings(obj);
setWasSelfViewDisabled(false);
}, 100);
}
setPropsToPassModal({});
setForceOpen(false);
},
forceOpen,
2023-05-30 02:02:29 +08:00
priority: 'low',
setIsOpen: setVideoPreviewModalIsOpen,
2023-05-30 02:02:29 +08:00
isOpen: isVideoPreviewModalOpen,
}}
{...propsToPassModal}
2023-05-26 21:19:29 +08:00
/>
) : null}
</>
);
};
JoinVideoButton.propTypes = propTypes;
2019-12-19 01:44:56 +08:00
export default injectIntl(memo(JoinVideoButton));