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 15KB

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