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

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