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 14KB

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