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.

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