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.

WelcomePage.web.js 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* global APP, config, interfaceConfig, JitsiMeetJS */
  2. import Button from '@atlaskit/button';
  3. import { FieldTextStateless } from '@atlaskit/field-text';
  4. import { AtlasKitThemeProvider } from '@atlaskit/theme';
  5. import React from 'react';
  6. import { connect } from 'react-redux';
  7. import { initAnalytics } from '../../analytics';
  8. import { translate } from '../../base/i18n';
  9. import { isAnalyticsEnabled } from '../../base/lib-jitsi-meet';
  10. import { HideNotificationBarStyle, Watermarks } from '../../base/react';
  11. import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
  12. /**
  13. * The Web container rendering the welcome page.
  14. *
  15. * @extends AbstractWelcomePage
  16. */
  17. class WelcomePage extends AbstractWelcomePage {
  18. /**
  19. * Initializes a new WelcomePage instance.
  20. *
  21. * @param {Object} props - The read-only properties with which the new
  22. * instance is to be initialized.
  23. */
  24. constructor(props) {
  25. super(props);
  26. this.state = {
  27. ...this.state,
  28. generateRoomnames:
  29. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE
  30. };
  31. /**
  32. * The HTML Element used as the container for additional content. Used
  33. * for directly appending the additional content template to the dom
  34. *
  35. * @private
  36. * @type {HTMLTemplateElement|null}
  37. */
  38. this._additionalContentRef = null;
  39. /**
  40. * The template to use as the main content for the welcome page. If
  41. * not found then only the welcome page head will display.
  42. *
  43. * @private
  44. * @type {HTMLTemplateElement|null}
  45. */
  46. this._additionalContentTemplate = document.getElementById(
  47. 'welcome-page-additional-content-template');
  48. // Bind event handlers so they are only bound once per instance.
  49. this._onFormSubmit = this._onFormSubmit.bind(this);
  50. this._onRoomChange = this._onRoomChange.bind(this);
  51. this._setAdditionalContentRef
  52. = this._setAdditionalContentRef.bind(this);
  53. }
  54. /**
  55. * Implements React's {@link Component#componentDidMount()}. Invoked
  56. * immediately after this component is mounted.
  57. *
  58. * @inheritdoc
  59. * @returns {void}
  60. */
  61. componentDidMount() {
  62. document.body.classList.add('welcome-page');
  63. // FIXME: This is not the best place for this logic. Ideally we should
  64. // use features/base/lib-jitsi-meet#initLib() action for this use case.
  65. // But currently lib-jitsi-meet#initLib()'s logic works for mobile only
  66. // (on web it ends up with infinite loop over initLib).
  67. JitsiMeetJS.init({
  68. enableAnalyticsLogging: isAnalyticsEnabled(APP.store),
  69. ...config
  70. }).then(() => {
  71. initAnalytics(APP.store);
  72. });
  73. if (this.state.generateRoomnames) {
  74. this._updateRoomname();
  75. }
  76. if (this._shouldShowAdditionalContent()) {
  77. this._additionalContentRef.appendChild(
  78. this._additionalContentTemplate.content.cloneNode(true));
  79. }
  80. }
  81. /**
  82. * Removes the classname used for custom styling of the welcome page.
  83. *
  84. * @inheritdoc
  85. * @returns {void}
  86. */
  87. componentWillUnmount() {
  88. super.componentWillUnmount();
  89. document.body.classList.remove('welcome-page');
  90. }
  91. /**
  92. * Implements React's {@link Component#render()}.
  93. *
  94. * @inheritdoc
  95. * @returns {ReactElement|null}
  96. */
  97. render() {
  98. const { t } = this.props;
  99. const { APP_NAME } = interfaceConfig;
  100. const showAdditionalContent = this._shouldShowAdditionalContent();
  101. return (
  102. <AtlasKitThemeProvider mode = 'light'>
  103. <div
  104. className = { `welcome ${showAdditionalContent
  105. ? 'with-content' : 'without-content'}` }
  106. id = 'new_welcome_page'>
  107. <div className = 'header'>
  108. <div className = 'header-image' />
  109. <Watermarks />
  110. <div className = 'header-text'>
  111. <h1 className = 'header-text-title'>
  112. { t('welcomepage.title') }
  113. </h1>
  114. <p className = 'header-text-description'>
  115. { t('welcomepage.appDescription',
  116. { app: APP_NAME }) }
  117. </p>
  118. </div>
  119. <div id = 'new_enter_room'>
  120. <form
  121. className = 'enter-room-input'
  122. onSubmit = { this._onFormSubmit }>
  123. <FieldTextStateless
  124. autoFocus = { true }
  125. id = 'enter_room_field'
  126. isLabelHidden = { true }
  127. label = 'enter_room_field'
  128. onChange = { this._onRoomChange }
  129. placeholder = { this.state.roomPlaceholder }
  130. shouldFitContainer = { true }
  131. type = 'text'
  132. value = { this.state.room } />
  133. </form>
  134. <Button
  135. appearance = 'primary'
  136. className = 'welcome-page-button'
  137. id = 'enter_room_button'
  138. onClick = { this._onJoin }
  139. type = 'button'>
  140. { t('welcomepage.go') }
  141. </Button>
  142. </div>
  143. </div>
  144. { showAdditionalContent
  145. ? <div
  146. className = 'welcome-page-content'
  147. ref = { this._setAdditionalContentRef } />
  148. : null }
  149. </div>
  150. <HideNotificationBarStyle />
  151. </AtlasKitThemeProvider>
  152. );
  153. }
  154. /**
  155. * Prevents submission of the form and delagates join logic.
  156. *
  157. * @param {Event} event - The HTML Event which details the form submission.
  158. * @private
  159. * @returns {void}
  160. */
  161. _onFormSubmit(event) {
  162. event.preventDefault();
  163. this._onJoin();
  164. }
  165. /**
  166. * Overrides the super to account for the differences in the argument types
  167. * provided by HTML and React Native text inputs.
  168. *
  169. * @inheritdoc
  170. * @override
  171. * @param {Event} event - The (HTML) Event which details the change such as
  172. * the EventTarget.
  173. * @protected
  174. */
  175. _onRoomChange(event) {
  176. super._onRoomChange(event.target.value);
  177. }
  178. /**
  179. * Sets the internal reference to the HTMLDivElement used to hold the
  180. * welcome page content.
  181. *
  182. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  183. * of the welcome page content.
  184. * @private
  185. * @returns {void}
  186. */
  187. _setAdditionalContentRef(el) {
  188. this._additionalContentRef = el;
  189. }
  190. /**
  191. * Returns whether or not additional content should be displayed belowed
  192. * the welcome page's header for entering a room name.
  193. *
  194. * @private
  195. * @returns {boolean}
  196. */
  197. _shouldShowAdditionalContent() {
  198. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  199. && this._additionalContentTemplate
  200. && this._additionalContentTemplate.content
  201. && this._additionalContentTemplate.innerHTML.trim();
  202. }
  203. }
  204. export default translate(connect(_mapStateToProps)(WelcomePage));