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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 { Watermarks } from '../../base/react';
  11. import { HideNotificationBarStyle } from '../../unsupported-browser';
  12. import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
  13. /**
  14. * The Web container rendering the welcome page.
  15. *
  16. * @extends AbstractWelcomePage
  17. */
  18. class WelcomePage extends AbstractWelcomePage {
  19. /**
  20. * Initializes a new WelcomePage instance.
  21. *
  22. * @param {Object} props - The read-only properties with which the new
  23. * instance is to be initialized.
  24. */
  25. constructor(props) {
  26. super(props);
  27. this.state = {
  28. ...this.state,
  29. generateRoomnames:
  30. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE
  31. };
  32. /**
  33. * The HTML Element used as the container for additional content. Used
  34. * for directly appending the additional content template to the dom
  35. *
  36. * @private
  37. * @type {HTMLTemplateElement|null}
  38. */
  39. this._additionalContentRef = null;
  40. /**
  41. * The template to use as the main content for the welcome page. If
  42. * not found then only the welcome page head will display.
  43. *
  44. * @private
  45. * @type {HTMLTemplateElement|null}
  46. */
  47. this._additionalContentTemplate = document.getElementById(
  48. 'welcome-page-additional-content-template');
  49. // Bind event handlers so they are only bound once per instance.
  50. this._onFormSubmit = this._onFormSubmit.bind(this);
  51. this._onRoomChange = this._onRoomChange.bind(this);
  52. this._setAdditionalContentRef
  53. = this._setAdditionalContentRef.bind(this);
  54. }
  55. /**
  56. * Implements React's {@link Component#componentDidMount()}. Invoked
  57. * immediately after this component is mounted.
  58. *
  59. * @inheritdoc
  60. * @returns {void}
  61. */
  62. componentDidMount() {
  63. document.body.classList.add('welcome-page');
  64. // FIXME: This is not the best place for this logic. Ideally we should
  65. // use features/base/lib-jitsi-meet#initLib() action for this use case.
  66. // But currently lib-jitsi-meet#initLib()'s logic works for mobile only
  67. // (on web it ends up with infinite loop over initLib).
  68. JitsiMeetJS.init({
  69. enableAnalyticsLogging: isAnalyticsEnabled(APP.store),
  70. ...config
  71. }).then(() => {
  72. initAnalytics(APP.store);
  73. });
  74. if (this.state.generateRoomnames) {
  75. this._updateRoomname();
  76. }
  77. if (this._shouldShowAdditionalContent()) {
  78. this._additionalContentRef.appendChild(
  79. this._additionalContentTemplate.content.cloneNode(true));
  80. }
  81. }
  82. /**
  83. * Removes the classname used for custom styling of the welcome page.
  84. *
  85. * @inheritdoc
  86. * @returns {void}
  87. */
  88. 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));