Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Prejoin.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. * If join button is disabled or not.
  44. */
  45. joinButtonDisabled: boolean,
  46. /**
  47. * Joins the current meeting.
  48. */
  49. joinConference: Function,
  50. /**
  51. * Joins the current meeting without audio.
  52. */
  53. joinConferenceWithoutAudio: Function,
  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. * The name of the meeting that is about to be joined.
  64. */
  65. roomName: string,
  66. /**
  67. * Sets visibility of the prejoin page for the next sessions.
  68. */
  69. setSkipPrejoin: Function,
  70. /**
  71. * Sets visibility of the 'JoinByPhoneDialog'.
  72. */
  73. setJoinByPhoneDialogVisiblity: Function,
  74. /**
  75. * Indicates whether the avatar should be shown when video is off
  76. */
  77. showAvatar: boolean,
  78. /**
  79. * Flag signaling the visibility of camera preview.
  80. */
  81. showCameraPreview: 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 'join by phone' buttons.
  110. */
  111. showJoinByPhoneButtons: boolean
  112. }
  113. /**
  114. * This component is displayed before joining a meeting.
  115. */
  116. class Prejoin extends Component<Props, State> {
  117. /**
  118. * Default values for {@code Prejoin} component's properties.
  119. *
  120. * @static
  121. */
  122. static defaultProps = {
  123. showConferenceInfo: true,
  124. showJoinActions: true,
  125. showSkipPrejoin: true
  126. };
  127. /**
  128. * Initializes a new {@code Prejoin} instance.
  129. *
  130. * @inheritdoc
  131. */
  132. constructor(props) {
  133. super(props);
  134. this.state = {
  135. showJoinByPhoneButtons: false
  136. };
  137. this._closeDialog = this._closeDialog.bind(this);
  138. this._showDialog = this._showDialog.bind(this);
  139. this._onToggleButtonClick = this._onToggleButtonClick.bind(this);
  140. this._onDropdownClose = this._onDropdownClose.bind(this);
  141. this._onOptionsClick = this._onOptionsClick.bind(this);
  142. this._setName = this._setName.bind(this);
  143. }
  144. _onToggleButtonClick: () => void;
  145. /**
  146. * Handler for the toggle button.
  147. *
  148. * @param {Object} e - The synthetic event.
  149. * @returns {void}
  150. */
  151. _onToggleButtonClick() {
  152. this.props.setSkipPrejoin(!this.props.buttonIsToggled);
  153. }
  154. _onDropdownClose: () => void;
  155. /**
  156. * Closes the dropdown.
  157. *
  158. * @returns {void}
  159. */
  160. _onDropdownClose() {
  161. this.setState({
  162. showJoinByPhoneButtons: false
  163. });
  164. }
  165. _onOptionsClick: () => void;
  166. /**
  167. * Displays the join by phone buttons dropdown.
  168. *
  169. * @param {Object} e - The synthetic event.
  170. * @returns {void}
  171. */
  172. _onOptionsClick(e) {
  173. e.stopPropagation();
  174. this.setState({
  175. showJoinByPhoneButtons: !this.state.showJoinByPhoneButtons
  176. });
  177. }
  178. _setName: () => void;
  179. /**
  180. * Sets the guest participant name.
  181. *
  182. * @param {string} displayName - Participant name.
  183. * @returns {void}
  184. */
  185. _setName(displayName) {
  186. this.props.updateSettings({
  187. displayName
  188. });
  189. }
  190. _closeDialog: () => void;
  191. /**
  192. * Closes the join by phone dialog.
  193. *
  194. * @returns {undefined}
  195. */
  196. _closeDialog() {
  197. this.props.setJoinByPhoneDialogVisiblity(false);
  198. }
  199. _showDialog: () => void;
  200. /**
  201. * Displays the dialog for joining a meeting by phone.
  202. *
  203. * @returns {undefined}
  204. */
  205. _showDialog() {
  206. this.props.setJoinByPhoneDialogVisiblity(true);
  207. this._onDropdownClose();
  208. }
  209. /**
  210. * Implements React's {@link Component#render()}.
  211. *
  212. * @inheritdoc
  213. * @returns {ReactElement}
  214. */
  215. render() {
  216. const {
  217. joinButtonDisabled,
  218. hasJoinByPhoneButton,
  219. joinConference,
  220. joinConferenceWithoutAudio,
  221. name,
  222. showAvatar,
  223. showCameraPreview,
  224. showDialog,
  225. showConferenceInfo,
  226. showJoinActions,
  227. t,
  228. videoTrack
  229. } = this.props;
  230. const { _closeDialog, _onDropdownClose, _onOptionsClick, _setName, _showDialog } = this;
  231. const { showJoinByPhoneButtons } = this.state;
  232. return (
  233. <PreMeetingScreen
  234. footer = { this._renderFooter() }
  235. name = { name }
  236. showAvatar = { showAvatar }
  237. showConferenceInfo = { showConferenceInfo }
  238. skipPrejoinButton = { this._renderSkipPrejoinButton() }
  239. title = { t('prejoin.joinMeeting') }
  240. videoMuted = { !showCameraPreview }
  241. videoTrack = { videoTrack }>
  242. {showJoinActions && (
  243. <div className = 'prejoin-input-area-container'>
  244. <div className = 'prejoin-input-area'>
  245. <InputField
  246. onChange = { _setName }
  247. onSubmit = { joinConference }
  248. placeHolder = { t('dialog.enterDisplayName') }
  249. value = { name } />
  250. <div className = 'prejoin-preview-dropdown-container'>
  251. <InlineDialog
  252. content = { <div className = 'prejoin-preview-dropdown-btns'>
  253. <div
  254. className = 'prejoin-preview-dropdown-btn'
  255. onClick = { joinConferenceWithoutAudio }>
  256. <Icon
  257. className = 'prejoin-preview-dropdown-icon'
  258. size = { 24 }
  259. src = { IconVolumeOff } />
  260. { t('prejoin.joinWithoutAudio') }
  261. </div>
  262. {hasJoinByPhoneButton && <div
  263. className = 'prejoin-preview-dropdown-btn'
  264. onClick = { _showDialog }>
  265. <Icon
  266. className = 'prejoin-preview-dropdown-icon'
  267. size = { 24 }
  268. src = { IconPhone } />
  269. { t('prejoin.joinAudioByPhone') }
  270. </div>}
  271. </div> }
  272. isOpen = { showJoinByPhoneButtons }
  273. onClose = { _onDropdownClose }>
  274. <ActionButton
  275. disabled = { joinButtonDisabled }
  276. hasOptions = { true }
  277. onClick = { joinConference }
  278. onOptionsClick = { _onOptionsClick }
  279. testId = 'prejoin.joinMeeting'
  280. type = 'primary'>
  281. { t('prejoin.joinMeeting') }
  282. </ActionButton>
  283. </InlineDialog>
  284. </div>
  285. </div>
  286. </div>
  287. )}
  288. { showDialog && (
  289. <JoinByPhoneDialog
  290. joinConferenceWithoutAudio = { joinConferenceWithoutAudio }
  291. onClose = { _closeDialog } />
  292. )}
  293. </PreMeetingScreen>
  294. );
  295. }
  296. /**
  297. * Renders the screen footer if any.
  298. *
  299. * @returns {React$Element}
  300. */
  301. _renderFooter() {
  302. return this.props.deviceStatusVisible && <DeviceStatus />;
  303. }
  304. /**
  305. * Renders the 'skip prejoin' button.
  306. *
  307. * @returns {React$Element}
  308. */
  309. _renderSkipPrejoinButton() {
  310. const { buttonIsToggled, t, showSkipPrejoin } = this.props;
  311. if (!showSkipPrejoin) {
  312. return null;
  313. }
  314. return (
  315. <div className = 'prejoin-checkbox-container'>
  316. <ToggleButton
  317. isToggled = { buttonIsToggled }
  318. onClick = { this._onToggleButtonClick }>
  319. {t('prejoin.doNotShow')}
  320. </ToggleButton>
  321. </div>
  322. );
  323. }
  324. }
  325. /**
  326. * Maps (parts of) the redux state to the React {@code Component} props.
  327. *
  328. * @param {Object} state - The redux state.
  329. * @param {Object} ownProps - The props passed to the component.
  330. * @returns {Object}
  331. */
  332. function mapStateToProps(state, ownProps): Object {
  333. const name = getDisplayName(state);
  334. const joinButtonDisabled = isDisplayNameRequired(state) && !name;
  335. const { showJoinActions } = ownProps;
  336. const isInviteButtonEnabled = isButtonEnabled('invite');
  337. // Hide conference info when interfaceConfig is available and the invite button is disabled.
  338. // In all other cases we want to preserve the behaviour and control the the conference info
  339. // visibility trough showJoinActions.
  340. const showConferenceInfo
  341. = typeof isInviteButtonEnabled === 'undefined' || isInviteButtonEnabled === true
  342. ? showJoinActions
  343. : false;
  344. return {
  345. buttonIsToggled: isPrejoinSkipped(state),
  346. joinButtonDisabled,
  347. name,
  348. deviceStatusVisible: isDeviceStatusVisible(state),
  349. roomName: getRoomName(state),
  350. showDialog: isJoinByPhoneDialogVisible(state),
  351. hasJoinByPhoneButton: isJoinByPhoneButtonVisible(state),
  352. showCameraPreview: !isVideoMutedByUser(state),
  353. showConferenceInfo,
  354. videoTrack: getLocalJitsiVideoTrack(state)
  355. };
  356. }
  357. const mapDispatchToProps = {
  358. joinConferenceWithoutAudio: joinConferenceWithoutAudioAction,
  359. joinConference: joinConferenceAction,
  360. setJoinByPhoneDialogVisiblity: setJoinByPhoneDialogVisiblityAction,
  361. setSkipPrejoin: setSkipPrejoinAction,
  362. updateSettings
  363. };
  364. export default connect(mapStateToProps, mapDispatchToProps)(translate(Prejoin));