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

WelcomePage.web.js 17KB

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