Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Prejoin.tsx 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /* eslint-disable react/jsx-no-bind */
  2. import React, { useMemo, useState } from 'react';
  3. import { useTranslation } from 'react-i18next';
  4. import { connect, useDispatch } from 'react-redux';
  5. import { makeStyles } from 'tss-react/mui';
  6. import { IReduxState } from '../../../app/types';
  7. import Avatar from '../../../base/avatar/components/Avatar';
  8. import { isNameReadOnly } from '../../../base/config/functions.web';
  9. import { IconArrowDown, IconArrowUp, IconPhoneRinging, IconVolumeOff } from '../../../base/icons/svg';
  10. import { isVideoMutedByUser } from '../../../base/media/functions';
  11. import { getLocalParticipant } from '../../../base/participants/functions';
  12. import Popover from '../../../base/popover/components/Popover.web';
  13. import ActionButton from '../../../base/premeeting/components/web/ActionButton';
  14. import PreMeetingScreen from '../../../base/premeeting/components/web/PreMeetingScreen';
  15. import { updateSettings } from '../../../base/settings/actions';
  16. import { getDisplayName } from '../../../base/settings/functions.web';
  17. import { withPixelLineHeight } from '../../../base/styles/functions.web';
  18. import { getLocalJitsiVideoTrack } from '../../../base/tracks/functions.web';
  19. import Button from '../../../base/ui/components/web/Button';
  20. import Input from '../../../base/ui/components/web/Input';
  21. import { BUTTON_TYPES } from '../../../base/ui/constants.any';
  22. import isInsecureRoomName from '../../../base/util/isInsecureRoomName';
  23. import { openDisplayNamePrompt } from '../../../display-name/actions';
  24. import { isUnsafeRoomWarningEnabled } from '../../../prejoin/functions';
  25. import {
  26. joinConference as joinConferenceAction,
  27. joinConferenceWithoutAudio as joinConferenceWithoutAudioAction,
  28. setJoinByPhoneDialogVisiblity as setJoinByPhoneDialogVisiblityAction
  29. } from '../../actions.web';
  30. import {
  31. isDeviceStatusVisible,
  32. isDisplayNameRequired,
  33. isJoinByPhoneButtonVisible,
  34. isJoinByPhoneDialogVisible,
  35. isPrejoinDisplayNameVisible
  36. } from '../../functions';
  37. import logger from '../../logger';
  38. import { hasDisplayName } from '../../utils';
  39. import JoinByPhoneDialog from './dialogs/JoinByPhoneDialog';
  40. interface IProps {
  41. /**
  42. * Flag signaling if the device status is visible or not.
  43. */
  44. deviceStatusVisible: boolean;
  45. /**
  46. * If join by phone button should be visible.
  47. */
  48. hasJoinByPhoneButton: boolean;
  49. /**
  50. * Flag signaling if the display name is visible or not.
  51. */
  52. isDisplayNameVisible: boolean;
  53. /**
  54. * Joins the current meeting.
  55. */
  56. joinConference: Function;
  57. /**
  58. * Joins the current meeting without audio.
  59. */
  60. joinConferenceWithoutAudio: Function;
  61. /**
  62. * Whether conference join is in progress.
  63. */
  64. joiningInProgress?: boolean;
  65. /**
  66. * The name of the user that is about to join.
  67. */
  68. name: string;
  69. /**
  70. * Local participant id.
  71. */
  72. participantId?: string;
  73. /**
  74. * The prejoin config.
  75. */
  76. prejoinConfig?: any;
  77. /**
  78. * Whether the name input should be read only or not.
  79. */
  80. readOnlyName: boolean;
  81. /**
  82. * Sets visibility of the 'JoinByPhoneDialog'.
  83. */
  84. setJoinByPhoneDialogVisiblity: Function;
  85. /**
  86. * Flag signaling the visibility of camera preview.
  87. */
  88. showCameraPreview: boolean;
  89. /**
  90. * If 'JoinByPhoneDialog' is visible or not.
  91. */
  92. showDialog: boolean;
  93. /**
  94. * If should show an error when joining without a name.
  95. */
  96. showErrorOnJoin: boolean;
  97. /**
  98. * If the recording warning is visible or not.
  99. */
  100. showRecordingWarning: boolean;
  101. /**
  102. * If should show unsafe room warning when joining.
  103. */
  104. showUnsafeRoomWarning: boolean;
  105. /**
  106. * Whether the user has approved to join a room with unsafe name.
  107. */
  108. unsafeRoomConsent?: boolean;
  109. /**
  110. * Updates settings.
  111. */
  112. updateSettings: Function;
  113. /**
  114. * The JitsiLocalTrack to display.
  115. */
  116. videoTrack?: Object;
  117. }
  118. const useStyles = makeStyles()(theme => {
  119. return {
  120. inputContainer: {
  121. width: '100%'
  122. },
  123. input: {
  124. width: '100%',
  125. marginBottom: theme.spacing(3),
  126. '& input': {
  127. textAlign: 'center'
  128. }
  129. },
  130. avatarContainer: {
  131. display: 'flex',
  132. alignItems: 'center',
  133. flexDirection: 'column'
  134. },
  135. avatar: {
  136. margin: `${theme.spacing(2)} auto ${theme.spacing(3)}`
  137. },
  138. avatarName: {
  139. ...withPixelLineHeight(theme.typography.bodyShortBoldLarge),
  140. color: theme.palette.text01,
  141. marginBottom: theme.spacing(5),
  142. textAlign: 'center'
  143. },
  144. error: {
  145. backgroundColor: theme.palette.actionDanger,
  146. color: theme.palette.text01,
  147. borderRadius: theme.shape.borderRadius,
  148. width: '100%',
  149. ...withPixelLineHeight(theme.typography.labelRegular),
  150. boxSizing: 'border-box',
  151. padding: theme.spacing(1),
  152. textAlign: 'center',
  153. marginTop: `-${theme.spacing(2)}`,
  154. marginBottom: theme.spacing(3)
  155. },
  156. dropdownContainer: {
  157. position: 'relative',
  158. width: '100%'
  159. },
  160. dropdownButtons: {
  161. width: '300px',
  162. padding: '8px 0',
  163. backgroundColor: theme.palette.action02,
  164. color: theme.palette.text04,
  165. borderRadius: theme.shape.borderRadius,
  166. position: 'relative',
  167. top: `-${theme.spacing(3)}`,
  168. '@media (max-width: 511px)': {
  169. margin: '0 auto',
  170. top: 0
  171. },
  172. '@media (max-width: 420px)': {
  173. top: 0,
  174. width: 'calc(100% - 32px)'
  175. }
  176. }
  177. };
  178. });
  179. const Prejoin = ({
  180. deviceStatusVisible,
  181. hasJoinByPhoneButton,
  182. isDisplayNameVisible,
  183. joinConference,
  184. joinConferenceWithoutAudio,
  185. joiningInProgress,
  186. name,
  187. participantId,
  188. prejoinConfig,
  189. readOnlyName,
  190. setJoinByPhoneDialogVisiblity,
  191. showCameraPreview,
  192. showDialog,
  193. showErrorOnJoin,
  194. showRecordingWarning,
  195. showUnsafeRoomWarning,
  196. unsafeRoomConsent,
  197. updateSettings: dispatchUpdateSettings,
  198. videoTrack
  199. }: IProps) => {
  200. const showDisplayNameField = useMemo(
  201. () => isDisplayNameVisible && !readOnlyName,
  202. [ isDisplayNameVisible, readOnlyName ]);
  203. const showErrorOnField = useMemo(
  204. () => showDisplayNameField && showErrorOnJoin,
  205. [ showDisplayNameField, showErrorOnJoin ]);
  206. const [ showJoinByPhoneButtons, setShowJoinByPhoneButtons ] = useState(false);
  207. const { classes } = useStyles();
  208. const { t } = useTranslation();
  209. const dispatch = useDispatch();
  210. /**
  211. * Handler for the join button.
  212. *
  213. * @param {Object} e - The synthetic event.
  214. * @returns {void}
  215. */
  216. const onJoinButtonClick = () => {
  217. if (showErrorOnJoin) {
  218. dispatch(openDisplayNamePrompt({
  219. onPostSubmit: joinConference,
  220. validateInput: hasDisplayName
  221. }));
  222. return;
  223. }
  224. logger.info('Prejoin join button clicked.');
  225. joinConference();
  226. };
  227. /**
  228. * Closes the dropdown.
  229. *
  230. * @returns {void}
  231. */
  232. const onDropdownClose = () => {
  233. setShowJoinByPhoneButtons(false);
  234. };
  235. /**
  236. * Displays the join by phone buttons dropdown.
  237. *
  238. * @param {Object} e - The synthetic event.
  239. * @returns {void}
  240. */
  241. const onOptionsClick = (e?: React.KeyboardEvent | React.MouseEvent | undefined) => {
  242. e?.stopPropagation();
  243. setShowJoinByPhoneButtons(show => !show);
  244. };
  245. /**
  246. * Sets the guest participant name.
  247. *
  248. * @param {string} displayName - Participant name.
  249. * @returns {void}
  250. */
  251. const setName = (displayName: string) => {
  252. dispatchUpdateSettings({
  253. displayName
  254. });
  255. };
  256. /**
  257. * Closes the join by phone dialog.
  258. *
  259. * @returns {undefined}
  260. */
  261. const closeDialog = () => {
  262. setJoinByPhoneDialogVisiblity(false);
  263. };
  264. /**
  265. * Displays the dialog for joining a meeting by phone.
  266. *
  267. * @returns {undefined}
  268. */
  269. const doShowDialog = () => {
  270. setJoinByPhoneDialogVisiblity(true);
  271. onDropdownClose();
  272. };
  273. /**
  274. * KeyPress handler for accessibility.
  275. *
  276. * @param {Object} e - The key event to handle.
  277. *
  278. * @returns {void}
  279. */
  280. const showDialogKeyPress = (e: React.KeyboardEvent) => {
  281. if (e.key === ' ' || e.key === 'Enter') {
  282. e.preventDefault();
  283. doShowDialog();
  284. }
  285. };
  286. /**
  287. * KeyPress handler for accessibility.
  288. *
  289. * @param {Object} e - The key event to handle.
  290. *
  291. * @returns {void}
  292. */
  293. const onJoinConferenceWithoutAudioKeyPress = (e: React.KeyboardEvent) => {
  294. if (joinConferenceWithoutAudio
  295. && (e.key === ' '
  296. || e.key === 'Enter')) {
  297. e.preventDefault();
  298. logger.info('Prejoin joinConferenceWithoutAudio dispatched on a key pressed.');
  299. joinConferenceWithoutAudio();
  300. }
  301. };
  302. /**
  303. * Gets the list of extra join buttons.
  304. *
  305. * @returns {Object} - The list of extra buttons.
  306. */
  307. const getExtraJoinButtons = () => {
  308. const noAudio = {
  309. key: 'no-audio',
  310. testId: 'prejoin.joinWithoutAudio',
  311. icon: IconVolumeOff,
  312. label: t('prejoin.joinWithoutAudio'),
  313. onClick: () => {
  314. logger.info('Prejoin join conference without audio pressed.');
  315. joinConferenceWithoutAudio();
  316. },
  317. onKeyPress: onJoinConferenceWithoutAudioKeyPress
  318. };
  319. const byPhone = {
  320. key: 'by-phone',
  321. testId: 'prejoin.joinByPhone',
  322. icon: IconPhoneRinging,
  323. label: t('prejoin.joinAudioByPhone'),
  324. onClick: doShowDialog,
  325. onKeyPress: showDialogKeyPress
  326. };
  327. return {
  328. noAudio,
  329. byPhone
  330. };
  331. };
  332. /**
  333. * Handle keypress on input.
  334. *
  335. * @param {KeyboardEvent} e - Keyboard event.
  336. * @returns {void}
  337. */
  338. const onInputKeyPress = (e: React.KeyboardEvent) => {
  339. if (e.key === 'Enter') {
  340. logger.info('Dispatching join conference on Enter key press from the prejoin screen.');
  341. joinConference();
  342. }
  343. };
  344. const extraJoinButtons = getExtraJoinButtons();
  345. let extraButtonsToRender = Object.values(extraJoinButtons).filter((val: any) =>
  346. !(prejoinConfig?.hideExtraJoinButtons || []).includes(val.key)
  347. );
  348. if (!hasJoinByPhoneButton) {
  349. extraButtonsToRender = extraButtonsToRender.filter((btn: any) => btn.key !== 'by-phone');
  350. }
  351. const hasExtraJoinButtons = Boolean(extraButtonsToRender.length);
  352. return (
  353. <PreMeetingScreen
  354. showDeviceStatus = { deviceStatusVisible }
  355. showRecordingWarning = { showRecordingWarning }
  356. showUnsafeRoomWarning = { showUnsafeRoomWarning }
  357. title = { t('prejoin.joinMeeting') }
  358. videoMuted = { !showCameraPreview }
  359. videoTrack = { videoTrack }>
  360. <div
  361. className = { classes.inputContainer }
  362. data-testid = 'prejoin.screen'>
  363. {showDisplayNameField ? (<Input
  364. accessibilityLabel = { t('dialog.enterDisplayName') }
  365. autoComplete = { 'name' }
  366. autoFocus = { true }
  367. className = { classes.input }
  368. error = { showErrorOnField }
  369. id = 'premeeting-name-input'
  370. onChange = { setName }
  371. onKeyPress = { showUnsafeRoomWarning && !unsafeRoomConsent ? undefined : onInputKeyPress }
  372. placeholder = { t('dialog.enterDisplayName') }
  373. readOnly = { readOnlyName }
  374. value = { name } />
  375. ) : (
  376. <div className = { classes.avatarContainer }>
  377. <Avatar
  378. className = { classes.avatar }
  379. displayName = { name }
  380. participantId = { participantId }
  381. size = { 72 } />
  382. {isDisplayNameVisible && <div className = { classes.avatarName }>{name}</div>}
  383. </div>
  384. )}
  385. {showErrorOnField && <div
  386. className = { classes.error }
  387. data-testid = 'prejoin.errorMessage'>{t('prejoin.errorMissingName')}</div>}
  388. <div className = { classes.dropdownContainer }>
  389. <Popover
  390. content = { hasExtraJoinButtons && <div className = { classes.dropdownButtons }>
  391. {extraButtonsToRender.map(({ key, ...rest }) => (
  392. <Button
  393. disabled = { joiningInProgress || showErrorOnField }
  394. fullWidth = { true }
  395. key = { key }
  396. type = { BUTTON_TYPES.SECONDARY }
  397. { ...rest } />
  398. ))}
  399. </div> }
  400. onPopoverClose = { onDropdownClose }
  401. position = 'bottom'
  402. trigger = 'click'
  403. visible = { showJoinByPhoneButtons }>
  404. <ActionButton
  405. OptionsIcon = { showJoinByPhoneButtons ? IconArrowUp : IconArrowDown }
  406. ariaDropDownLabel = { t('prejoin.joinWithoutAudio') }
  407. ariaLabel = { t('prejoin.joinMeeting') }
  408. ariaPressed = { showJoinByPhoneButtons }
  409. disabled = { joiningInProgress
  410. || (showUnsafeRoomWarning && !unsafeRoomConsent)
  411. || showErrorOnField }
  412. hasOptions = { hasExtraJoinButtons }
  413. onClick = { onJoinButtonClick }
  414. onOptionsClick = { onOptionsClick }
  415. role = 'button'
  416. tabIndex = { 0 }
  417. testId = 'prejoin.joinMeeting'
  418. type = 'primary'>
  419. {t('prejoin.joinMeeting')}
  420. </ActionButton>
  421. </Popover>
  422. </div>
  423. </div>
  424. {showDialog && (
  425. <JoinByPhoneDialog
  426. joinConferenceWithoutAudio = { joinConferenceWithoutAudio }
  427. onClose = { closeDialog } />
  428. )}
  429. </PreMeetingScreen>
  430. );
  431. };
  432. /**
  433. * Maps (parts of) the redux state to the React {@code Component} props.
  434. *
  435. * @param {Object} state - The redux state.
  436. * @returns {Object}
  437. */
  438. function mapStateToProps(state: IReduxState) {
  439. const name = getDisplayName(state);
  440. const showErrorOnJoin = isDisplayNameRequired(state) && !name;
  441. const { id: participantId } = getLocalParticipant(state) ?? {};
  442. const { joiningInProgress } = state['features/prejoin'];
  443. const { room } = state['features/base/conference'];
  444. const { unsafeRoomConsent } = state['features/base/premeeting'];
  445. const { showPrejoinWarning: showRecordingWarning } = state['features/base/config'].recordings ?? {};
  446. return {
  447. deviceStatusVisible: isDeviceStatusVisible(state),
  448. hasJoinByPhoneButton: isJoinByPhoneButtonVisible(state),
  449. isDisplayNameVisible: isPrejoinDisplayNameVisible(state),
  450. joiningInProgress,
  451. name,
  452. participantId,
  453. prejoinConfig: state['features/base/config'].prejoinConfig,
  454. readOnlyName: isNameReadOnly(state),
  455. showCameraPreview: !isVideoMutedByUser(state),
  456. showDialog: isJoinByPhoneDialogVisible(state),
  457. showErrorOnJoin,
  458. showRecordingWarning: Boolean(showRecordingWarning),
  459. showUnsafeRoomWarning: isInsecureRoomName(room) && isUnsafeRoomWarningEnabled(state),
  460. unsafeRoomConsent,
  461. videoTrack: getLocalJitsiVideoTrack(state)
  462. };
  463. }
  464. const mapDispatchToProps = {
  465. joinConferenceWithoutAudio: joinConferenceWithoutAudioAction,
  466. joinConference: joinConferenceAction,
  467. setJoinByPhoneDialogVisiblity: setJoinByPhoneDialogVisiblityAction,
  468. updateSettings
  469. };
  470. export default connect(mapStateToProps, mapDispatchToProps)(Prejoin);