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

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