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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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 { SETTINGS_TABS, SettingsButton } 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 = 'header'>
  162. <div className = 'header-image' />
  163. <div className = 'header-container'>
  164. <div className = 'header-watermark-container'>
  165. <div className = 'welcome-watermark'>
  166. <Watermarks
  167. defaultJitsiLogoURL = { DEFAULT_WELCOME_PAGE_LOGO_URL }
  168. noMargins = { true } />
  169. </div>
  170. </div>
  171. <div className = 'welcome-page-settings'>
  172. <SettingsButton
  173. defaultTab = { SETTINGS_TABS.CALENDAR }
  174. isDisplayedOnWelcomePage = { true } />
  175. { showAdditionalToolbarContent
  176. ? <div
  177. className = 'settings-toolbar-content'
  178. ref = { this._setAdditionalToolbarContentRef } />
  179. : null
  180. }
  181. </div>
  182. <h1 className = 'header-text-title'>
  183. { t('welcomepage.headerTitle') }
  184. </h1>
  185. <span className = 'header-text-subtitle'>
  186. { t('welcomepage.headerSubtitle')}
  187. </span>
  188. <div id = 'enter_room'>
  189. <div className = 'enter-room-input-container'>
  190. <form onSubmit = { this._onFormSubmit }>
  191. <input
  192. aria-disabled = 'false'
  193. aria-label = 'Meeting name input'
  194. autoFocus = { true }
  195. className = 'enter-room-input'
  196. id = 'enter_room_field'
  197. onChange = { this._onRoomChange }
  198. pattern = { ROOM_NAME_VALIDATE_PATTERN_STR }
  199. placeholder = { this.state.roomPlaceholder }
  200. ref = { this._setRoomInputRef }
  201. title = { t('welcomepage.roomNameAllowedChars') }
  202. type = 'text'
  203. value = { this.state.room } />
  204. <div
  205. className = { _moderatedRoomServiceUrl
  206. ? 'warning-with-link'
  207. : 'warning-without-link' }>
  208. { this._renderInsecureRoomNameWarning() }
  209. </div>
  210. </form>
  211. </div>
  212. <button
  213. aria-disabled = 'false'
  214. aria-label = 'Start meeting'
  215. className = 'welcome-page-button'
  216. id = 'enter_room_button'
  217. onClick = { this._onFormSubmit }
  218. tabIndex = '0'
  219. type = 'button'>
  220. { t('welcomepage.startMeeting') }
  221. </button>
  222. </div>
  223. { _moderatedRoomServiceUrl && (
  224. <div id = 'moderated-meetings'>
  225. {
  226. translateToHTML(
  227. t, 'welcomepage.moderatedMessage', { url: _moderatedRoomServiceUrl })
  228. }
  229. </div>)}
  230. </div>
  231. </div>
  232. <div className = 'welcome-cards-container'>
  233. <div className = 'welcome-card-column'>
  234. <div className = 'welcome-tabs welcome-card welcome-card--blue'>
  235. { this._renderTabs() }
  236. </div>
  237. { showAdditionalCard
  238. ? <div
  239. className = 'welcome-card welcome-card--dark'
  240. ref = { this._setAdditionalCardRef } />
  241. : null }
  242. </div>
  243. { showAdditionalContent
  244. ? <div
  245. className = 'welcome-page-content'
  246. ref = { this._setAdditionalContentRef } />
  247. : null }
  248. </div>
  249. { DISPLAY_WELCOME_FOOTER && this._renderFooter()}
  250. </div>
  251. );
  252. }
  253. /**
  254. * Renders the insecure room name warning.
  255. *
  256. * @inheritdoc
  257. */
  258. _doRenderInsecureRoomNameWarning() {
  259. return (
  260. <div className = 'insecure-room-name-warning'>
  261. <Icon src = { IconWarning } />
  262. <span>
  263. { this.props.t('security.insecureRoomNameWarning') }
  264. </span>
  265. </div>
  266. );
  267. }
  268. /**
  269. * Prevents submission of the form and delegates join logic.
  270. *
  271. * @param {Event} event - The HTML Event which details the form submission.
  272. * @private
  273. * @returns {void}
  274. */
  275. _onFormSubmit(event) {
  276. event.preventDefault();
  277. if (!this._roomInputRef || this._roomInputRef.reportValidity()) {
  278. this._onJoin();
  279. }
  280. }
  281. /**
  282. * Overrides the super to account for the differences in the argument types
  283. * provided by HTML and React Native text inputs.
  284. *
  285. * @inheritdoc
  286. * @override
  287. * @param {Event} event - The (HTML) Event which details the change such as
  288. * the EventTarget.
  289. * @protected
  290. */
  291. _onRoomChange(event) {
  292. super._onRoomChange(event.target.value);
  293. }
  294. /**
  295. * Callback invoked when the desired tab to display should be changed.
  296. *
  297. * @param {number} tabIndex - The index of the tab within the array of
  298. * displayed tabs.
  299. * @private
  300. * @returns {void}
  301. */
  302. _onTabSelected(tabIndex) {
  303. this.setState({ selectedTab: tabIndex });
  304. }
  305. /**
  306. * Renders the footer.
  307. *
  308. * @returns {ReactElement}
  309. */
  310. _renderFooter() {
  311. const {
  312. t,
  313. _deeplinkingCfg: {
  314. ios = {},
  315. android = {}
  316. }
  317. } = this.props;
  318. const { downloadLink: iosDownloadLink } = ios;
  319. const { fDroidUrl, downloadLink: androidDownloadLink } = android;
  320. return (<footer className = 'welcome-footer'>
  321. <div className = 'welcome-footer-centered'>
  322. <div className = 'welcome-footer-padded'>
  323. <div className = 'welcome-footer-row-block welcome-footer--row-1'>
  324. <div className = 'welcome-footer-row-1-text'>{t('welcomepage.jitsiOnMobile')}</div>
  325. <a
  326. className = 'welcome-badge'
  327. href = { iosDownloadLink }>
  328. <img
  329. alt = { t('welcomepage.mobileDownLoadLinkIos') }
  330. src = './images/app-store-badge.png' />
  331. </a>
  332. <a
  333. className = 'welcome-badge'
  334. href = { androidDownloadLink }>
  335. <img
  336. alt = { t('welcomepage.mobileDownLoadLinkAndroid') }
  337. src = './images/google-play-badge.png' />
  338. </a>
  339. <a
  340. className = 'welcome-badge'
  341. href = { fDroidUrl }>
  342. <img
  343. alt = { t('welcomepage.mobileDownLoadLinkFDroid') }
  344. src = './images/f-droid-badge.png' />
  345. </a>
  346. </div>
  347. </div>
  348. </div>
  349. </footer>);
  350. }
  351. /**
  352. * Renders tabs to show previous meetings and upcoming calendar events. The
  353. * tabs are purposefully hidden on mobile browsers.
  354. *
  355. * @returns {ReactElement|null}
  356. */
  357. _renderTabs() {
  358. if (isMobileBrowser()) {
  359. return null;
  360. }
  361. const { _calendarEnabled, _recentListEnabled, t } = this.props;
  362. const tabs = [];
  363. if (_calendarEnabled) {
  364. tabs.push({
  365. label: t('welcomepage.upcomingMeetings'),
  366. content: <CalendarList />
  367. });
  368. }
  369. if (_recentListEnabled) {
  370. tabs.push({
  371. label: t('welcomepage.recentMeetings'),
  372. content: <RecentList />
  373. });
  374. }
  375. if (tabs.length === 0) {
  376. return null;
  377. }
  378. return (
  379. <Tabs
  380. onSelect = { this._onTabSelected }
  381. selected = { this.state.selectedTab }
  382. tabs = { tabs } />);
  383. }
  384. /**
  385. * Sets the internal reference to the HTMLDivElement used to hold the
  386. * additional card shown near the tabs card.
  387. *
  388. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  389. * of the welcome page content.
  390. * @private
  391. * @returns {void}
  392. */
  393. _setAdditionalCardRef(el) {
  394. this._additionalCardRef = el;
  395. }
  396. /**
  397. * Sets the internal reference to the HTMLDivElement used to hold the
  398. * welcome page content.
  399. *
  400. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  401. * of the welcome page content.
  402. * @private
  403. * @returns {void}
  404. */
  405. _setAdditionalContentRef(el) {
  406. this._additionalContentRef = el;
  407. }
  408. /**
  409. * Sets the internal reference to the HTMLDivElement used to hold the
  410. * toolbar additional content.
  411. *
  412. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  413. * of the additional toolbar content.
  414. * @private
  415. * @returns {void}
  416. */
  417. _setAdditionalToolbarContentRef(el) {
  418. this._additionalToolbarContentRef = el;
  419. }
  420. /**
  421. * Sets the internal reference to the HTMLInputElement used to hold the
  422. * welcome page input room element.
  423. *
  424. * @param {HTMLInputElement} el - The HTMLElement for the input of the room name on the welcome page.
  425. * @private
  426. * @returns {void}
  427. */
  428. _setRoomInputRef(el) {
  429. this._roomInputRef = el;
  430. }
  431. /**
  432. * Returns whether or not an additional card should be displayed near the tabs.
  433. *
  434. * @private
  435. * @returns {boolean}
  436. */
  437. _shouldShowAdditionalCard() {
  438. return interfaceConfig.DISPLAY_WELCOME_PAGE_ADDITIONAL_CARD
  439. && this._additionalCardTemplate
  440. && this._additionalCardTemplate.content
  441. && this._additionalCardTemplate.innerHTML.trim();
  442. }
  443. /**
  444. * Returns whether or not additional content should be displayed below
  445. * the welcome page's header for entering a room name.
  446. *
  447. * @private
  448. * @returns {boolean}
  449. */
  450. _shouldShowAdditionalContent() {
  451. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  452. && this._additionalContentTemplate
  453. && this._additionalContentTemplate.content
  454. && this._additionalContentTemplate.innerHTML.trim();
  455. }
  456. /**
  457. * Returns whether or not additional content should be displayed inside
  458. * the header toolbar.
  459. *
  460. * @private
  461. * @returns {boolean}
  462. */
  463. _shouldShowAdditionalToolbarContent() {
  464. return interfaceConfig.DISPLAY_WELCOME_PAGE_TOOLBAR_ADDITIONAL_CONTENT
  465. && this._additionalToolbarContentTemplate
  466. && this._additionalToolbarContentTemplate.content
  467. && this._additionalToolbarContentTemplate.innerHTML.trim();
  468. }
  469. }
  470. export default translate(connect(_mapStateToProps)(WelcomePage));