You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Prejoin.tsx 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. import InlineDialog from '@atlaskit/inline-dialog';
  2. import React, { Component } from 'react';
  3. import { WithTranslation } from 'react-i18next';
  4. import { IReduxState } from '../../../app/types';
  5. // eslint-disable-next-line lines-around-comment
  6. // @ts-ignore
  7. import { Avatar } from '../../../base/avatar';
  8. import { isNameReadOnly } from '../../../base/config/functions.web';
  9. import { translate } from '../../../base/i18n/functions';
  10. import { IconArrowDown, IconArrowUp, IconPhoneRinging, IconVolumeOff } from '../../../base/icons/svg';
  11. import { isVideoMutedByUser } from '../../../base/media/functions';
  12. import { getLocalParticipant } from '../../../base/participants/functions';
  13. import ActionButton from '../../../base/premeeting/components/web/ActionButton';
  14. import PreMeetingScreen from '../../../base/premeeting/components/web/PreMeetingScreen';
  15. import { connect } from '../../../base/redux/functions';
  16. import { updateSettings } from '../../../base/settings/actions';
  17. import { getDisplayName } from '../../../base/settings/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. // @ts-ignore
  35. import JoinByPhoneDialog from './dialogs/JoinByPhoneDialog';
  36. interface IProps extends WithTranslation {
  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. * Updates settings.
  95. */
  96. updateSettings: Function;
  97. /**
  98. * The JitsiLocalTrack to display.
  99. */
  100. videoTrack?: Object;
  101. }
  102. interface IState {
  103. /**
  104. * Flag controlling the visibility of the 'join by phone' buttons.
  105. */
  106. showJoinByPhoneButtons: boolean;
  107. }
  108. /**
  109. * This component is displayed before joining a meeting.
  110. */
  111. class Prejoin extends Component<IProps, IState> {
  112. showDisplayNameField: boolean;
  113. /**
  114. * Initializes a new {@code Prejoin} instance.
  115. *
  116. * @inheritdoc
  117. */
  118. constructor(props: IProps) {
  119. super(props);
  120. this.state = {
  121. showJoinByPhoneButtons: false
  122. };
  123. this._closeDialog = this._closeDialog.bind(this);
  124. this._showDialog = this._showDialog.bind(this);
  125. this._onJoinButtonClick = this._onJoinButtonClick.bind(this);
  126. this._onDropdownClose = this._onDropdownClose.bind(this);
  127. this._onOptionsClick = this._onOptionsClick.bind(this);
  128. this._setName = this._setName.bind(this);
  129. this._onJoinConferenceWithoutAudioKeyPress = this._onJoinConferenceWithoutAudioKeyPress.bind(this);
  130. this._showDialogKeyPress = this._showDialogKeyPress.bind(this);
  131. this._getExtraJoinButtons = this._getExtraJoinButtons.bind(this);
  132. this._onInputKeyPress = this._onInputKeyPress.bind(this);
  133. this.showDisplayNameField = props.canEditDisplayName || props.showErrorOnJoin;
  134. }
  135. /**
  136. * Handler for the join button.
  137. *
  138. * @param {Object} e - The synthetic event.
  139. * @returns {void}
  140. */
  141. _onJoinButtonClick() {
  142. if (this.props.showErrorOnJoin) {
  143. return;
  144. }
  145. this.props.joinConference();
  146. }
  147. /**
  148. * Closes the dropdown.
  149. *
  150. * @returns {void}
  151. */
  152. _onDropdownClose() {
  153. this.setState({
  154. showJoinByPhoneButtons: false
  155. });
  156. }
  157. /**
  158. * Displays the join by phone buttons dropdown.
  159. *
  160. * @param {Object} e - The synthetic event.
  161. * @returns {void}
  162. */
  163. _onOptionsClick(e?: React.KeyboardEvent | React.MouseEvent | undefined) {
  164. e?.stopPropagation();
  165. this.setState({
  166. showJoinByPhoneButtons: !this.state.showJoinByPhoneButtons
  167. });
  168. }
  169. /**
  170. * Sets the guest participant name.
  171. *
  172. * @param {string} displayName - Participant name.
  173. * @returns {void}
  174. */
  175. _setName(displayName: string) {
  176. this.props.updateSettings({
  177. displayName
  178. });
  179. }
  180. /**
  181. * Closes the join by phone dialog.
  182. *
  183. * @returns {undefined}
  184. */
  185. _closeDialog() {
  186. this.props.setJoinByPhoneDialogVisiblity(false);
  187. }
  188. /**
  189. * Displays the dialog for joining a meeting by phone.
  190. *
  191. * @returns {undefined}
  192. */
  193. _showDialog() {
  194. this.props.setJoinByPhoneDialogVisiblity(true);
  195. this._onDropdownClose();
  196. }
  197. /**
  198. * KeyPress handler for accessibility.
  199. *
  200. * @param {Object} e - The key event to handle.
  201. *
  202. * @returns {void}
  203. */
  204. _showDialogKeyPress(e: React.KeyboardEvent) {
  205. if (e.key === ' ' || e.key === 'Enter') {
  206. e.preventDefault();
  207. this._showDialog();
  208. }
  209. }
  210. /**
  211. * KeyPress handler for accessibility.
  212. *
  213. * @param {Object} e - The key event to handle.
  214. *
  215. * @returns {void}
  216. */
  217. _onJoinConferenceWithoutAudioKeyPress(e: React.KeyboardEvent) {
  218. if (this.props.joinConferenceWithoutAudio
  219. && (e.key === ' '
  220. || e.key === 'Enter')) {
  221. e.preventDefault();
  222. this.props.joinConferenceWithoutAudio();
  223. }
  224. }
  225. /**
  226. * Gets the list of extra join buttons.
  227. *
  228. * @returns {Object} - The list of extra buttons.
  229. */
  230. _getExtraJoinButtons() {
  231. const { joinConferenceWithoutAudio, t } = this.props;
  232. const noAudio = {
  233. key: 'no-audio',
  234. testId: 'prejoin.joinWithoutAudio',
  235. icon: IconVolumeOff,
  236. label: t('prejoin.joinWithoutAudio'),
  237. onClick: joinConferenceWithoutAudio,
  238. onKeyPress: this._onJoinConferenceWithoutAudioKeyPress
  239. };
  240. const byPhone = {
  241. key: 'by-phone',
  242. testId: 'prejoin.joinByPhone',
  243. icon: IconPhoneRinging,
  244. label: t('prejoin.joinAudioByPhone'),
  245. onClick: this._showDialog,
  246. onKeyPress: this._showDialogKeyPress
  247. };
  248. return {
  249. noAudio,
  250. byPhone
  251. };
  252. }
  253. /**
  254. * Handle keypress on input.
  255. *
  256. * @param {KeyboardEvent} e - Keyboard event.
  257. * @returns {void}
  258. */
  259. _onInputKeyPress(e: React.KeyboardEvent) {
  260. const { joinConference } = this.props;
  261. if (e.key === 'Enter') {
  262. joinConference();
  263. }
  264. }
  265. /**
  266. * Implements React's {@link Component#render()}.
  267. *
  268. * @inheritdoc
  269. * @returns {ReactElement}
  270. */
  271. render() {
  272. const {
  273. deviceStatusVisible,
  274. hasJoinByPhoneButton,
  275. joinConferenceWithoutAudio,
  276. joiningInProgress,
  277. name,
  278. participantId,
  279. prejoinConfig,
  280. readOnlyName,
  281. showCameraPreview,
  282. showDialog,
  283. showErrorOnJoin,
  284. t,
  285. videoTrack
  286. } = this.props;
  287. const { _closeDialog, _onDropdownClose, _onJoinButtonClick,
  288. _onOptionsClick, _setName, _onInputKeyPress } = this;
  289. const extraJoinButtons = this._getExtraJoinButtons();
  290. let extraButtonsToRender = Object.values(extraJoinButtons).filter((val: any) =>
  291. !(prejoinConfig?.hideExtraJoinButtons || []).includes(val.key)
  292. );
  293. if (!hasJoinByPhoneButton) {
  294. extraButtonsToRender = extraButtonsToRender.filter((btn: any) => btn.key !== 'by-phone');
  295. }
  296. const hasExtraJoinButtons = Boolean(extraButtonsToRender.length);
  297. const { showJoinByPhoneButtons } = this.state;
  298. return (
  299. <PreMeetingScreen
  300. showDeviceStatus = { deviceStatusVisible }
  301. title = { t('prejoin.joinMeeting') }
  302. videoMuted = { !showCameraPreview }
  303. videoTrack = { videoTrack }>
  304. <div
  305. className = 'prejoin-input-area'
  306. data-testid = 'prejoin.screen'>
  307. {this.showDisplayNameField ? (<Input
  308. autoComplete = { 'name' }
  309. autoFocus = { true }
  310. className = 'prejoin-input'
  311. error = { showErrorOnJoin }
  312. onChange = { _setName }
  313. onKeyPress = { _onInputKeyPress }
  314. placeholder = { t('dialog.enterDisplayName') }
  315. readOnly = { readOnlyName }
  316. value = { name } />
  317. ) : (
  318. <div className = 'prejoin-avatar-container'>
  319. <Avatar
  320. className = 'prejoin-avatar'
  321. displayName = { name }
  322. participantId = { participantId }
  323. size = { 72 } />
  324. <div className = 'prejoin-avatar-name'>{name}</div>
  325. </div>
  326. )}
  327. {showErrorOnJoin && <div
  328. className = 'prejoin-error'
  329. data-testid = 'prejoin.errorMessage'>{t('prejoin.errorMissingName')}</div>}
  330. <div className = 'prejoin-preview-dropdown-container'>
  331. <InlineDialog
  332. content = { hasExtraJoinButtons && <div className = 'prejoin-preview-dropdown-btns'>
  333. {extraButtonsToRender.map(({ key, ...rest }) => (
  334. <Button
  335. disabled = { joiningInProgress }
  336. fullWidth = { true }
  337. key = { key }
  338. type = { BUTTON_TYPES.SECONDARY }
  339. { ...rest } />
  340. ))}
  341. </div> }
  342. isOpen = { showJoinByPhoneButtons }
  343. onClose = { _onDropdownClose }>
  344. <ActionButton
  345. OptionsIcon = { showJoinByPhoneButtons ? IconArrowUp : IconArrowDown }
  346. ariaDropDownLabel = { t('prejoin.joinWithoutAudio') }
  347. ariaLabel = { t('prejoin.joinMeeting') }
  348. ariaPressed = { showJoinByPhoneButtons }
  349. disabled = { joiningInProgress }
  350. hasOptions = { hasExtraJoinButtons }
  351. onClick = { _onJoinButtonClick }
  352. onOptionsClick = { _onOptionsClick }
  353. role = 'button'
  354. tabIndex = { 0 }
  355. testId = 'prejoin.joinMeeting'
  356. type = 'primary'>
  357. { t('prejoin.joinMeeting') }
  358. </ActionButton>
  359. </InlineDialog>
  360. </div>
  361. </div>
  362. { showDialog && (
  363. <JoinByPhoneDialog
  364. joinConferenceWithoutAudio = { joinConferenceWithoutAudio }
  365. onClose = { _closeDialog } />
  366. )}
  367. </PreMeetingScreen>
  368. );
  369. }
  370. }
  371. /**
  372. * Maps (parts of) the redux state to the React {@code Component} props.
  373. *
  374. * @param {Object} state - The redux state.
  375. * @returns {Object}
  376. */
  377. function mapStateToProps(state: IReduxState) {
  378. const name = getDisplayName(state);
  379. const showErrorOnJoin = isDisplayNameRequired(state) && !name;
  380. const { id: participantId } = getLocalParticipant(state) ?? {};
  381. const { joiningInProgress } = state['features/prejoin'];
  382. return {
  383. canEditDisplayName: isPrejoinDisplayNameVisible(state),
  384. deviceStatusVisible: isDeviceStatusVisible(state),
  385. hasJoinByPhoneButton: isJoinByPhoneButtonVisible(state),
  386. joiningInProgress,
  387. name,
  388. participantId,
  389. prejoinConfig: state['features/base/config'].prejoinConfig,
  390. readOnlyName: isNameReadOnly(state),
  391. showCameraPreview: !isVideoMutedByUser(state),
  392. showDialog: isJoinByPhoneDialogVisible(state),
  393. showErrorOnJoin,
  394. videoTrack: getLocalJitsiVideoTrack(state)
  395. };
  396. }
  397. const mapDispatchToProps = {
  398. joinConferenceWithoutAudio: joinConferenceWithoutAudioAction,
  399. joinConference: joinConferenceAction,
  400. setJoinByPhoneDialogVisiblity: setJoinByPhoneDialogVisiblityAction,
  401. updateSettings
  402. };
  403. export default connect(mapStateToProps, mapDispatchToProps)(translate(Prejoin));