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 13KB

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