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

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