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.

Prejoin.js 11KB

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