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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. // @flow
  2. import InlineDialog from '@atlaskit/inline-dialog';
  3. import React, { Component } from 'react';
  4. import { getRoomName } from '../../base/conference';
  5. import { translate } from '../../base/i18n';
  6. import { Icon, IconArrowDown, IconArrowUp, IconPhone, IconVolumeOff } from '../../base/icons';
  7. import { isVideoMutedByUser } from '../../base/media';
  8. import { ActionButton, InputField, PreMeetingScreen, ToggleButton } from '../../base/premeeting';
  9. import { connect } from '../../base/redux';
  10. import { getDisplayName, updateSettings } from '../../base/settings';
  11. import { getLocalJitsiVideoTrack } from '../../base/tracks';
  12. import {
  13. joinConference as joinConferenceAction,
  14. joinConferenceWithoutAudio as joinConferenceWithoutAudioAction,
  15. setSkipPrejoin as setSkipPrejoinAction,
  16. setJoinByPhoneDialogVisiblity as setJoinByPhoneDialogVisiblityAction
  17. } from '../actions';
  18. import {
  19. isDeviceStatusVisible,
  20. isDisplayNameRequired,
  21. isJoinByPhoneButtonVisible,
  22. isJoinByPhoneDialogVisible,
  23. isPrejoinSkipped
  24. } from '../functions';
  25. import JoinByPhoneDialog from './dialogs/JoinByPhoneDialog';
  26. type Props = {
  27. /**
  28. * Flag signaling if the 'skip prejoin' button is toggled or not.
  29. */
  30. buttonIsToggled: boolean,
  31. /**
  32. * Flag signaling if the device status is visible or not.
  33. */
  34. deviceStatusVisible: boolean,
  35. /**
  36. * If join by phone button should be visible.
  37. */
  38. hasJoinByPhoneButton: boolean,
  39. /**
  40. * Joins the current meeting.
  41. */
  42. joinConference: Function,
  43. /**
  44. * Joins the current meeting without audio.
  45. */
  46. joinConferenceWithoutAudio: Function,
  47. /**
  48. * The name of the user that is about to join.
  49. */
  50. name: string,
  51. /**
  52. * Updates settings.
  53. */
  54. updateSettings: Function,
  55. /**
  56. * The name of the meeting that is about to be joined.
  57. */
  58. roomName: string,
  59. /**
  60. * Sets visibility of the prejoin page for the next sessions.
  61. */
  62. setSkipPrejoin: Function,
  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._onToggleButtonClick = this._onToggleButtonClick.bind(this);
  117. this._onDropdownClose = this._onDropdownClose.bind(this);
  118. this._onOptionsClick = this._onOptionsClick.bind(this);
  119. this._setName = this._setName.bind(this);
  120. this._onJoinConferenceWithoutAudioKeyPress = this._onJoinConferenceWithoutAudioKeyPress.bind(this);
  121. this._showDialogKeyPress = this._showDialogKeyPress.bind(this);
  122. this._onJoinKeyPress = this._onJoinKeyPress.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. _onToggleButtonClick: () => void;
  156. /**
  157. * Handler for the toggle button.
  158. *
  159. * @param {Object} e - The synthetic event.
  160. * @returns {void}
  161. */
  162. _onToggleButtonClick() {
  163. this.props.setSkipPrejoin(!this.props.buttonIsToggled);
  164. }
  165. _onDropdownClose: () => void;
  166. /**
  167. * Closes the dropdown.
  168. *
  169. * @returns {void}
  170. */
  171. _onDropdownClose() {
  172. this.setState({
  173. showJoinByPhoneButtons: false
  174. });
  175. }
  176. _onOptionsClick: () => void;
  177. /**
  178. * Displays the join by phone buttons dropdown.
  179. *
  180. * @param {Object} e - The synthetic event.
  181. * @returns {void}
  182. */
  183. _onOptionsClick(e) {
  184. e.stopPropagation();
  185. this.setState({
  186. showJoinByPhoneButtons: !this.state.showJoinByPhoneButtons
  187. });
  188. }
  189. _setName: () => void;
  190. /**
  191. * Sets the guest participant name.
  192. *
  193. * @param {string} displayName - Participant name.
  194. * @returns {void}
  195. */
  196. _setName(displayName) {
  197. this.props.updateSettings({
  198. displayName
  199. });
  200. }
  201. _closeDialog: () => void;
  202. /**
  203. * Closes the join by phone dialog.
  204. *
  205. * @returns {undefined}
  206. */
  207. _closeDialog() {
  208. this.props.setJoinByPhoneDialogVisiblity(false);
  209. }
  210. _showDialog: () => void;
  211. /**
  212. * Displays the dialog for joining a meeting by phone.
  213. *
  214. * @returns {undefined}
  215. */
  216. _showDialog() {
  217. this.props.setJoinByPhoneDialogVisiblity(true);
  218. this._onDropdownClose();
  219. }
  220. _showDialogKeyPress: (Object) => void;
  221. /**
  222. * KeyPress handler for accessibility.
  223. *
  224. * @param {Object} e - The key event to handle.
  225. *
  226. * @returns {void}
  227. */
  228. _showDialogKeyPress(e) {
  229. if (e.key === ' ' || e.key === 'Enter') {
  230. e.preventDefault();
  231. this._showDialog();
  232. }
  233. }
  234. _onJoinConferenceWithoutAudioKeyPress: (Object) => void;
  235. /**
  236. * KeyPress handler for accessibility.
  237. *
  238. * @param {Object} e - The key event to handle.
  239. *
  240. * @returns {void}
  241. */
  242. _onJoinConferenceWithoutAudioKeyPress(e) {
  243. if (this.props.joinConferenceWithoutAudio
  244. && (e.key === ' '
  245. || e.key === 'Enter')) {
  246. e.preventDefault();
  247. this.props.joinConferenceWithoutAudio();
  248. }
  249. }
  250. /**
  251. * Implements React's {@link Component#render()}.
  252. *
  253. * @inheritdoc
  254. * @returns {ReactElement}
  255. */
  256. render() {
  257. const {
  258. deviceStatusVisible,
  259. hasJoinByPhoneButton,
  260. joinConference,
  261. joinConferenceWithoutAudio,
  262. name,
  263. showCameraPreview,
  264. showDialog,
  265. t,
  266. videoTrack
  267. } = this.props;
  268. const { _closeDialog, _onDropdownClose, _onJoinButtonClick, _onJoinKeyPress, _showDialogKeyPress,
  269. _onJoinConferenceWithoutAudioKeyPress, _onOptionsClick, _setName, _showDialog } = this;
  270. const { showJoinByPhoneButtons, showError } = this.state;
  271. return (
  272. <PreMeetingScreen
  273. showDeviceStatus = { deviceStatusVisible }
  274. skipPrejoinButton = { this._renderSkipPrejoinButton() }
  275. title = { t('prejoin.joinMeeting') }
  276. videoMuted = { !showCameraPreview }
  277. videoTrack = { videoTrack }>
  278. <div
  279. className = 'prejoin-input-area'
  280. data-testid = 'prejoin.screen'>
  281. <InputField
  282. autoComplete = { 'name' }
  283. autoFocus = { true }
  284. className = { showError ? 'error' : '' }
  285. hasError = { showError }
  286. onChange = { _setName }
  287. onSubmit = { joinConference }
  288. placeHolder = { t('dialog.enterDisplayName') }
  289. value = { name } />
  290. {showError && <div
  291. className = 'prejoin-error'
  292. data-testid = 'prejoin.errorMessage'>{t('prejoin.errorMissingName')}</div>}
  293. <div className = 'prejoin-preview-dropdown-container'>
  294. <InlineDialog
  295. content = { <div className = 'prejoin-preview-dropdown-btns'>
  296. <div
  297. className = 'prejoin-preview-dropdown-btn'
  298. data-testid = 'prejoin.joinWithoutAudio'
  299. onClick = { joinConferenceWithoutAudio }
  300. onKeyPress = { _onJoinConferenceWithoutAudioKeyPress }
  301. role = 'button'
  302. tabIndex = { 0 }>
  303. <Icon
  304. className = 'prejoin-preview-dropdown-icon'
  305. size = { 24 }
  306. src = { IconVolumeOff } />
  307. { t('prejoin.joinWithoutAudio') }
  308. </div>
  309. {hasJoinByPhoneButton && <div
  310. className = 'prejoin-preview-dropdown-btn'
  311. onClick = { _showDialog }
  312. onKeyPress = { _showDialogKeyPress }
  313. role = 'button'
  314. tabIndex = { 0 }>
  315. <Icon
  316. className = 'prejoin-preview-dropdown-icon'
  317. data-testid = 'prejoin.joinByPhone'
  318. size = { 24 }
  319. src = { IconPhone } />
  320. { t('prejoin.joinAudioByPhone') }
  321. </div>}
  322. </div> }
  323. isOpen = { showJoinByPhoneButtons }
  324. onClose = { _onDropdownClose }>
  325. <ActionButton
  326. OptionsIcon = { showJoinByPhoneButtons ? IconArrowUp : IconArrowDown }
  327. ariaDropDownLabel = { t('prejoin.joinWithoutAudio') }
  328. ariaLabel = { t('prejoin.joinMeeting') }
  329. ariaPressed = { showJoinByPhoneButtons }
  330. hasOptions = { true }
  331. onClick = { _onJoinButtonClick }
  332. onKeyPress = { _onJoinKeyPress }
  333. onOptionsClick = { _onOptionsClick }
  334. role = 'button'
  335. tabIndex = { 0 }
  336. testId = 'prejoin.joinMeeting'
  337. type = 'primary'>
  338. { t('prejoin.joinMeeting') }
  339. </ActionButton>
  340. </InlineDialog>
  341. </div>
  342. </div>
  343. { showDialog && (
  344. <JoinByPhoneDialog
  345. joinConferenceWithoutAudio = { joinConferenceWithoutAudio }
  346. onClose = { _closeDialog } />
  347. )}
  348. </PreMeetingScreen>
  349. );
  350. }
  351. /**
  352. * Renders the 'skip prejoin' button.
  353. *
  354. * @returns {React$Element}
  355. */
  356. _renderSkipPrejoinButton() {
  357. const { buttonIsToggled, t } = this.props;
  358. return (
  359. <div className = 'prejoin-checkbox-container'>
  360. <ToggleButton
  361. isToggled = { buttonIsToggled }
  362. onClick = { this._onToggleButtonClick }>
  363. {t('prejoin.doNotShow')}
  364. </ToggleButton>
  365. </div>
  366. );
  367. }
  368. }
  369. /**
  370. * Maps (parts of) the redux state to the React {@code Component} props.
  371. *
  372. * @param {Object} state - The redux state.
  373. * @returns {Object}
  374. */
  375. function mapStateToProps(state): Object {
  376. const name = getDisplayName(state);
  377. const showErrorOnJoin = isDisplayNameRequired(state) && !name;
  378. return {
  379. buttonIsToggled: isPrejoinSkipped(state),
  380. name,
  381. deviceStatusVisible: isDeviceStatusVisible(state),
  382. roomName: getRoomName(state),
  383. showDialog: isJoinByPhoneDialogVisible(state),
  384. showErrorOnJoin,
  385. hasJoinByPhoneButton: isJoinByPhoneButtonVisible(state),
  386. showCameraPreview: !isVideoMutedByUser(state),
  387. videoTrack: getLocalJitsiVideoTrack(state)
  388. };
  389. }
  390. const mapDispatchToProps = {
  391. joinConferenceWithoutAudio: joinConferenceWithoutAudioAction,
  392. joinConference: joinConferenceAction,
  393. setJoinByPhoneDialogVisiblity: setJoinByPhoneDialogVisiblityAction,
  394. setSkipPrejoin: setSkipPrejoinAction,
  395. updateSettings
  396. };
  397. export default connect(mapStateToProps, mapDispatchToProps)(translate(Prejoin));