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

WelcomePage.web.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /* global interfaceConfig, APP, $ */
  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. // XXX Temporary solution until we add React translation.
  45. APP.translation.translateElement($('#welcome_page'));
  46. }
  47. /**
  48. * Implements React's {@link Component#render()}.
  49. *
  50. * @inheritdoc
  51. * @returns {ReactElement|null}
  52. */
  53. render() {
  54. return (
  55. <div>
  56. <div id = 'welcome_page'>
  57. {
  58. this._renderHeader()
  59. }
  60. {
  61. this._renderMain()
  62. }
  63. </div>
  64. </div>
  65. );
  66. }
  67. /**
  68. * Returns the domain name.
  69. *
  70. * @private
  71. * @returns {string} Domain name.
  72. */
  73. _getDomain() {
  74. return `${window.location.protocol}//${window.location.host}/`;
  75. }
  76. /**
  77. * Method that initializes state of the component.
  78. *
  79. * @returns {void}
  80. */
  81. _initState() {
  82. const showBrandWatermark = interfaceConfig.SHOW_BRAND_WATERMARK;
  83. const showJitsiWatermark = interfaceConfig.SHOW_JITSI_WATERMARK;
  84. this.state = {
  85. ...this.state,
  86. brandWatermarkLink:
  87. showBrandWatermark ? interfaceConfig.BRAND_WATERMARK_LINK : '',
  88. enableWelcomePage: true,
  89. generateRoomnames:
  90. interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE,
  91. jitsiWatermarkLink:
  92. showJitsiWatermark ? interfaceConfig.JITSI_WATERMARK_LINK : '',
  93. showBrandWatermark,
  94. showJitsiWatermark,
  95. showPoweredBy: interfaceConfig.SHOW_POWERED_BY
  96. };
  97. }
  98. /**
  99. * Handles <tt>change</tt> event of the checkbox which allows specifying
  100. * whether the WelcomePage is disabled.
  101. *
  102. * @param {Event} event - The (HTML) Event which details the change such as
  103. * the EventTarget.
  104. * @returns {void}
  105. */
  106. _onDisableWelcomeChange(event) {
  107. this.setState({
  108. enableWelcomePage: !event.target.value
  109. }, () => {
  110. APP.settings.setWelcomePageEnabled(this.state.enableWelcomePage);
  111. });
  112. }
  113. /**
  114. * Overrides the super in order to prevent the dispatching of the Redux
  115. * action SET_ROOM.
  116. *
  117. * @override
  118. * @protected
  119. * @returns {null}
  120. */
  121. _onJoin() {
  122. // Don't call the super implementation and thus prevent the dispatching
  123. // of the Redux action SET_ROOM.
  124. }
  125. /**
  126. * Handles 'keydown' event to initiate joining the room when the
  127. * 'Enter/Return' button is pressed.
  128. *
  129. * @param {Event} event - Key down event object.
  130. * @private
  131. * @returns {void}
  132. */
  133. _onKeyDown(event) {
  134. if (event.keyCode === /* Enter */ 13) {
  135. this._onJoin();
  136. }
  137. }
  138. /**
  139. * Overrides the super to account for the differences in the argument types
  140. * provided by HTML and React Native text inputs.
  141. *
  142. * @inheritdoc
  143. * @override
  144. * @param {Event} event - The (HTML) Event which details the change such as
  145. * the EventTarget.
  146. * @protected
  147. */
  148. _onRoomChange(event) {
  149. super._onRoomChange(event.target.value);
  150. }
  151. /**
  152. * Method that returns brand watermark element if it is enabled.
  153. *
  154. * @private
  155. * @returns {ReactElement|null} Watermark element or null.
  156. */
  157. _renderBrandWatermark() {
  158. if (this.state.showBrandWatermark) {
  159. return (
  160. <a
  161. href = { this.state.brandWatermarkLink }
  162. target = '_new'>
  163. <div
  164. className = 'watermark rightwatermark'
  165. style = { RIGHT_WATERMARK_STYLE } />
  166. </a>
  167. );
  168. }
  169. return null;
  170. }
  171. /**
  172. * Renders a feature with a specific index.
  173. *
  174. * @param {number} index - The index of the feature to render.
  175. * @private
  176. * @returns {ReactElement}
  177. */
  178. _renderFeature(index) {
  179. return (
  180. <div className = 'feature_holder'>
  181. <div
  182. className = 'feature_icon'
  183. data-i18n = { `welcomepage.feature${index}.title` } />
  184. <div
  185. className = 'feature_description'
  186. data-i18n = { `welcomepage.feature${index}.content` }
  187. data-i18n-options = { JSON.stringify({
  188. postProcess: 'resolveAppName'
  189. }) } />
  190. </div>
  191. );
  192. }
  193. /**
  194. * Renders a row of features.
  195. *
  196. * @param {number} beginIndex - The inclusive feature index to begin the row
  197. * with.
  198. * @param {number} endIndex - The exclusive feature index to end the row
  199. * with.
  200. * @private
  201. * @returns {ReactElement}
  202. */
  203. _renderFeatureRow(beginIndex, endIndex) {
  204. const features = [];
  205. for (let index = beginIndex; index < endIndex; ++index) {
  206. features.push(this._renderFeature(index));
  207. }
  208. return (
  209. <div className = 'feature_row'>
  210. {
  211. features
  212. }
  213. </div>
  214. );
  215. }
  216. /* eslint-disable require-jsdoc */
  217. /**
  218. * Renders the header part of this WelcomePage.
  219. *
  220. * @private
  221. * @returns {ReactElement|null}
  222. */
  223. _renderHeader() {
  224. /* eslint-enable require-jsdoc */
  225. return (
  226. <div id = 'welcome_page_header'>
  227. {
  228. this._renderJitsiWatermark()
  229. }
  230. {
  231. this._renderBrandWatermark()
  232. }
  233. {
  234. this._renderPoweredBy()
  235. }
  236. <div id = 'enter_room_container'>
  237. <div id = 'enter_room_form'>
  238. <div className = 'domain-name'>
  239. {
  240. this._getDomain()
  241. }
  242. </div>
  243. <div id = 'enter_room'>
  244. <input
  245. autoFocus = { true }
  246. className = 'enter-room__field'
  247. data-room-name
  248. = { this.state.generatedRoomname }
  249. id = 'enter_room_field'
  250. onChange = { this._onRoomChange }
  251. onKeyDown = { this._onKeyDown }
  252. placeholder = { this.state.roomPlaceholder }
  253. type = 'text'
  254. value = { this.state.room } />
  255. { /* eslint-disable react/jsx-handler-names */ }
  256. <div
  257. className = 'icon-reload enter-room__reload'
  258. onClick = { this._updateRoomname } />
  259. { /* eslint-enable react/jsx-handler-names */ }
  260. <button
  261. className = 'enter-room__button'
  262. data-i18n = 'welcomepage.go'
  263. id = 'enter_room_button'
  264. onClick = { this._onJoin }
  265. type = 'button' />
  266. </div>
  267. </div>
  268. </div>
  269. <div id = 'brand_header' />
  270. <input
  271. checked = { !this.state.enableWelcomePage }
  272. id = 'disable_welcome'
  273. name = 'checkbox'
  274. onChange = { this._onDisableWelcomeChange }
  275. type = 'checkbox' />
  276. <label
  277. className = 'disable_welcome_position'
  278. data-i18n = 'welcomepage.disable'
  279. htmlFor = 'disable_welcome' />
  280. <div id = 'header_text' />
  281. </div>
  282. );
  283. }
  284. /**
  285. * Method that returns jitsi watermark element if it is enabled.
  286. *
  287. * @private
  288. * @returns {ReactElement|null} Watermark element or null.
  289. */
  290. _renderJitsiWatermark() {
  291. if (this.state.showJitsiWatermark) {
  292. return (
  293. <a
  294. href = { this.state.jitsiWatermarkLink }
  295. target = '_new'>
  296. <div className = 'watermark leftwatermark' />
  297. </a>
  298. );
  299. }
  300. return null;
  301. }
  302. /**
  303. * Renders powered by block if it is enabled.
  304. *
  305. * @private
  306. * @returns {ReactElement|null}
  307. */
  308. _renderPoweredBy() {
  309. if (this.state.showPoweredBy) {
  310. return (
  311. <a
  312. className = 'poweredby'
  313. href = 'http://jitsi.org'
  314. target = '_new'>
  315. <span data-i18n = 'poweredby' /> jitsi.org
  316. </a>
  317. );
  318. }
  319. return null;
  320. }
  321. /**
  322. * Handles updating roomname.
  323. *
  324. * @private
  325. * @returns {void}
  326. **/
  327. _onUpdateRoomname() {
  328. this._updateRoomname();
  329. }
  330. /**
  331. * Event handler for changing room name input from web.
  332. *
  333. * @inheritdoc
  334. * @override
  335. * @protected
  336. */
  337. _onRoomChange() {
  338. super._onRoomChange(this.roomNameInput.value);
  339. }
  340. /**
  341. * Handles 'keydown' event and initiate joining the room if 'return' button
  342. * was pressed.
  343. *
  344. * @param {Event} event - Key down event object.
  345. * @returns {void}
  346. * @private
  347. */
  348. _onKeyDown(event) {
  349. const RETURN_BUTTON_CODE = 13;
  350. if (event.keyCode === RETURN_BUTTON_CODE) {
  351. this._onJoin();
  352. }
  353. }
  354. /**
  355. * Renders the main part of this WelcomePage.
  356. *
  357. * @private
  358. * @returns {ReactElement|null}
  359. */
  360. _renderMain() {
  361. return (
  362. <div id = 'welcome_page_main'>
  363. <div id = 'features'>
  364. {
  365. this._renderFeatureRow(1, 5)
  366. }
  367. {
  368. this._renderFeatureRow(5, 9)
  369. }
  370. </div>
  371. </div>
  372. );
  373. }
  374. }
  375. export default connect(mapStateToProps)(WelcomePage);