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.js 13KB

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