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.

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