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.

AbstractApp.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import React, { Component } from 'react';
  2. import {
  3. localParticipantJoined,
  4. localParticipantLeft
  5. } from '../../base/participants';
  6. import {
  7. appNavigate,
  8. appWillMount,
  9. appWillUnmount
  10. } from '../actions';
  11. /**
  12. * Default config.
  13. *
  14. * @type {Object}
  15. */
  16. const DEFAULT_CONFIG = {
  17. configLocation: './config.js',
  18. hosts: {
  19. domain: 'meet.jit.si'
  20. }
  21. };
  22. /**
  23. * Base (abstract) class for main App component.
  24. *
  25. * @abstract
  26. */
  27. export class AbstractApp extends Component {
  28. /**
  29. * AbstractApp component's property types.
  30. *
  31. * @static
  32. */
  33. static propTypes = {
  34. config: React.PropTypes.object,
  35. store: React.PropTypes.object,
  36. /**
  37. * The URL, if any, with which the app was launched.
  38. */
  39. url: React.PropTypes.string
  40. }
  41. /**
  42. * Init lib-jitsi-meet and create local participant when component is going
  43. * to be mounted.
  44. *
  45. * @inheritdoc
  46. */
  47. componentWillMount() {
  48. const dispatch = this.props.store.dispatch;
  49. dispatch(appWillMount(this));
  50. dispatch(localParticipantJoined());
  51. const config
  52. = typeof this.props.config === 'object'
  53. ? this.props.config
  54. : DEFAULT_CONFIG;
  55. this._openURL(this.props.url || `https://${config.hosts.domain}`);
  56. }
  57. /**
  58. * Dispose lib-jitsi-meet and remove local participant when component is
  59. * going to be unmounted.
  60. *
  61. * @inheritdoc
  62. */
  63. componentWillUnmount() {
  64. const dispatch = this.props.store.dispatch;
  65. dispatch(localParticipantLeft());
  66. dispatch(appWillUnmount(this));
  67. }
  68. /**
  69. * Create a ReactElement from the specified component, the specified props
  70. * and the props of this AbstractApp which are suitable for propagation to
  71. * the children of this Component.
  72. *
  73. * @param {Component} component - The component from which the ReactElement
  74. * is to be created.
  75. * @param {Object} props - The read-only React Component props with which
  76. * the ReactElement is to be initialized.
  77. * @returns {ReactElement}
  78. * @protected
  79. */
  80. _createElement(component, props) {
  81. /* eslint-disable no-unused-vars, lines-around-comment */
  82. const {
  83. // Don't propagate the config prop(erty) because the config is
  84. // stored inside the Redux state and, thus, is visible to the
  85. // children anyway.
  86. config,
  87. // Don't propagate the dispatch and store props because they usually
  88. // come from react-redux and programmers don't really expect them to
  89. // be inherited but rather explicitly connected.
  90. dispatch, // eslint-disable-line react/prop-types
  91. store,
  92. // The url property was introduced to be consumed entirely by
  93. // AbstractApp.
  94. url,
  95. // The remaining props, if any, are considered suitable for
  96. // propagation to the children of this Component.
  97. ...thisProps
  98. } = this.props;
  99. /* eslint-enable no-unused-vars, lines-around-comment */
  100. // eslint-disable-next-line object-property-newline
  101. return React.createElement(component, { ...thisProps, ...props });
  102. }
  103. /**
  104. * Navigates this AbstractApp to (i.e. opens) a specific URL.
  105. *
  106. * @param {string} url - The URL to which to navigate this AbstractApp (i.e.
  107. * the URL to open).
  108. * @protected
  109. * @returns {void}
  110. */
  111. _openURL(url) {
  112. this.props.store.dispatch(appNavigate(url));
  113. }
  114. }