Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

WelcomePage.web.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. * 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 { _moderatedRoomServiceUrl, t } = this.props;
  139. const { APP_NAME, DEFAULT_WELCOME_PAGE_LOGO_URL } = 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 defaultJitsiLogoURL = { DEFAULT_WELCOME_PAGE_LOGO_URL } />
  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. { _moderatedRoomServiceUrl && (
  204. <div id = 'moderated-meetings'>
  205. <p>
  206. {
  207. translateToHTML(
  208. t, 'welcomepage.moderatedMessage', { url: _moderatedRoomServiceUrl })
  209. }
  210. </p>
  211. </div>
  212. ) }
  213. { this._renderTabs() }
  214. </div>
  215. { showAdditionalContent
  216. ? <div
  217. className = 'welcome-page-content'
  218. ref = { this._setAdditionalContentRef } />
  219. : null }
  220. </div>
  221. );
  222. }
  223. /**
  224. * Renders the insecure room name warning.
  225. *
  226. * @inheritdoc
  227. */
  228. _doRenderInsecureRoomNameWarning() {
  229. return (
  230. <div className = 'insecure-room-name-warning'>
  231. <Icon src = { IconWarning } />
  232. <span>
  233. { this.props.t('security.insecureRoomNameWarning') }
  234. </span>
  235. </div>
  236. );
  237. }
  238. /**
  239. * Prevents submission of the form and delegates join logic.
  240. *
  241. * @param {Event} event - The HTML Event which details the form submission.
  242. * @private
  243. * @returns {void}
  244. */
  245. _onFormSubmit(event) {
  246. event.preventDefault();
  247. if (!this._roomInputRef || this._roomInputRef.reportValidity()) {
  248. this._onJoin();
  249. }
  250. }
  251. /**
  252. * Overrides the super to account for the differences in the argument types
  253. * provided by HTML and React Native text inputs.
  254. *
  255. * @inheritdoc
  256. * @override
  257. * @param {Event} event - The (HTML) Event which details the change such as
  258. * the EventTarget.
  259. * @protected
  260. */
  261. _onRoomChange(event) {
  262. super._onRoomChange(event.target.value);
  263. }
  264. /**
  265. * Callback invoked when the desired tab to display should be changed.
  266. *
  267. * @param {number} tabIndex - The index of the tab within the array of
  268. * displayed tabs.
  269. * @private
  270. * @returns {void}
  271. */
  272. _onTabSelected(tabIndex) {
  273. this.setState({ selectedTab: tabIndex });
  274. }
  275. /**
  276. * Renders tabs to show previous meetings and upcoming calendar events. The
  277. * tabs are purposefully hidden on mobile browsers.
  278. *
  279. * @returns {ReactElement|null}
  280. */
  281. _renderTabs() {
  282. if (isMobileBrowser()) {
  283. return null;
  284. }
  285. const { _calendarEnabled, _recentListEnabled, t } = this.props;
  286. const tabs = [];
  287. if (_calendarEnabled) {
  288. tabs.push({
  289. label: t('welcomepage.calendar'),
  290. content: <CalendarList />
  291. });
  292. }
  293. if (_recentListEnabled) {
  294. tabs.push({
  295. label: t('welcomepage.recentList'),
  296. content: <RecentList />
  297. });
  298. }
  299. if (tabs.length === 0) {
  300. return null;
  301. }
  302. return (
  303. <Tabs
  304. onSelect = { this._onTabSelected }
  305. selected = { this.state.selectedTab }
  306. tabs = { tabs } />);
  307. }
  308. /**
  309. * Sets the internal reference to the HTMLDivElement used to hold the
  310. * welcome page content.
  311. *
  312. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  313. * of the welcome page content.
  314. * @private
  315. * @returns {void}
  316. */
  317. _setAdditionalContentRef(el) {
  318. this._additionalContentRef = el;
  319. }
  320. /**
  321. * Sets the internal reference to the HTMLDivElement used to hold the
  322. * toolbar additional content.
  323. *
  324. * @param {HTMLDivElement} el - The HTMLElement for the div that is the root
  325. * of the additional toolbar content.
  326. * @private
  327. * @returns {void}
  328. */
  329. _setAdditionalToolbarContentRef(el) {
  330. this._additionalToolbarContentRef = el;
  331. }
  332. /**
  333. * Sets the internal reference to the HTMLInputElement used to hold the
  334. * welcome page input room element.
  335. *
  336. * @param {HTMLInputElement} el - The HTMLElement for the input of the room name on the welcome page.
  337. * @private
  338. * @returns {void}
  339. */
  340. _setRoomInputRef(el) {
  341. this._roomInputRef = el;
  342. }
  343. /**
  344. * Returns whether or not additional content should be displayed below
  345. * the welcome page's header for entering a room name.
  346. *
  347. * @private
  348. * @returns {boolean}
  349. */
  350. _shouldShowAdditionalContent() {
  351. return interfaceConfig.DISPLAY_WELCOME_PAGE_CONTENT
  352. && this._additionalContentTemplate
  353. && this._additionalContentTemplate.content
  354. && this._additionalContentTemplate.innerHTML.trim();
  355. }
  356. /**
  357. * Returns whether or not additional content should be displayed inside
  358. * the header toolbar.
  359. *
  360. * @private
  361. * @returns {boolean}
  362. */
  363. _shouldShowAdditionalToolbarContent() {
  364. return interfaceConfig.DISPLAY_WELCOME_PAGE_TOOLBAR_ADDITIONAL_CONTENT
  365. && this._additionalToolbarContentTemplate
  366. && this._additionalToolbarContentTemplate.content
  367. && this._additionalToolbarContentTemplate.innerHTML.trim();
  368. }
  369. /**
  370. * Returns whether or not the screen has a size smaller than a custom margin
  371. * and therefore display different text in the go button.
  372. *
  373. * @private
  374. * @returns {boolean}
  375. */
  376. _shouldShowResponsiveText() {
  377. const { innerWidth } = window;
  378. return innerWidth <= WINDOW_WIDTH_THRESHOLD;
  379. }
  380. }
  381. export default translate(connect(_mapStateToProps)(WelcomePage));