您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

WelcomePage.web.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /* global interfaceConfig */
  2. import React from 'react';
  3. import { translate } from '../../base/i18n';
  4. import { Platform, Watermarks } from '../../base/react';
  5. import { connect } from '../../base/redux';
  6. import { CalendarList } from '../../calendar-sync';
  7. import { RecentList } from '../../recent-list';
  8. import { SettingsButton, SETTINGS_TABS } from '../../settings';
  9. import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
  10. import Tabs from './Tabs';
  11. /**
  12. * The pattern used to validate room name.
  13. * @type {string}
  14. */
  15. export const ROOM_NAME_VALIDATE_PATTERN_STR = '^[^?&:\u0022\u0027%#]+$';
  16. /**
  17. * Maximum number of pixels corresponding to a mobile layout.
  18. * @type {number}
  19. */
  20. const WINDOW_WIDTH_THRESHOLD = 425;
  21. /**
  22. * The Web container rendering the welcome page.
  23. *
  24. * @extends AbstractWelcomePage
  25. */
  26. class WelcomePage extends AbstractWelcomePage {
  27. /**
  28. * Default values for {@code WelcomePage} component's properties.
  29. *
  30. * @static
  31. */
  32. static defaultProps = {
  33. _room: ''
  34. };
  35. /**
  36. * Initializes a new WelcomePage instance.
  37. *
  38. * @param {Object} props - The read-only properties with which the new
  39. * instance is to be initialized.
  40. */
  41. constructor(props) {
  42. super(props);
  43. this.state = {
  44. ...this.state,
  45. generateRoomnames:
  46. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE,
  47. selectedTab: 0
  48. };
  49. /**
  50. * The HTML Element used as the container for additional content. Used
  51. * for directly appending the additional content template to the dom.
  52. *
  53. * @private
  54. * @type {HTMLTemplateElement|null}
  55. */
  56. this._additionalContentRef = null;
  57. this._roomInputRef = null;
  58. /**
  59. * The HTML Element used as the container for additional toolbar content. Used
  60. * for directly appending the additional content template to the dom.
  61. *
  62. * @private
  63. * @type {HTMLTemplateElement|null}
  64. */
  65. this._additionalToolbarContentRef = null;
  66. /**
  67. * The template to use as the main content for the welcome page. If
  68. * not found then only the welcome page head will display.
  69. *
  70. * @private
  71. * @type {HTMLTemplateElement|null}
  72. */
  73. this._additionalContentTemplate = document.getElementById(
  74. 'welcome-page-additional-content-template');
  75. /**
  76. * The template to use as the additional content for the welcome page header toolbar.
  77. * If not found then only the settings icon will be displayed.
  78. *
  79. * @private
  80. * @type {HTMLTemplateElement|null}
  81. */
  82. this._additionalToolbarContentTemplate = document.getElementById(
  83. 'settings-toolbar-additional-content-template'
  84. );
  85. // Bind event handlers so they are only bound once per instance.
  86. this._onFormSubmit = this._onFormSubmit.bind(this);
  87. this._onRoomChange = this._onRoomChange.bind(this);
  88. this._setAdditionalContentRef
  89. = this._setAdditionalContentRef.bind(this);
  90. this._setRoomInputRef = this._setRoomInputRef.bind(this);
  91. this._setAdditionalToolbarContentRef
  92. = this._setAdditionalToolbarContentRef.bind(this);
  93. this._onTabSelected = this._onTabSelected.bind(this);
  94. }
  95. /**
  96. * Implements React's {@link Component#componentDidMount()}. Invoked
  97. * immediately after this component is mounted.
  98. *
  99. * @inheritdoc
  100. * @returns {void}
  101. */
  102. componentDidMount() {
  103. super.componentDidMount();
  104. document.body.classList.add('welcome-page');
  105. document.title = interfaceConfig.APP_NAME;
  106. if (this.state.generateRoomnames) {
  107. this._updateRoomname();
  108. }
  109. if (this._shouldShowAdditionalContent()) {
  110. this._additionalContentRef.appendChild(
  111. this._additionalContentTemplate.content.cloneNode(true));
  112. }
  113. if (this._shouldShowAdditionalToolbarContent()) {
  114. this._additionalToolbarContentRef.appendChild(
  115. this._additionalToolbarContentTemplate.content.cloneNode(true)
  116. );
  117. }
  118. }
  119. /**
  120. * Removes the classname used for custom styling of the welcome page.
  121. *
  122. * @inheritdoc
  123. * @returns {void}
  124. */
  125. componentWillUnmount() {
  126. super.componentWillUnmount();
  127. document.body.classList.remove('welcome-page');
  128. }
  129. /**
  130. * Implements React's {@link Component#render()}.
  131. *
  132. * @inheritdoc
  133. * @returns {ReactElement|null}
  134. */
  135. render() {
  136. const { t } = this.props;
  137. const { APP_NAME } = interfaceConfig;
  138. const showAdditionalContent = this._shouldShowAdditionalContent();
  139. const showAdditionalToolbarContent = this._shouldShowAdditionalToolbarContent();
  140. const showResponsiveText = this._shouldShowResponsiveText();
  141. return (
  142. <div
  143. className = { `welcome ${showAdditionalContent
  144. ? 'with-content' : 'without-content'}` }
  145. id = 'welcome_page'>
  146. <div className = 'welcome-watermark'>
  147. <Watermarks />
  148. </div>
  149. <div className = 'header'>
  150. <div className = 'welcome-page-settings'>
  151. <SettingsButton
  152. defaultTab = { SETTINGS_TABS.CALENDAR } />
  153. { showAdditionalToolbarContent
  154. ? <div
  155. className = 'settings-toolbar-content'
  156. ref = { this._setAdditionalToolbarContentRef } />
  157. : null
  158. }
  159. </div>
  160. <div className = 'header-image' />
  161. <div className = 'header-text'>
  162. <h1 className = 'header-text-title'>
  163. { t('welcomepage.title') }
  164. </h1>
  165. <p className = 'header-text-description'>
  166. { t('welcomepage.appDescription',
  167. { app: APP_NAME }) }
  168. </p>
  169. </div>
  170. <div id = 'enter_room'>
  171. <div className = 'enter-room-input-container'>
  172. <div className = 'enter-room-title'>
  173. { t('welcomepage.enterRoomTitle') }
  174. </div>
  175. <form onSubmit = { this._onFormSubmit }>
  176. <input
  177. autoFocus = { true }
  178. className = 'enter-room-input'
  179. id = 'enter_room_field'
  180. onChange = { this._onRoomChange }
  181. pattern = { ROOM_NAME_VALIDATE_PATTERN_STR }
  182. placeholder = { this.state.roomPlaceholder }
  183. ref = { this._setRoomInputRef }
  184. title = { t('welcomepage.roomNameAllowedChars') }
  185. type = 'text'
  186. value = { this.state.room } />
  187. </form>
  188. </div>
  189. <div
  190. className = 'welcome-page-button'
  191. id = 'enter_room_button'
  192. onClick = { this._onFormSubmit }>
  193. {
  194. showResponsiveText
  195. ? t('welcomepage.goSmall')
  196. : t('welcomepage.go')
  197. }
  198. </div>
  199. </div>
  200. { this._renderTabs() }
  201. </div>
  202. { showAdditionalContent
  203. ? <div
  204. className = 'welcome-page-content'
  205. ref = { this._setAdditionalContentRef } />
  206. : null }
  207. </div>
  208. );
  209. }
  210. /**
  211. * Prevents submission of the form and delegates join logic.
  212. *
  213. * @param {Event} event - The HTML Event which details the form submission.
  214. * @private
  215. * @returns {void}
  216. */
  217. _onFormSubmit(event) {
  218. event.preventDefault();
  219. if (!this._roomInputRef || this._roomInputRef.reportValidity()) {
  220. this._onJoin();
  221. }
  222. }
  223. /**
  224. * Overrides the super to account for the differences in the argument types
  225. * provided by HTML and React Native text inputs.
  226. *
  227. * @inheritdoc
  228. * @override
  229. * @param {Event} event - The (HTML) Event which details the change such as
  230. * the EventTarget.
  231. * @protected
  232. */
  233. _onRoomChange(event) {
  234. super._onRoomChange(event.target.value);
  235. }
  236. /**
  237. * Callback invoked when the desired tab to display should be changed.
  238. *
  239. * @param {number} tabIndex - The index of the tab within the array of
  240. * displayed tabs.
  241. * @private
  242. * @returns {void}
  243. */
  244. _onTabSelected(tabIndex) {
  245. this.setState({ selectedTab: tabIndex });
  246. }
  247. /**
  248. * Renders tabs to show previous meetings and upcoming calendar events. The
  249. * tabs are purposefully hidden on mobile browsers.
  250. *
  251. * @returns {ReactElement|null}
  252. */
  253. _renderTabs() {
  254. const isMobileBrowser
  255. = Platform.OS === 'android' || Platform.OS === 'ios';
  256. if (isMobileBrowser) {
  257. return null;
  258. }
  259. const { _calendarEnabled, t } = this.props;
  260. const tabs = [];
  261. if (_calendarEnabled) {
  262. tabs.push({
  263. label: t('welcomepage.calendar'),
  264. content: <CalendarList />
  265. });
  266. }
  267. tabs.push({
  268. label: t('welcomepage.recentList'),
  269. content: <RecentList />
  270. });
  271. return (
  272. <Tabs
  273. onSelect = { this._onTabSelected }
  274. selected = { this.state.selectedTab }
  275. tabs = { tabs } />);
  276. }
  277. /**
  278. * Sets the internal reference to the HTMLDivElement used to hold the
  279. * welcome page content.
  280. *
  281. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  282. * of the welcome page content.
  283. * @private
  284. * @returns {void}
  285. */
  286. _setAdditionalContentRef(el) {
  287. this._additionalContentRef = el;
  288. }
  289. /**
  290. * Sets the internal reference to the HTMLDivElement used to hold the
  291. * toolbar additional content.
  292. *
  293. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  294. * of the additional toolbar content.
  295. * @private
  296. * @returns {void}
  297. */
  298. _setAdditionalToolbarContentRef(el) {
  299. this._additionalToolbarContentRef = el;
  300. }
  301. /**
  302. * Sets the internal reference to the HTMLInputElement used to hold the
  303. * welcome page input room element.
  304. *
  305. * @param {HTMLInputElement} el - The HTMLElement for the input of the room name on the welcome page.
  306. * @private
  307. * @returns {void}
  308. */
  309. _setRoomInputRef(el) {
  310. this._roomInputRef = el;
  311. }
  312. /**
  313. * Returns whether or not additional content should be displayed below
  314. * the welcome page's header for entering a room name.
  315. *
  316. * @private
  317. * @returns {boolean}
  318. */
  319. _shouldShowAdditionalContent() {
  320. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  321. && this._additionalContentTemplate
  322. && this._additionalContentTemplate.content
  323. && this._additionalContentTemplate.innerHTML.trim();
  324. }
  325. /**
  326. * Returns whether or not additional content should be displayed inside
  327. * the header toolbar.
  328. *
  329. * @private
  330. * @returns {boolean}
  331. */
  332. _shouldShowAdditionalToolbarContent() {
  333. return interfaceConfig.DISPLAY_WELCOME_PAGE_TOOLBAR_ADDITIONAL_CONTENT
  334. && this._additionalToolbarContentTemplate
  335. && this._additionalToolbarContentTemplate.content
  336. && this._additionalToolbarContentTemplate.innerHTML.trim();
  337. }
  338. /**
  339. * Returns whether or not the screen has a size smaller than a custom margin
  340. * and therefore display different text in the go button.
  341. *
  342. * @private
  343. * @returns {boolean}
  344. */
  345. _shouldShowResponsiveText() {
  346. const { innerWidth } = window;
  347. return innerWidth <= WINDOW_WIDTH_THRESHOLD;
  348. }
  349. }
  350. export default translate(connect(_mapStateToProps)(WelcomePage));