Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

WelcomePage.web.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 { 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. // FIXME: This is not the best place for this logic. Ideally we should
  63. // use features/base/lib-jitsi-meet#initLib() action for this use case.
  64. // But currently lib-jitsi-meet#initLib()'s logic works for mobile only
  65. // (on web it ends up with infinite loop over initLib).
  66. JitsiMeetJS.init({
  67. enableAnalyticsLogging: isAnalyticsEnabled(APP.store),
  68. ...config
  69. }).then(() => {
  70. initAnalytics(APP.store);
  71. });
  72. if (this.state.generateRoomnames) {
  73. this._updateRoomname();
  74. }
  75. if (this._shouldShowAdditionalContent()) {
  76. this._additionalContentRef.appendChild(
  77. this._additionalContentTemplate.content.cloneNode(true));
  78. }
  79. }
  80. /**
  81. * Implements React's {@link Component#render()}.
  82. *
  83. * @inheritdoc
  84. * @returns {ReactElement|null}
  85. */
  86. render() {
  87. const { t } = this.props;
  88. const { APP_NAME } = interfaceConfig;
  89. const showAdditionalContent = this._shouldShowAdditionalContent();
  90. return (
  91. <AtlasKitThemeProvider mode = 'light'>
  92. <div
  93. className = { `welcome ${showAdditionalContent
  94. ? 'with-content' : 'without-content'}` }
  95. id = 'new_welcome_page'>
  96. <div className = 'header'>
  97. <div className = 'header-image' />
  98. <Watermarks />
  99. <div className = 'header-text'>
  100. <h1 className = 'header-text-title'>
  101. { t('welcomepage.title') }
  102. </h1>
  103. <p className = 'header-text-description'>
  104. { t('welcomepage.appDescription',
  105. { app: APP_NAME }) }
  106. </p>
  107. </div>
  108. <div id = 'new_enter_room'>
  109. <form
  110. className = 'enter-room-input'
  111. onSubmit = { this._onFormSubmit }>
  112. <FieldTextStateless
  113. autoFocus = { true }
  114. id = 'enter_room_field'
  115. isLabelHidden = { true }
  116. label = 'enter_room_field'
  117. onChange = { this._onRoomChange }
  118. placeholder = { this.state.roomPlaceholder }
  119. shouldFitContainer = { true }
  120. type = 'text'
  121. value = { this.state.room } />
  122. </form>
  123. <Button
  124. appearance = 'primary'
  125. className = 'welcome-page-button'
  126. id = 'enter_room_button'
  127. onClick = { this._onJoin }
  128. type = 'button'>
  129. { t('welcomepage.go') }
  130. </Button>
  131. </div>
  132. </div>
  133. { showAdditionalContent
  134. ? <div
  135. className = 'welcome-page-content'
  136. ref = { this._setAdditionalContentRef } />
  137. : null }
  138. </div>
  139. </AtlasKitThemeProvider>
  140. );
  141. }
  142. /**
  143. * Prevents submission of the form and delagates join logic.
  144. *
  145. * @param {Event} event - The HTML Event which details the form submission.
  146. * @private
  147. * @returns {void}
  148. */
  149. _onFormSubmit(event) {
  150. event.preventDefault();
  151. this._onJoin();
  152. }
  153. /**
  154. * Overrides the super to account for the differences in the argument types
  155. * provided by HTML and React Native text inputs.
  156. *
  157. * @inheritdoc
  158. * @override
  159. * @param {Event} event - The (HTML) Event which details the change such as
  160. * the EventTarget.
  161. * @protected
  162. */
  163. _onRoomChange(event) {
  164. super._onRoomChange(event.target.value);
  165. }
  166. /**
  167. * Sets the internal reference to the HTMLDivElement used to hold the
  168. * welcome page content.
  169. *
  170. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  171. * of the welcome page content.
  172. * @private
  173. * @returns {void}
  174. */
  175. _setAdditionalContentRef(el) {
  176. this._additionalContentRef = el;
  177. }
  178. /**
  179. * Returns whether or not additional content should be displayed belowed
  180. * the welcome page's header for entering a room name.
  181. *
  182. * @private
  183. * @returns {boolean}
  184. */
  185. _shouldShowAdditionalContent() {
  186. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  187. && this._additionalContentTemplate
  188. && this._additionalContentTemplate.content
  189. && this._additionalContentTemplate.innerHTML.trim();
  190. }
  191. }
  192. export default translate(connect(_mapStateToProps)(WelcomePage));