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

Prejoin.tsx 16KB

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