Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Prejoin.tsx 16KB

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