123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- // @flow
-
- import InlineDialog from '@atlaskit/inline-dialog';
- import React, { Component } from 'react';
-
- import { getRoomName } from '../../base/conference';
- import { translate } from '../../base/i18n';
- import { Icon, IconArrowDown, IconArrowUp, IconPhone, IconVolumeOff } from '../../base/icons';
- import { isVideoMutedByUser } from '../../base/media';
- import { ActionButton, InputField, PreMeetingScreen, ToggleButton } from '../../base/premeeting';
- import { connect } from '../../base/redux';
- import { getDisplayName, updateSettings } from '../../base/settings';
- import { getLocalJitsiVideoTrack } from '../../base/tracks';
- import {
- joinConference as joinConferenceAction,
- joinConferenceWithoutAudio as joinConferenceWithoutAudioAction,
- setSkipPrejoin as setSkipPrejoinAction,
- setJoinByPhoneDialogVisiblity as setJoinByPhoneDialogVisiblityAction
- } from '../actions';
- import {
- isDeviceStatusVisible,
- isDisplayNameRequired,
- isJoinByPhoneButtonVisible,
- isJoinByPhoneDialogVisible,
- isPrejoinSkipped
- } from '../functions';
-
- import JoinByPhoneDialog from './dialogs/JoinByPhoneDialog';
-
- type Props = {
-
- /**
- * Flag signaling if the 'skip prejoin' button is toggled or not.
- */
- buttonIsToggled: boolean,
-
- /**
- * Flag signaling if the device status is visible or not.
- */
- deviceStatusVisible: boolean,
-
- /**
- * If join by phone button should be visible.
- */
- hasJoinByPhoneButton: boolean,
-
- /**
- * Joins the current meeting.
- */
- joinConference: Function,
-
- /**
- * Joins the current meeting without audio.
- */
- joinConferenceWithoutAudio: Function,
-
- /**
- * The name of the user that is about to join.
- */
- name: string,
-
- /**
- * Updates settings.
- */
- updateSettings: Function,
-
- /**
- * The name of the meeting that is about to be joined.
- */
- roomName: string,
-
- /**
- * Sets visibility of the prejoin page for the next sessions.
- */
- setSkipPrejoin: Function,
-
- /**
- * Sets visibility of the 'JoinByPhoneDialog'.
- */
- setJoinByPhoneDialogVisiblity: Function,
-
- /**
- * Flag signaling the visibility of camera preview.
- */
- showCameraPreview: boolean,
-
- /**
- * If should show an error when joining without a name.
- */
- showErrorOnJoin: boolean,
-
- /**
- * If 'JoinByPhoneDialog' is visible or not.
- */
- showDialog: boolean,
-
- /**
- * Used for translation.
- */
- t: Function,
-
- /**
- * The JitsiLocalTrack to display.
- */
- videoTrack: ?Object
- };
-
- type State = {
-
- /**
- * Flag controlling the visibility of the error label.
- */
- showError: boolean,
-
- /**
- * Flag controlling the visibility of the 'join by phone' buttons.
- */
- showJoinByPhoneButtons: boolean
- }
-
- /**
- * This component is displayed before joining a meeting.
- */
- class Prejoin extends Component<Props, State> {
- /**
- * Initializes a new {@code Prejoin} instance.
- *
- * @inheritdoc
- */
- constructor(props) {
- super(props);
-
- this.state = {
- showError: false,
- showJoinByPhoneButtons: false
- };
-
- this._closeDialog = this._closeDialog.bind(this);
- this._showDialog = this._showDialog.bind(this);
- this._onJoinButtonClick = this._onJoinButtonClick.bind(this);
- this._onToggleButtonClick = this._onToggleButtonClick.bind(this);
- this._onDropdownClose = this._onDropdownClose.bind(this);
- this._onOptionsClick = this._onOptionsClick.bind(this);
- this._setName = this._setName.bind(this);
- this._onJoinConferenceWithoutAudioKeyPress = this._onJoinConferenceWithoutAudioKeyPress.bind(this);
- this._showDialogKeyPress = this._showDialogKeyPress.bind(this);
- this._onJoinKeyPress = this._onJoinKeyPress.bind(this);
- }
- _onJoinButtonClick: () => void;
-
- /**
- * Handler for the join button.
- *
- * @param {Object} e - The synthetic event.
- * @returns {void}
- */
- _onJoinButtonClick() {
- if (this.props.showErrorOnJoin) {
- this.setState({
- showError: true
- });
-
- return;
- }
-
- this.setState({ showError: false });
- this.props.joinConference();
- }
-
- _onJoinKeyPress: (Object) => void;
-
- /**
- * KeyPress handler for accessibility.
- *
- * @param {Object} e - The key event to handle.
- *
- * @returns {void}
- */
- _onJoinKeyPress(e) {
- if (e.key === ' ' || e.key === 'Enter') {
- e.preventDefault();
- this._onJoinButtonClick();
- }
- }
-
- _onToggleButtonClick: () => void;
-
- /**
- * Handler for the toggle button.
- *
- * @param {Object} e - The synthetic event.
- * @returns {void}
- */
- _onToggleButtonClick() {
- this.props.setSkipPrejoin(!this.props.buttonIsToggled);
- }
-
- _onDropdownClose: () => void;
-
- /**
- * Closes the dropdown.
- *
- * @returns {void}
- */
- _onDropdownClose() {
- this.setState({
- showJoinByPhoneButtons: false
- });
- }
-
- _onOptionsClick: () => void;
-
- /**
- * Displays the join by phone buttons dropdown.
- *
- * @param {Object} e - The synthetic event.
- * @returns {void}
- */
- _onOptionsClick(e) {
- e.stopPropagation();
-
- this.setState({
- showJoinByPhoneButtons: !this.state.showJoinByPhoneButtons
- });
- }
-
- _setName: () => void;
-
- /**
- * Sets the guest participant name.
- *
- * @param {string} displayName - Participant name.
- * @returns {void}
- */
- _setName(displayName) {
- this.props.updateSettings({
- displayName
- });
- }
-
- _closeDialog: () => void;
-
- /**
- * Closes the join by phone dialog.
- *
- * @returns {undefined}
- */
- _closeDialog() {
- this.props.setJoinByPhoneDialogVisiblity(false);
- }
-
- _showDialog: () => void;
-
- /**
- * Displays the dialog for joining a meeting by phone.
- *
- * @returns {undefined}
- */
- _showDialog() {
- this.props.setJoinByPhoneDialogVisiblity(true);
- this._onDropdownClose();
- }
-
- _showDialogKeyPress: (Object) => void;
-
- /**
- * KeyPress handler for accessibility.
- *
- * @param {Object} e - The key event to handle.
- *
- * @returns {void}
- */
- _showDialogKeyPress(e) {
- if (e.key === ' ' || e.key === 'Enter') {
- e.preventDefault();
- this._showDialog();
- }
- }
-
- _onJoinConferenceWithoutAudioKeyPress: (Object) => void;
-
- /**
- * KeyPress handler for accessibility.
- *
- * @param {Object} e - The key event to handle.
- *
- * @returns {void}
- */
- _onJoinConferenceWithoutAudioKeyPress(e) {
- if (this.props.joinConferenceWithoutAudio
- && (e.key === ' '
- || e.key === 'Enter')) {
- e.preventDefault();
- this.props.joinConferenceWithoutAudio();
- }
- }
-
- /**
- * Implements React's {@link Component#render()}.
- *
- * @inheritdoc
- * @returns {ReactElement}
- */
- render() {
- const {
- deviceStatusVisible,
- hasJoinByPhoneButton,
- joinConference,
- joinConferenceWithoutAudio,
- name,
- showCameraPreview,
- showDialog,
- t,
- videoTrack
- } = this.props;
-
- const { _closeDialog, _onDropdownClose, _onJoinButtonClick, _onJoinKeyPress, _showDialogKeyPress,
- _onJoinConferenceWithoutAudioKeyPress, _onOptionsClick, _setName, _showDialog } = this;
- const { showJoinByPhoneButtons, showError } = this.state;
-
- return (
- <PreMeetingScreen
- showDeviceStatus = { deviceStatusVisible }
- skipPrejoinButton = { this._renderSkipPrejoinButton() }
- title = { t('prejoin.joinMeeting') }
- videoMuted = { !showCameraPreview }
- videoTrack = { videoTrack }>
- <div
- className = 'prejoin-input-area'
- data-testid = 'prejoin.screen'>
- <InputField
- autoComplete = { 'name' }
- autoFocus = { true }
- className = { showError ? 'error' : '' }
- hasError = { showError }
- onChange = { _setName }
- onSubmit = { joinConference }
- placeHolder = { t('dialog.enterDisplayName') }
- value = { name } />
-
- {showError && <div
- className = 'prejoin-error'
- data-testid = 'prejoin.errorMessage'>{t('prejoin.errorMissingName')}</div>}
-
- <div className = 'prejoin-preview-dropdown-container'>
- <InlineDialog
- content = { <div className = 'prejoin-preview-dropdown-btns'>
- <div
- className = 'prejoin-preview-dropdown-btn'
- data-testid = 'prejoin.joinWithoutAudio'
- onClick = { joinConferenceWithoutAudio }
- onKeyPress = { _onJoinConferenceWithoutAudioKeyPress }
- role = 'button'
- tabIndex = { 0 }>
- <Icon
- className = 'prejoin-preview-dropdown-icon'
- size = { 24 }
- src = { IconVolumeOff } />
- { t('prejoin.joinWithoutAudio') }
- </div>
- {hasJoinByPhoneButton && <div
- className = 'prejoin-preview-dropdown-btn'
- onClick = { _showDialog }
- onKeyPress = { _showDialogKeyPress }
- role = 'button'
- tabIndex = { 0 }>
- <Icon
- className = 'prejoin-preview-dropdown-icon'
- data-testid = 'prejoin.joinByPhone'
- size = { 24 }
- src = { IconPhone } />
- { t('prejoin.joinAudioByPhone') }
- </div>}
- </div> }
- isOpen = { showJoinByPhoneButtons }
- onClose = { _onDropdownClose }>
- <ActionButton
- OptionsIcon = { showJoinByPhoneButtons ? IconArrowUp : IconArrowDown }
- ariaDropDownLabel = { t('prejoin.joinWithoutAudio') }
- ariaLabel = { t('prejoin.joinMeeting') }
- ariaPressed = { showJoinByPhoneButtons }
- hasOptions = { true }
- onClick = { _onJoinButtonClick }
- onKeyPress = { _onJoinKeyPress }
- onOptionsClick = { _onOptionsClick }
- role = 'button'
- tabIndex = { 0 }
- testId = 'prejoin.joinMeeting'
- type = 'primary'>
- { t('prejoin.joinMeeting') }
- </ActionButton>
- </InlineDialog>
- </div>
- </div>
- { showDialog && (
- <JoinByPhoneDialog
- joinConferenceWithoutAudio = { joinConferenceWithoutAudio }
- onClose = { _closeDialog } />
- )}
- </PreMeetingScreen>
- );
- }
-
- /**
- * Renders the 'skip prejoin' button.
- *
- * @returns {React$Element}
- */
- _renderSkipPrejoinButton() {
- const { buttonIsToggled, t } = this.props;
-
- return (
- <div className = 'prejoin-checkbox-container'>
- <ToggleButton
- isToggled = { buttonIsToggled }
- onClick = { this._onToggleButtonClick }>
- {t('prejoin.doNotShow')}
- </ToggleButton>
- </div>
- );
- }
- }
-
- /**
- * Maps (parts of) the redux state to the React {@code Component} props.
- *
- * @param {Object} state - The redux state.
- * @returns {Object}
- */
- function mapStateToProps(state): Object {
- const name = getDisplayName(state);
- const showErrorOnJoin = isDisplayNameRequired(state) && !name;
-
- return {
- buttonIsToggled: isPrejoinSkipped(state),
- name,
- deviceStatusVisible: isDeviceStatusVisible(state),
- roomName: getRoomName(state),
- showDialog: isJoinByPhoneDialogVisible(state),
- showErrorOnJoin,
- hasJoinByPhoneButton: isJoinByPhoneButtonVisible(state),
- showCameraPreview: !isVideoMutedByUser(state),
- videoTrack: getLocalJitsiVideoTrack(state)
- };
- }
-
- const mapDispatchToProps = {
- joinConferenceWithoutAudio: joinConferenceWithoutAudioAction,
- joinConference: joinConferenceAction,
- setJoinByPhoneDialogVisiblity: setJoinByPhoneDialogVisiblityAction,
- setSkipPrejoin: setSkipPrejoinAction,
- updateSettings
- };
-
- export default connect(mapStateToProps, mapDispatchToProps)(translate(Prejoin));
|