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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. /* global interfaceConfig */
  2. import React from 'react';
  3. import { isMobileBrowser } from '../../base/environment/utils';
  4. import { translate, translateToHTML } 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. *
  16. * @type {string}
  17. */
  18. export const ROOM_NAME_VALIDATE_PATTERN_STR = '^[^?&:\u0022\u0027%#]+$';
  19. /**
  20. * The Web container rendering the welcome page.
  21. *
  22. * @augments AbstractWelcomePage
  23. */
  24. class WelcomePage extends AbstractWelcomePage {
  25. /**
  26. * Default values for {@code WelcomePage} component's properties.
  27. *
  28. * @static
  29. */
  30. static defaultProps = {
  31. _room: ''
  32. };
  33. /**
  34. * Initializes a new WelcomePage instance.
  35. *
  36. * @param {Object} props - The read-only properties with which the new
  37. * instance is to be initialized.
  38. */
  39. constructor(props) {
  40. super(props);
  41. this.state = {
  42. ...this.state,
  43. generateRoomnames:
  44. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE,
  45. selectedTab: 0
  46. };
  47. /**
  48. * The HTML Element used as the container for additional content. Used
  49. * for directly appending the additional content template to the dom.
  50. *
  51. * @private
  52. * @type {HTMLTemplateElement|null}
  53. */
  54. this._additionalContentRef = null;
  55. this._roomInputRef = null;
  56. /**
  57. * The HTML Element used as the container for additional toolbar content. Used
  58. * for directly appending the additional content template to the dom.
  59. *
  60. * @private
  61. * @type {HTMLTemplateElement|null}
  62. */
  63. this._additionalToolbarContentRef = null;
  64. this._additionalCardRef = null;
  65. /**
  66. * The template to use as the additional card displayed near the main one.
  67. *
  68. * @private
  69. * @type {HTMLTemplateElement|null}
  70. */
  71. this._additionalCardTemplate = document.getElementById(
  72. 'welcome-page-additional-card-template');
  73. /**
  74. * The template to use as the main content for the welcome page. If
  75. * not found then only the welcome page head will display.
  76. *
  77. * @private
  78. * @type {HTMLTemplateElement|null}
  79. */
  80. this._additionalContentTemplate = document.getElementById(
  81. 'welcome-page-additional-content-template');
  82. /**
  83. * The template to use as the additional content for the welcome page header toolbar.
  84. * If not found then only the settings icon will be displayed.
  85. *
  86. * @private
  87. * @type {HTMLTemplateElement|null}
  88. */
  89. this._additionalToolbarContentTemplate = document.getElementById(
  90. 'settings-toolbar-additional-content-template'
  91. );
  92. // Bind event handlers so they are only bound once per instance.
  93. this._onFormSubmit = this._onFormSubmit.bind(this);
  94. this._onRoomChange = this._onRoomChange.bind(this);
  95. this._setAdditionalCardRef = this._setAdditionalCardRef.bind(this);
  96. this._setAdditionalContentRef
  97. = this._setAdditionalContentRef.bind(this);
  98. this._setRoomInputRef = this._setRoomInputRef.bind(this);
  99. this._setAdditionalToolbarContentRef
  100. = this._setAdditionalToolbarContentRef.bind(this);
  101. this._onTabSelected = this._onTabSelected.bind(this);
  102. this._renderFooter = this._renderFooter.bind(this);
  103. }
  104. /**
  105. * Implements React's {@link Component#componentDidMount()}. Invoked
  106. * immediately after this component is mounted.
  107. *
  108. * @inheritdoc
  109. * @returns {void}
  110. */
  111. componentDidMount() {
  112. super.componentDidMount();
  113. document.body.classList.add('welcome-page');
  114. document.title = interfaceConfig.APP_NAME;
  115. if (this.state.generateRoomnames) {
  116. this._updateRoomname();
  117. }
  118. if (this._shouldShowAdditionalContent()) {
  119. this._additionalContentRef.appendChild(
  120. this._additionalContentTemplate.content.cloneNode(true));
  121. }
  122. if (this._shouldShowAdditionalToolbarContent()) {
  123. this._additionalToolbarContentRef.appendChild(
  124. this._additionalToolbarContentTemplate.content.cloneNode(true)
  125. );
  126. }
  127. if (this._shouldShowAdditionalCard()) {
  128. this._additionalCardRef.appendChild(
  129. this._additionalCardTemplate.content.cloneNode(true)
  130. );
  131. }
  132. }
  133. /**
  134. * Removes the classname used for custom styling of the welcome page.
  135. *
  136. * @inheritdoc
  137. * @returns {void}
  138. */
  139. componentWillUnmount() {
  140. super.componentWillUnmount();
  141. document.body.classList.remove('welcome-page');
  142. }
  143. /**
  144. * Implements React's {@link Component#render()}.
  145. *
  146. * @inheritdoc
  147. * @returns {ReactElement|null}
  148. */
  149. render() {
  150. const { _moderatedRoomServiceUrl, t } = this.props;
  151. const { DEFAULT_WELCOME_PAGE_LOGO_URL, DISPLAY_WELCOME_FOOTER } = interfaceConfig;
  152. const showAdditionalCard = this._shouldShowAdditionalCard();
  153. const showAdditionalContent = this._shouldShowAdditionalContent();
  154. const showAdditionalToolbarContent = this._shouldShowAdditionalToolbarContent();
  155. const contentClassName = showAdditionalContent ? 'with-content' : 'without-content';
  156. const footerClassName = DISPLAY_WELCOME_FOOTER ? 'with-footer' : 'without-footer';
  157. return (
  158. <div
  159. className = { `welcome ${contentClassName} ${footerClassName}` }
  160. id = 'welcome_page'>
  161. <div className = 'welcome-watermark'>
  162. <Watermarks defaultJitsiLogoURL = { DEFAULT_WELCOME_PAGE_LOGO_URL } />
  163. </div>
  164. <div className = 'header'>
  165. <div className = 'welcome-page-settings'>
  166. <SettingsButton
  167. defaultTab = { SETTINGS_TABS.CALENDAR } />
  168. { showAdditionalToolbarContent
  169. ? <div
  170. className = 'settings-toolbar-content'
  171. ref = { this._setAdditionalToolbarContentRef } />
  172. : null
  173. }
  174. </div>
  175. <div className = 'header-image' />
  176. <div className = 'header-container'>
  177. <h1 className = 'header-text-title'>
  178. { t('welcomepage.headerTitle') }
  179. </h1>
  180. <span className = 'header-text-subtitle'>
  181. { t('welcomepage.headerSubtitle')}
  182. </span>
  183. <div id = 'enter_room'>
  184. <div className = 'enter-room-input-container'>
  185. <form onSubmit = { this._onFormSubmit }>
  186. <input
  187. aria-disabled = 'false'
  188. aria-label = 'Meeting name input'
  189. autoFocus = { true }
  190. className = 'enter-room-input'
  191. id = 'enter_room_field'
  192. onChange = { this._onRoomChange }
  193. pattern = { ROOM_NAME_VALIDATE_PATTERN_STR }
  194. placeholder = { this.state.roomPlaceholder }
  195. ref = { this._setRoomInputRef }
  196. title = { t('welcomepage.roomNameAllowedChars') }
  197. type = 'text'
  198. value = { this.state.room } />
  199. <div
  200. className = { _moderatedRoomServiceUrl
  201. ? 'warning-with-link'
  202. : 'warning-without-link' }>
  203. { this._renderInsecureRoomNameWarning() }
  204. </div>
  205. </form>
  206. </div>
  207. <button
  208. aria-disabled = 'false'
  209. aria-label = 'Start meeting'
  210. className = 'welcome-page-button'
  211. id = 'enter_room_button'
  212. onClick = { this._onFormSubmit }
  213. tabIndex = '0'
  214. type = 'button'>
  215. { t('welcomepage.startMeeting') }
  216. </button>
  217. </div>
  218. { _moderatedRoomServiceUrl && (
  219. <div id = 'moderated-meetings'>
  220. <p>
  221. {
  222. translateToHTML(
  223. t, 'welcomepage.moderatedMessage', { url: _moderatedRoomServiceUrl })
  224. }
  225. </p>
  226. </div>)}
  227. </div>
  228. </div>
  229. <div className = 'welcome-cards-container'>
  230. <div className = 'welcome-card-row'>
  231. <div className = 'welcome-tabs welcome-card welcome-card--blue'>
  232. { this._renderTabs() }
  233. </div>
  234. { showAdditionalCard
  235. ? <div
  236. className = 'welcome-card welcome-card--dark'
  237. ref = { this._setAdditionalCardRef } />
  238. : null }
  239. </div>
  240. { showAdditionalContent
  241. ? <div
  242. className = 'welcome-page-content'
  243. ref = { this._setAdditionalContentRef } />
  244. : null }
  245. </div>
  246. { DISPLAY_WELCOME_FOOTER && this._renderFooter()}
  247. </div>
  248. );
  249. }
  250. /**
  251. * Renders the insecure room name warning.
  252. *
  253. * @inheritdoc
  254. */
  255. _doRenderInsecureRoomNameWarning() {
  256. return (
  257. <div className = 'insecure-room-name-warning'>
  258. <Icon src = { IconWarning } />
  259. <span>
  260. { this.props.t('security.insecureRoomNameWarning') }
  261. </span>
  262. </div>
  263. );
  264. }
  265. /**
  266. * Prevents submission of the form and delegates join logic.
  267. *
  268. * @param {Event} event - The HTML Event which details the form submission.
  269. * @private
  270. * @returns {void}
  271. */
  272. _onFormSubmit(event) {
  273. event.preventDefault();
  274. if (!this._roomInputRef || this._roomInputRef.reportValidity()) {
  275. this._onJoin();
  276. }
  277. }
  278. /**
  279. * Overrides the super to account for the differences in the argument types
  280. * provided by HTML and React Native text inputs.
  281. *
  282. * @inheritdoc
  283. * @override
  284. * @param {Event} event - The (HTML) Event which details the change such as
  285. * the EventTarget.
  286. * @protected
  287. */
  288. _onRoomChange(event) {
  289. super._onRoomChange(event.target.value);
  290. }
  291. /**
  292. * Callback invoked when the desired tab to display should be changed.
  293. *
  294. * @param {number} tabIndex - The index of the tab within the array of
  295. * displayed tabs.
  296. * @private
  297. * @returns {void}
  298. */
  299. _onTabSelected(tabIndex) {
  300. this.setState({ selectedTab: tabIndex });
  301. }
  302. /**
  303. * Renders the footer.
  304. *
  305. * @returns {ReactElement}
  306. */
  307. _renderFooter() {
  308. const { t } = this.props;
  309. const {
  310. MOBILE_DOWNLOAD_LINK_ANDROID,
  311. MOBILE_DOWNLOAD_LINK_F_DROID,
  312. MOBILE_DOWNLOAD_LINK_IOS
  313. } = interfaceConfig;
  314. return (<footer className = 'welcome-footer'>
  315. <div className = 'welcome-footer-centered'>
  316. <div className = 'welcome-footer-padded'>
  317. <div className = 'welcome-footer-row-block welcome-footer--row-1'>
  318. <div className = 'welcome-footer-row-1-text'>{t('welcomepage.jitsiOnMobile')}</div>
  319. <a
  320. className = 'welcome-badge'
  321. href = { MOBILE_DOWNLOAD_LINK_IOS }>
  322. <img
  323. alt = { t('welcomepage.mobileDownLoadLinkIos') }
  324. src = './images/app-store-badge.png' />
  325. </a>
  326. <a
  327. className = 'welcome-badge'
  328. href = { MOBILE_DOWNLOAD_LINK_ANDROID }>
  329. <img
  330. alt = { t('welcomepage.mobileDownLoadLinkAndroid') }
  331. src = './images/google-play-badge.png' />
  332. </a>
  333. <a
  334. className = 'welcome-badge'
  335. href = { MOBILE_DOWNLOAD_LINK_F_DROID }>
  336. <img
  337. alt = { t('welcomepage.mobileDownLoadLinkFDroid') }
  338. src = './images/f-droid-badge.png' />
  339. </a>
  340. </div>
  341. </div>
  342. </div>
  343. </footer>);
  344. }
  345. /**
  346. * Renders tabs to show previous meetings and upcoming calendar events. The
  347. * tabs are purposefully hidden on mobile browsers.
  348. *
  349. * @returns {ReactElement|null}
  350. */
  351. _renderTabs() {
  352. if (isMobileBrowser()) {
  353. return null;
  354. }
  355. const { _calendarEnabled, _recentListEnabled, t } = this.props;
  356. const tabs = [];
  357. if (_calendarEnabled) {
  358. tabs.push({
  359. label: t('welcomepage.calendar'),
  360. content: <CalendarList />
  361. });
  362. }
  363. if (_recentListEnabled) {
  364. tabs.push({
  365. label: t('welcomepage.recentList'),
  366. content: <RecentList />
  367. });
  368. }
  369. if (tabs.length === 0) {
  370. return null;
  371. }
  372. return (
  373. <Tabs
  374. onSelect = { this._onTabSelected }
  375. selected = { this.state.selectedTab }
  376. tabs = { tabs } />);
  377. }
  378. /**
  379. * Sets the internal reference to the HTMLDivElement used to hold the
  380. * additional card shown near the tabs card.
  381. *
  382. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  383. * of the welcome page content.
  384. * @private
  385. * @returns {void}
  386. */
  387. _setAdditionalCardRef(el) {
  388. this._additionalCardRef = el;
  389. }
  390. /**
  391. * Sets the internal reference to the HTMLDivElement used to hold the
  392. * welcome page content.
  393. *
  394. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  395. * of the welcome page content.
  396. * @private
  397. * @returns {void}
  398. */
  399. _setAdditionalContentRef(el) {
  400. this._additionalContentRef = el;
  401. }
  402. /**
  403. * Sets the internal reference to the HTMLDivElement used to hold the
  404. * toolbar additional content.
  405. *
  406. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  407. * of the additional toolbar content.
  408. * @private
  409. * @returns {void}
  410. */
  411. _setAdditionalToolbarContentRef(el) {
  412. this._additionalToolbarContentRef = el;
  413. }
  414. /**
  415. * Sets the internal reference to the HTMLInputElement used to hold the
  416. * welcome page input room element.
  417. *
  418. * @param {HTMLInputElement} el - The HTMLElement for the input of the room name on the welcome page.
  419. * @private
  420. * @returns {void}
  421. */
  422. _setRoomInputRef(el) {
  423. this._roomInputRef = el;
  424. }
  425. /**
  426. * Returns whether or not an additional card should be displayed near the tabs.
  427. *
  428. * @private
  429. * @returns {boolean}
  430. */
  431. _shouldShowAdditionalCard() {
  432. return interfaceConfig.DISPLAY_WELCOME_PAGE_ADDITIONAL_CARD
  433. && this._additionalCardTemplate
  434. && this._additionalCardTemplate.content
  435. && this._additionalCardTemplate.innerHTML.trim();
  436. }
  437. /**
  438. * Returns whether or not additional content should be displayed below
  439. * the welcome page's header for entering a room name.
  440. *
  441. * @private
  442. * @returns {boolean}
  443. */
  444. _shouldShowAdditionalContent() {
  445. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  446. && this._additionalContentTemplate
  447. && this._additionalContentTemplate.content
  448. && this._additionalContentTemplate.innerHTML.trim();
  449. }
  450. /**
  451. * Returns whether or not additional content should be displayed inside
  452. * the header toolbar.
  453. *
  454. * @private
  455. * @returns {boolean}
  456. */
  457. _shouldShowAdditionalToolbarContent() {
  458. return interfaceConfig.DISPLAY_WELCOME_PAGE_TOOLBAR_ADDITIONAL_CONTENT
  459. && this._additionalToolbarContentTemplate
  460. && this._additionalToolbarContentTemplate.content
  461. && this._additionalToolbarContentTemplate.innerHTML.trim();
  462. }
  463. }
  464. export default translate(connect(_mapStateToProps)(WelcomePage));