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

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