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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /* global APP, interfaceConfig */
  2. import React from 'react';
  3. import { connect } from 'react-redux';
  4. import { Conference } from '../../conference';
  5. import { AbstractWelcomePage, mapStateToProps } from './AbstractWelcomePage';
  6. /**
  7. * The CSS style of the element with CSS class <tt>rightwatermark</tt>.
  8. */
  9. const RIGHT_WATERMARK_STYLE = {
  10. backgroundImage: 'url(images/rightwatermark.png)'
  11. };
  12. /* eslint-disable require-jsdoc */
  13. /**
  14. * The Web container rendering the welcome page.
  15. *
  16. * @extends AbstractWelcomePage
  17. */
  18. class WelcomePage extends AbstractWelcomePage {
  19. /* eslint-enable require-jsdoc */
  20. /**
  21. * Initializes a new WelcomePage instance.
  22. *
  23. * @param {Object} props - The read-only properties with which the new
  24. * instance is to be initialized.
  25. */
  26. constructor(props) {
  27. super(props);
  28. this._initState();
  29. // Bind event handlers so they are only bound once for every instance.
  30. this._onDisableWelcomeChange = this._onDisableWelcomeChange.bind(this);
  31. this._onKeyDown = this._onKeyDown.bind(this);
  32. this._onRoomChange = this._onRoomChange.bind(this);
  33. }
  34. /**
  35. * This method is executed when comonent is mounted.
  36. *
  37. * @inheritdoc
  38. * @returns {void}
  39. */
  40. componentDidMount() {
  41. if (this.state.generateRoomnames) {
  42. this._updateRoomname();
  43. }
  44. }
  45. /**
  46. * Implements React's {@link Component#render()}.
  47. *
  48. * @inheritdoc
  49. * @returns {ReactElement|null}
  50. */
  51. render() {
  52. // FIXME The rendering of Conference bellow is a very quick and dirty
  53. // temporary fix for the following issue: when the WelcomePage is
  54. // disabled, app.js expects Conference to be rendered already and only
  55. // then it builds a room name but the App component expects the room
  56. // name to be built already (by looking at the window's location) in
  57. // order to choose between WelcomePage and Conference.
  58. return (
  59. <div>
  60. <div id = 'welcome_page'>
  61. {
  62. this._renderHeader()
  63. }
  64. {
  65. this._renderMain()
  66. }
  67. </div>
  68. <Conference />
  69. </div>
  70. );
  71. }
  72. /**
  73. * Returns the domain name.
  74. *
  75. * @private
  76. * @returns {string} Domain name.
  77. */
  78. _getDomain() {
  79. return `${window.location.protocol}//${window.location.host}/`;
  80. }
  81. /**
  82. * Method that initializes state of the component.
  83. *
  84. * @returns {void}
  85. */
  86. _initState() {
  87. const showBrandWatermark = interfaceConfig.SHOW_BRAND_WATERMARK;
  88. const showJitsiWatermark = interfaceConfig.SHOW_JITSI_WATERMARK;
  89. this.state = {
  90. ...this.state,
  91. brandWatermarkLink:
  92. showBrandWatermark ? interfaceConfig.BRAND_WATERMARK_LINK : '',
  93. enableWelcomePage: true,
  94. generateRoomnames:
  95. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE,
  96. jitsiWatermarkLink:
  97. showJitsiWatermark ? interfaceConfig.JITSI_WATERMARK_LINK : '',
  98. showBrandWatermark,
  99. showJitsiWatermark,
  100. showPoweredBy: interfaceConfig.SHOW_POWERED_BY
  101. };
  102. }
  103. /**
  104. * Handles <tt>change</tt> event of the checkbox which allows specifying
  105. * whether the WelcomePage is disabled.
  106. *
  107. * @param {Event} event - The (HTML) Event which details the change such as
  108. * the EventTarget.
  109. * @returns {void}
  110. */
  111. _onDisableWelcomeChange(event) {
  112. this.setState({
  113. enableWelcomePage: !event.target.value
  114. }, () => {
  115. APP.settings.setWelcomePageEnabled(this.state.enableWelcomePage);
  116. });
  117. }
  118. /**
  119. * Overrides the super in order to prevent the dispatching of the Redux
  120. * action SET_ROOM.
  121. *
  122. * @override
  123. * @protected
  124. * @returns {null}
  125. */
  126. _onJoin() {
  127. // Don't call the super implementation and thus prevent the dispatching
  128. // of the Redux action SET_ROOM.
  129. }
  130. /**
  131. * Handles 'keydown' event to initiate joining the room when the
  132. * 'Enter/Return' button is pressed.
  133. *
  134. * @param {Event} event - Key down event object.
  135. * @private
  136. * @returns {void}
  137. */
  138. _onKeyDown(event) {
  139. if (event.keyCode === /* Enter */ 13) {
  140. this._onJoin();
  141. }
  142. }
  143. /**
  144. * Overrides the super to account for the differences in the argument types
  145. * provided by HTML and React Native text inputs.
  146. *
  147. * @inheritdoc
  148. * @override
  149. * @param {Event} event - The (HTML) Event which details the change such as
  150. * the EventTarget.
  151. * @protected
  152. */
  153. _onRoomChange(event) {
  154. super._onRoomChange(event.target.value);
  155. }
  156. /**
  157. * Method that returns brand watermark element if it is enabled.
  158. *
  159. * @private
  160. * @returns {ReactElement|null} Watermark element or null.
  161. */
  162. _renderBrandWatermark() {
  163. if (this.state.showBrandWatermark) {
  164. return (
  165. <a
  166. href = { this.state.brandWatermarkLink }
  167. target = '_new'>
  168. <div
  169. className = 'watermark rightwatermark'
  170. style = { RIGHT_WATERMARK_STYLE } />
  171. </a>
  172. );
  173. }
  174. return null;
  175. }
  176. /**
  177. * Renders a feature with a specific index.
  178. *
  179. * @param {number} index - The index of the feature to render.
  180. * @private
  181. * @returns {ReactElement}
  182. */
  183. _renderFeature(index) {
  184. return (
  185. <div className = 'feature_holder'>
  186. <div
  187. className = 'feature_icon'
  188. data-i18n = { `welcomepage.feature${index}.title` } />
  189. <div
  190. className = 'feature_description'
  191. data-i18n = { `welcomepage.feature${index}.content` }
  192. data-i18n-options = { JSON.stringify({
  193. postProcess: 'resolveAppName'
  194. }) } />
  195. </div>
  196. );
  197. }
  198. /**
  199. * Renders a row of features.
  200. *
  201. * @param {number} beginIndex - The inclusive feature index to begin the row
  202. * with.
  203. * @param {number} endIndex - The exclusive feature index to end the row
  204. * with.
  205. * @private
  206. * @returns {ReactElement}
  207. */
  208. _renderFeatureRow(beginIndex, endIndex) {
  209. const features = [];
  210. for (let index = beginIndex; index < endIndex; ++index) {
  211. features.push(this._renderFeature(index));
  212. }
  213. return (
  214. <div className = 'feature_row'>
  215. {
  216. features
  217. }
  218. </div>
  219. );
  220. }
  221. /* eslint-disable require-jsdoc */
  222. /**
  223. * Renders the header part of this WelcomePage.
  224. *
  225. * @private
  226. * @returns {ReactElement|null}
  227. */
  228. _renderHeader() {
  229. /* eslint-enable require-jsdoc */
  230. return (
  231. <div id = 'welcome_page_header'>
  232. {
  233. this._renderJitsiWatermark()
  234. }
  235. {
  236. this._renderBrandWatermark()
  237. }
  238. {
  239. this._renderPoweredBy()
  240. }
  241. <div id = 'enter_room_container'>
  242. <div id = 'enter_room_form'>
  243. <div className = 'domain-name'>
  244. {
  245. this._getDomain()
  246. }
  247. </div>
  248. <div id = 'enter_room'>
  249. <input
  250. autoFocus = { true }
  251. className = 'enter-room__field'
  252. data-room-name
  253. = { this.state.generatedRoomname }
  254. id = 'enter_room_field'
  255. onChange = { this._onRoomChange }
  256. onKeyDown = { this._onKeyDown }
  257. placeholder = { this.state.roomPlaceholder }
  258. type = 'text'
  259. value = { this.state.room } />
  260. { /* eslint-disable react/jsx-handler-names */ }
  261. <div
  262. className = 'icon-reload enter-room__reload'
  263. onClick = { this._updateRoomname } />
  264. { /* eslint-enable react/jsx-handler-names */ }
  265. <button
  266. className = 'enter-room__button'
  267. data-i18n = 'welcomepage.go'
  268. id = 'enter_room_button'
  269. onClick = { this._onJoin }
  270. type = 'button' />
  271. </div>
  272. </div>
  273. </div>
  274. <div id = 'brand_header' />
  275. <input
  276. checked = { !this.state.enableWelcomePage }
  277. id = 'disable_welcome'
  278. name = 'checkbox'
  279. onChange = { this._onDisableWelcomeChange }
  280. type = 'checkbox' />
  281. <label
  282. className = 'disable_welcome_position'
  283. data-i18n = 'welcomepage.disable'
  284. htmlFor = 'disable_welcome' />
  285. <div id = 'header_text' />
  286. </div>
  287. );
  288. }
  289. /**
  290. * Method that returns jitsi watermark element if it is enabled.
  291. *
  292. * @private
  293. * @returns {ReactElement|null} Watermark element or null.
  294. */
  295. _renderJitsiWatermark() {
  296. if (this.state.showJitsiWatermark) {
  297. return (
  298. <a
  299. href = { this.state.jitsiWatermarkLink }
  300. target = '_new'>
  301. <div className = 'watermark leftwatermark' />
  302. </a>
  303. );
  304. }
  305. return null;
  306. }
  307. /**
  308. * Renders powered by block if it is enabled.
  309. *
  310. * @private
  311. * @returns {ReactElement|null}
  312. */
  313. _renderPoweredBy() {
  314. if (this.state.showPoweredBy) {
  315. return (
  316. <a
  317. className = 'poweredby'
  318. href = 'http://jitsi.org'
  319. target = '_new'>
  320. <span data-i18n = 'poweredby' /> jitsi.org
  321. </a>
  322. );
  323. }
  324. return null;
  325. }
  326. /**
  327. * Renders the main part of this WelcomePage.
  328. *
  329. * @private
  330. * @returns {ReactElement|null}
  331. */
  332. _renderMain() {
  333. return (
  334. <div id = 'welcome_page_main'>
  335. <div id = 'features'>
  336. {
  337. this._renderFeatureRow(1, 5)
  338. }
  339. {
  340. this._renderFeatureRow(5, 9)
  341. }
  342. </div>
  343. </div>
  344. );
  345. }
  346. }
  347. export default connect(mapStateToProps)(WelcomePage);