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.

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