Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Prejoin.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. // @flow
  2. import InlineDialog from '@atlaskit/inline-dialog';
  3. import React, { Component } from 'react';
  4. import { LoginDialog, WaitForOwnerDialog } from '../../authentication/components';
  5. import { Avatar } from '../../base/avatar';
  6. import { getRoomName } from '../../base/conference';
  7. import { isNameReadOnly } from '../../base/config';
  8. import { isDialogOpen } from '../../base/dialog/functions';
  9. import { translate } from '../../base/i18n';
  10. import { IconArrowDown, IconArrowUp, IconPhone, IconVolumeOff } from '../../base/icons';
  11. import { isVideoMutedByUser } from '../../base/media';
  12. import { getLocalParticipant } from '../../base/participants';
  13. import { ActionButton, InputField, PreMeetingScreen } from '../../base/premeeting';
  14. import { connect } from '../../base/redux';
  15. import { getDisplayName, updateSettings } from '../../base/settings';
  16. import { getLocalJitsiVideoTrack } from '../../base/tracks';
  17. import { PasswordRequiredPrompt } from '../../room-lock/components';
  18. import {
  19. joinConference as joinConferenceAction,
  20. joinConferenceWithoutAudio as joinConferenceWithoutAudioAction,
  21. setJoinByPhoneDialogVisiblity as setJoinByPhoneDialogVisiblityAction
  22. } from '../actions';
  23. import {
  24. isDeviceStatusVisible,
  25. isDisplayNameRequired,
  26. isJoinByPhoneButtonVisible,
  27. isJoinByPhoneDialogVisible,
  28. isPrejoinDisplayNameVisible
  29. } from '../functions';
  30. import DropdownButton from './DropdownButton';
  31. import JoinByPhoneDialog from './dialogs/JoinByPhoneDialog';
  32. type Props = {
  33. /**
  34. * Indicates whether the display name is editable.
  35. */
  36. canEditDisplayName: boolean,
  37. /**
  38. * Flag signaling if the device status is visible or not.
  39. */
  40. deviceStatusVisible: boolean,
  41. /**
  42. * If join by phone button should be visible.
  43. */
  44. hasJoinByPhoneButton: boolean,
  45. /**
  46. * Whether authentication is taking place or not.
  47. */
  48. isAuthInProgress: 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. * The name of the user that is about to join.
  59. */
  60. name: string,
  61. /**
  62. * Updates settings.
  63. */
  64. updateSettings: Function,
  65. /**
  66. * Local participant id.
  67. */
  68. participantId: string,
  69. /**
  70. * The prejoin config.
  71. */
  72. prejoinConfig?: Object,
  73. /**
  74. * Whether the name input should be read only or not.
  75. */
  76. readOnlyName: boolean,
  77. /**
  78. * The name of the meeting that is about to be joined.
  79. */
  80. roomName: string,
  81. /**
  82. * Sets visibility of the 'JoinByPhoneDialog'.
  83. */
  84. setJoinByPhoneDialogVisiblity: Function,
  85. /**
  86. * Flag signaling the visibility of camera preview.
  87. */
  88. showCameraPreview: boolean,
  89. /**
  90. * If should show an error when joining without a name.
  91. */
  92. showErrorOnJoin: boolean,
  93. /**
  94. * If 'JoinByPhoneDialog' is visible or not.
  95. */
  96. showDialog: boolean,
  97. /**
  98. * Used for translation.
  99. */
  100. t: Function,
  101. /**
  102. * The JitsiLocalTrack to display.
  103. */
  104. videoTrack: ?Object
  105. };
  106. type State = {
  107. /**
  108. * Flag controlling the visibility of the error label.
  109. */
  110. showError: boolean,
  111. /**
  112. * Flag controlling the visibility of the 'join by phone' buttons.
  113. */
  114. showJoinByPhoneButtons: boolean
  115. }
  116. /**
  117. * This component is displayed before joining a meeting.
  118. */
  119. class Prejoin extends Component<Props, State> {
  120. /**
  121. * Initializes a new {@code Prejoin} instance.
  122. *
  123. * @inheritdoc
  124. */
  125. constructor(props) {
  126. super(props);
  127. this.state = {
  128. showError: false,
  129. showJoinByPhoneButtons: false
  130. };
  131. this._closeDialog = this._closeDialog.bind(this);
  132. this._showDialog = this._showDialog.bind(this);
  133. this._onJoinButtonClick = this._onJoinButtonClick.bind(this);
  134. this._onDropdownClose = this._onDropdownClose.bind(this);
  135. this._onOptionsClick = this._onOptionsClick.bind(this);
  136. this._setName = this._setName.bind(this);
  137. this._onJoinConferenceWithoutAudioKeyPress = this._onJoinConferenceWithoutAudioKeyPress.bind(this);
  138. this._showDialogKeyPress = this._showDialogKeyPress.bind(this);
  139. this._onJoinKeyPress = this._onJoinKeyPress.bind(this);
  140. this._getExtraJoinButtons = this._getExtraJoinButtons.bind(this);
  141. this.showDisplayNameField = props.canEditDisplayName || props.showErrorOnJoin;
  142. }
  143. _onJoinButtonClick: () => void;
  144. /**
  145. * Handler for the join button.
  146. *
  147. * @param {Object} e - The synthetic event.
  148. * @returns {void}
  149. */
  150. _onJoinButtonClick() {
  151. if (this.props.showErrorOnJoin) {
  152. this.setState({
  153. showError: true
  154. });
  155. return;
  156. }
  157. this.setState({ showError: false });
  158. this.props.joinConference();
  159. }
  160. _onJoinKeyPress: (Object) => void;
  161. /**
  162. * KeyPress handler for accessibility.
  163. *
  164. * @param {Object} e - The key event to handle.
  165. *
  166. * @returns {void}
  167. */
  168. _onJoinKeyPress(e) {
  169. if (e.key === ' ' || e.key === 'Enter') {
  170. e.preventDefault();
  171. this._onJoinButtonClick();
  172. }
  173. }
  174. _onDropdownClose: () => void;
  175. /**
  176. * Closes the dropdown.
  177. *
  178. * @returns {void}
  179. */
  180. _onDropdownClose() {
  181. this.setState({
  182. showJoinByPhoneButtons: false
  183. });
  184. }
  185. _onOptionsClick: () => void;
  186. /**
  187. * Displays the join by phone buttons dropdown.
  188. *
  189. * @param {Object} e - The synthetic event.
  190. * @returns {void}
  191. */
  192. _onOptionsClick(e) {
  193. e.stopPropagation();
  194. this.setState({
  195. showJoinByPhoneButtons: !this.state.showJoinByPhoneButtons
  196. });
  197. }
  198. _setName: () => void;
  199. /**
  200. * Sets the guest participant name.
  201. *
  202. * @param {string} displayName - Participant name.
  203. * @returns {void}
  204. */
  205. _setName(displayName) {
  206. this.props.updateSettings({
  207. displayName
  208. });
  209. }
  210. _closeDialog: () => void;
  211. /**
  212. * Closes the join by phone dialog.
  213. *
  214. * @returns {undefined}
  215. */
  216. _closeDialog() {
  217. this.props.setJoinByPhoneDialogVisiblity(false);
  218. }
  219. _showDialog: () => void;
  220. /**
  221. * Displays the dialog for joining a meeting by phone.
  222. *
  223. * @returns {undefined}
  224. */
  225. _showDialog() {
  226. this.props.setJoinByPhoneDialogVisiblity(true);
  227. this._onDropdownClose();
  228. }
  229. _showDialogKeyPress: (Object) => void;
  230. /**
  231. * KeyPress handler for accessibility.
  232. *
  233. * @param {Object} e - The key event to handle.
  234. *
  235. * @returns {void}
  236. */
  237. _showDialogKeyPress(e) {
  238. if (e.key === ' ' || e.key === 'Enter') {
  239. e.preventDefault();
  240. this._showDialog();
  241. }
  242. }
  243. _onJoinConferenceWithoutAudioKeyPress: (Object) => void;
  244. /**
  245. * KeyPress handler for accessibility.
  246. *
  247. * @param {Object} e - The key event to handle.
  248. *
  249. * @returns {void}
  250. */
  251. _onJoinConferenceWithoutAudioKeyPress(e) {
  252. if (this.props.joinConferenceWithoutAudio
  253. && (e.key === ' '
  254. || e.key === 'Enter')) {
  255. e.preventDefault();
  256. this.props.joinConferenceWithoutAudio();
  257. }
  258. }
  259. _getExtraJoinButtons: () => Object;
  260. /**
  261. * Gets the list of extra join buttons.
  262. *
  263. * @returns {Object} - The list of extra buttons.
  264. */
  265. _getExtraJoinButtons() {
  266. const { joinConferenceWithoutAudio, t } = this.props;
  267. const noAudio = {
  268. key: 'no-audio',
  269. dataTestId: 'prejoin.joinWithoutAudio',
  270. icon: IconVolumeOff,
  271. label: t('prejoin.joinWithoutAudio'),
  272. onButtonClick: joinConferenceWithoutAudio,
  273. onKeyPressed: this._onJoinConferenceWithoutAudioKeyPress
  274. };
  275. const byPhone = {
  276. key: 'by-phone',
  277. dataTestId: 'prejoin.joinByPhone',
  278. icon: IconPhone,
  279. label: t('prejoin.joinAudioByPhone'),
  280. onButtonClick: this._showDialog,
  281. onKeyPressed: this._showDialogKeyPress
  282. };
  283. return {
  284. noAudio,
  285. byPhone
  286. };
  287. }
  288. /**
  289. * Implements React's {@link Component#render()}.
  290. *
  291. * @inheritdoc
  292. * @returns {ReactElement}
  293. */
  294. render() {
  295. const {
  296. deviceStatusVisible,
  297. hasJoinByPhoneButton,
  298. isAuthInProgress,
  299. joinConference,
  300. joinConferenceWithoutAudio,
  301. name,
  302. participantId,
  303. prejoinConfig,
  304. readOnlyName,
  305. showCameraPreview,
  306. showDialog,
  307. t,
  308. videoTrack
  309. } = this.props;
  310. const { _closeDialog, _onDropdownClose, _onJoinButtonClick, _onJoinKeyPress,
  311. _onOptionsClick, _setName } = this;
  312. const extraJoinButtons = this._getExtraJoinButtons();
  313. let extraButtonsToRender = Object.values(extraJoinButtons).filter((val: Object) =>
  314. !(prejoinConfig?.hideExtraJoinButtons || []).includes(val.key)
  315. );
  316. if (!hasJoinByPhoneButton) {
  317. extraButtonsToRender = extraButtonsToRender.filter((btn: Object) => btn.key !== 'by-phone');
  318. }
  319. const hasExtraJoinButtons = Boolean(extraButtonsToRender.length);
  320. const { showJoinByPhoneButtons, showError } = this.state;
  321. return (
  322. <PreMeetingScreen
  323. showDeviceStatus = { deviceStatusVisible }
  324. title = { t('prejoin.joinMeeting') }
  325. videoMuted = { !showCameraPreview }
  326. videoTrack = { videoTrack }>
  327. <div
  328. className = 'prejoin-input-area'
  329. data-testid = 'prejoin.screen'>
  330. {this.showDisplayNameField ? (<InputField
  331. autoComplete = { 'name' }
  332. autoFocus = { !isAuthInProgress }
  333. className = { showError ? 'error' : '' }
  334. hasError = { showError }
  335. onChange = { _setName }
  336. onSubmit = { joinConference }
  337. placeHolder = { t('dialog.enterDisplayName') }
  338. readOnly = { readOnlyName }
  339. value = { name } />
  340. ) : (
  341. <div className = 'prejoin-avatar-container'>
  342. <Avatar
  343. className = 'prejoin-avatar'
  344. displayName = { name }
  345. participantId = { participantId }
  346. size = { 72 } />
  347. <div className = 'prejoin-avatar-name'>{name}</div>
  348. </div>
  349. )}
  350. {showError && <div
  351. className = 'prejoin-error'
  352. data-testid = 'prejoin.errorMessage'>{t('prejoin.errorMissingName')}</div>}
  353. <div className = 'prejoin-preview-dropdown-container'>
  354. <InlineDialog
  355. content = { hasExtraJoinButtons && <div className = 'prejoin-preview-dropdown-btns'>
  356. {extraButtonsToRender.map(({ key, ...rest }: Object) => (
  357. <DropdownButton
  358. key = { key }
  359. { ...rest } />
  360. ))}
  361. </div> }
  362. isOpen = { showJoinByPhoneButtons }
  363. onClose = { _onDropdownClose }>
  364. <ActionButton
  365. OptionsIcon = { showJoinByPhoneButtons ? IconArrowUp : IconArrowDown }
  366. ariaDropDownLabel = { t('prejoin.joinWithoutAudio') }
  367. ariaLabel = { t('prejoin.joinMeeting') }
  368. ariaPressed = { showJoinByPhoneButtons }
  369. hasOptions = { hasExtraJoinButtons }
  370. onClick = { _onJoinButtonClick }
  371. onKeyPress = { _onJoinKeyPress }
  372. onOptionsClick = { _onOptionsClick }
  373. role = 'button'
  374. tabIndex = { 0 }
  375. testId = 'prejoin.joinMeeting'
  376. type = 'primary'>
  377. { t('prejoin.joinMeeting') }
  378. </ActionButton>
  379. </InlineDialog>
  380. </div>
  381. </div>
  382. { showDialog && (
  383. <JoinByPhoneDialog
  384. joinConferenceWithoutAudio = { joinConferenceWithoutAudio }
  385. onClose = { _closeDialog } />
  386. )}
  387. </PreMeetingScreen>
  388. );
  389. }
  390. }
  391. /**
  392. * Maps (parts of) the redux state to the React {@code Component} props.
  393. *
  394. * @param {Object} state - The redux state.
  395. * @returns {Object}
  396. */
  397. function mapStateToProps(state): Object {
  398. const name = getDisplayName(state);
  399. const showErrorOnJoin = isDisplayNameRequired(state) && !name;
  400. const { id: participantId } = getLocalParticipant(state);
  401. const isAuthInProgress = isDialogOpen(state, WaitForOwnerDialog)
  402. || isDialogOpen(state, LoginDialog) || isDialogOpen(state, PasswordRequiredPrompt);
  403. return {
  404. canEditDisplayName: isPrejoinDisplayNameVisible(state),
  405. deviceStatusVisible: isDeviceStatusVisible(state),
  406. hasJoinByPhoneButton: isJoinByPhoneButtonVisible(state),
  407. isAuthInProgress,
  408. name,
  409. participantId,
  410. prejoinConfig: state['features/base/config'].prejoinConfig,
  411. readOnlyName: isNameReadOnly(state),
  412. roomName: getRoomName(state),
  413. showCameraPreview: !isVideoMutedByUser(state),
  414. showDialog: isJoinByPhoneDialogVisible(state),
  415. showErrorOnJoin,
  416. videoTrack: getLocalJitsiVideoTrack(state)
  417. };
  418. }
  419. const mapDispatchToProps = {
  420. joinConferenceWithoutAudio: joinConferenceWithoutAudioAction,
  421. joinConference: joinConferenceAction,
  422. setJoinByPhoneDialogVisiblity: setJoinByPhoneDialogVisiblityAction,
  423. updateSettings
  424. };
  425. export default connect(mapStateToProps, mapDispatchToProps)(translate(Prejoin));