Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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