您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Prejoin.tsx 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. import React, { Component } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { connect } from 'react-redux';
  4. import { IReduxState } from '../../../app/types';
  5. import Avatar from '../../../base/avatar/components/Avatar';
  6. import { isNameReadOnly } from '../../../base/config/functions.web';
  7. import { translate } from '../../../base/i18n/functions';
  8. import { IconArrowDown, IconArrowUp, IconPhoneRinging, IconVolumeOff } from '../../../base/icons/svg';
  9. import { isVideoMutedByUser } from '../../../base/media/functions';
  10. import { getLocalParticipant } from '../../../base/participants/functions';
  11. import Popover from '../../../base/popover/components/Popover.web';
  12. import ActionButton from '../../../base/premeeting/components/web/ActionButton';
  13. import PreMeetingScreen from '../../../base/premeeting/components/web/PreMeetingScreen';
  14. import { updateSettings } from '../../../base/settings/actions';
  15. import { getDisplayName } from '../../../base/settings/functions.web';
  16. import { getLocalJitsiVideoTrack } from '../../../base/tracks/functions.web';
  17. import Button from '../../../base/ui/components/web/Button';
  18. import Input from '../../../base/ui/components/web/Input';
  19. import { BUTTON_TYPES } from '../../../base/ui/constants.any';
  20. import {
  21. joinConference as joinConferenceAction,
  22. joinConferenceWithoutAudio as joinConferenceWithoutAudioAction,
  23. setJoinByPhoneDialogVisiblity as setJoinByPhoneDialogVisiblityAction
  24. } from '../../actions.web';
  25. import {
  26. isDeviceStatusVisible,
  27. isDisplayNameRequired,
  28. isJoinByPhoneButtonVisible,
  29. isJoinByPhoneDialogVisible,
  30. isPrejoinDisplayNameVisible
  31. } from '../../functions';
  32. // @ts-ignore
  33. import JoinByPhoneDialog from './dialogs/JoinByPhoneDialog';
  34. interface IProps extends WithTranslation {
  35. /**
  36. * Indicates whether the display name is editable.
  37. */
  38. canEditDisplayName: boolean;
  39. /**
  40. * Flag signaling if the device status is visible or not.
  41. */
  42. deviceStatusVisible: boolean;
  43. /**
  44. * If join by phone button should be visible.
  45. */
  46. hasJoinByPhoneButton: boolean;
  47. /**
  48. * Joins the current meeting.
  49. */
  50. joinConference: Function;
  51. /**
  52. * Joins the current meeting without audio.
  53. */
  54. joinConferenceWithoutAudio: Function;
  55. /**
  56. * Whether conference join is in progress.
  57. */
  58. joiningInProgress?: boolean;
  59. /**
  60. * The name of the user that is about to join.
  61. */
  62. name: string;
  63. /**
  64. * Local participant id.
  65. */
  66. participantId?: string;
  67. /**
  68. * The prejoin config.
  69. */
  70. prejoinConfig?: any;
  71. /**
  72. * Whether the name input should be read only or not.
  73. */
  74. readOnlyName: boolean;
  75. /**
  76. * Sets visibility of the 'JoinByPhoneDialog'.
  77. */
  78. setJoinByPhoneDialogVisiblity: Function;
  79. /**
  80. * Flag signaling the visibility of camera preview.
  81. */
  82. showCameraPreview: boolean;
  83. /**
  84. * If 'JoinByPhoneDialog' is visible or not.
  85. */
  86. showDialog: boolean;
  87. /**
  88. * If should show an error when joining without a name.
  89. */
  90. showErrorOnJoin: boolean;
  91. /**
  92. * Updates settings.
  93. */
  94. updateSettings: Function;
  95. /**
  96. * The JitsiLocalTrack to display.
  97. */
  98. videoTrack?: Object;
  99. }
  100. interface IState {
  101. /**
  102. * Flag controlling the visibility of the 'join by phone' buttons.
  103. */
  104. showJoinByPhoneButtons: boolean;
  105. }
  106. /**
  107. * This component is displayed before joining a meeting.
  108. */
  109. class Prejoin extends Component<IProps, IState> {
  110. showDisplayNameField: boolean;
  111. /**
  112. * Initializes a new {@code Prejoin} instance.
  113. *
  114. * @inheritdoc
  115. */
  116. constructor(props: IProps) {
  117. super(props);
  118. this.state = {
  119. showJoinByPhoneButtons: false
  120. };
  121. this._closeDialog = this._closeDialog.bind(this);
  122. this._showDialog = this._showDialog.bind(this);
  123. this._onJoinButtonClick = this._onJoinButtonClick.bind(this);
  124. this._onDropdownClose = this._onDropdownClose.bind(this);
  125. this._onOptionsClick = this._onOptionsClick.bind(this);
  126. this._setName = this._setName.bind(this);
  127. this._onJoinConferenceWithoutAudioKeyPress = this._onJoinConferenceWithoutAudioKeyPress.bind(this);
  128. this._showDialogKeyPress = this._showDialogKeyPress.bind(this);
  129. this._getExtraJoinButtons = this._getExtraJoinButtons.bind(this);
  130. this._onInputKeyPress = this._onInputKeyPress.bind(this);
  131. this.showDisplayNameField = props.canEditDisplayName || props.showErrorOnJoin;
  132. }
  133. /**
  134. * Handler for the join button.
  135. *
  136. * @param {Object} e - The synthetic event.
  137. * @returns {void}
  138. */
  139. _onJoinButtonClick() {
  140. if (this.props.showErrorOnJoin) {
  141. return;
  142. }
  143. this.props.joinConference();
  144. }
  145. /**
  146. * Closes the dropdown.
  147. *
  148. * @returns {void}
  149. */
  150. _onDropdownClose() {
  151. this.setState({
  152. showJoinByPhoneButtons: false
  153. });
  154. }
  155. /**
  156. * Displays the join by phone buttons dropdown.
  157. *
  158. * @param {Object} e - The synthetic event.
  159. * @returns {void}
  160. */
  161. _onOptionsClick(e?: React.KeyboardEvent | React.MouseEvent | undefined) {
  162. e?.stopPropagation();
  163. this.setState({
  164. showJoinByPhoneButtons: !this.state.showJoinByPhoneButtons
  165. });
  166. }
  167. /**
  168. * Sets the guest participant name.
  169. *
  170. * @param {string} displayName - Participant name.
  171. * @returns {void}
  172. */
  173. _setName(displayName: string) {
  174. this.props.updateSettings({
  175. displayName
  176. });
  177. }
  178. /**
  179. * Closes the join by phone dialog.
  180. *
  181. * @returns {undefined}
  182. */
  183. _closeDialog() {
  184. this.props.setJoinByPhoneDialogVisiblity(false);
  185. }
  186. /**
  187. * Displays the dialog for joining a meeting by phone.
  188. *
  189. * @returns {undefined}
  190. */
  191. _showDialog() {
  192. this.props.setJoinByPhoneDialogVisiblity(true);
  193. this._onDropdownClose();
  194. }
  195. /**
  196. * KeyPress handler for accessibility.
  197. *
  198. * @param {Object} e - The key event to handle.
  199. *
  200. * @returns {void}
  201. */
  202. _showDialogKeyPress(e: React.KeyboardEvent) {
  203. if (e.key === ' ' || e.key === 'Enter') {
  204. e.preventDefault();
  205. this._showDialog();
  206. }
  207. }
  208. /**
  209. * KeyPress handler for accessibility.
  210. *
  211. * @param {Object} e - The key event to handle.
  212. *
  213. * @returns {void}
  214. */
  215. _onJoinConferenceWithoutAudioKeyPress(e: React.KeyboardEvent) {
  216. if (this.props.joinConferenceWithoutAudio
  217. && (e.key === ' '
  218. || e.key === 'Enter')) {
  219. e.preventDefault();
  220. this.props.joinConferenceWithoutAudio();
  221. }
  222. }
  223. /**
  224. * Gets the list of extra join buttons.
  225. *
  226. * @returns {Object} - The list of extra buttons.
  227. */
  228. _getExtraJoinButtons() {
  229. const { joinConferenceWithoutAudio, t } = this.props;
  230. const noAudio = {
  231. key: 'no-audio',
  232. testId: 'prejoin.joinWithoutAudio',
  233. icon: IconVolumeOff,
  234. label: t('prejoin.joinWithoutAudio'),
  235. onClick: joinConferenceWithoutAudio,
  236. onKeyPress: this._onJoinConferenceWithoutAudioKeyPress
  237. };
  238. const byPhone = {
  239. key: 'by-phone',
  240. testId: 'prejoin.joinByPhone',
  241. icon: IconPhoneRinging,
  242. label: t('prejoin.joinAudioByPhone'),
  243. onClick: this._showDialog,
  244. onKeyPress: this._showDialogKeyPress
  245. };
  246. return {
  247. noAudio,
  248. byPhone
  249. };
  250. }
  251. /**
  252. * Handle keypress on input.
  253. *
  254. * @param {KeyboardEvent} e - Keyboard event.
  255. * @returns {void}
  256. */
  257. _onInputKeyPress(e: React.KeyboardEvent) {
  258. const { joinConference } = this.props;
  259. if (e.key === 'Enter') {
  260. joinConference();
  261. }
  262. }
  263. /**
  264. * Implements React's {@link Component#render()}.
  265. *
  266. * @inheritdoc
  267. * @returns {ReactElement}
  268. */
  269. render() {
  270. const {
  271. deviceStatusVisible,
  272. hasJoinByPhoneButton,
  273. joinConferenceWithoutAudio,
  274. joiningInProgress,
  275. name,
  276. participantId,
  277. prejoinConfig,
  278. readOnlyName,
  279. showCameraPreview,
  280. showDialog,
  281. showErrorOnJoin,
  282. t,
  283. videoTrack
  284. } = this.props;
  285. const { _closeDialog, _onDropdownClose, _onJoinButtonClick,
  286. _onOptionsClick, _setName, _onInputKeyPress } = this;
  287. const extraJoinButtons = this._getExtraJoinButtons();
  288. let extraButtonsToRender = Object.values(extraJoinButtons).filter((val: any) =>
  289. !(prejoinConfig?.hideExtraJoinButtons || []).includes(val.key)
  290. );
  291. if (!hasJoinByPhoneButton) {
  292. extraButtonsToRender = extraButtonsToRender.filter((btn: any) => btn.key !== 'by-phone');
  293. }
  294. const hasExtraJoinButtons = Boolean(extraButtonsToRender.length);
  295. const { showJoinByPhoneButtons } = this.state;
  296. return (
  297. <PreMeetingScreen
  298. showDeviceStatus = { deviceStatusVisible }
  299. title = { t('prejoin.joinMeeting') }
  300. videoMuted = { !showCameraPreview }
  301. videoTrack = { videoTrack }>
  302. <div
  303. className = 'prejoin-input-area'
  304. data-testid = 'prejoin.screen'>
  305. {this.showDisplayNameField ? (<Input
  306. autoComplete = { 'name' }
  307. autoFocus = { true }
  308. className = 'prejoin-input'
  309. error = { showErrorOnJoin }
  310. onChange = { _setName }
  311. onKeyPress = { _onInputKeyPress }
  312. placeholder = { t('dialog.enterDisplayName') }
  313. readOnly = { readOnlyName }
  314. value = { name } />
  315. ) : (
  316. <div className = 'prejoin-avatar-container'>
  317. <Avatar
  318. className = 'prejoin-avatar'
  319. displayName = { name }
  320. participantId = { participantId }
  321. size = { 72 } />
  322. <div className = 'prejoin-avatar-name'>{name}</div>
  323. </div>
  324. )}
  325. {showErrorOnJoin && <div
  326. className = 'prejoin-error'
  327. data-testid = 'prejoin.errorMessage'>{t('prejoin.errorMissingName')}</div>}
  328. <div className = 'prejoin-preview-dropdown-container'>
  329. <Popover
  330. content = { hasExtraJoinButtons && <div className = 'prejoin-preview-dropdown-btns'>
  331. {extraButtonsToRender.map(({ key, ...rest }) => (
  332. <Button
  333. disabled = { joiningInProgress }
  334. fullWidth = { true }
  335. key = { key }
  336. type = { BUTTON_TYPES.SECONDARY }
  337. { ...rest } />
  338. ))}
  339. </div> }
  340. onPopoverClose = { _onDropdownClose }
  341. position = 'bottom'
  342. trigger = 'click'
  343. visible = { showJoinByPhoneButtons }>
  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. </Popover>
  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));