您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Prejoin.js 13KB

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