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

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