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

TestConnectionInfo.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import React, { Component, Fragment } from 'react';
  2. import { connect } from 'react-redux';
  3. import statsEmitter from '../../../connection-indicator/statsEmitter';
  4. import { getLocalParticipant } from '../../participants/functions';
  5. import { isTestModeEnabled } from '../functions';
  6. import TestHint from './TestHint';
  7. /**
  8. * Defines the TestConnectionInfo's properties.
  9. */
  10. type Props = {
  11. /**
  12. * The JitsiConference's connection state. It's the lib-jitsi-meet's event
  13. * name converted to a string directly. At the time of this writing these
  14. * are the possible values:
  15. * 'conference.connectionEstablished'
  16. * 'conference.connectionInterrupted'
  17. * 'conference.connectionRestored'.
  18. */
  19. _conferenceConnectionState: string,
  20. /**
  21. * This will be a boolean converted to a string. The value will be 'true'
  22. * once the conference is joined (the XMPP MUC room to be specific).
  23. */
  24. _conferenceJoinedState: string,
  25. /**
  26. * The local participant's ID. Required to be able to observe the local RTP
  27. * stats.
  28. */
  29. _localUserId: string,
  30. /**
  31. * The local participant's role.
  32. */
  33. _localUserRole: string,
  34. /**
  35. * Indicates whether or not the test mode is currently on. Otherwise the
  36. * TestConnectionInfo component will not render.
  37. */
  38. _testMode: boolean
  39. }
  40. /**
  41. * Describes the TestConnectionInfo's state.
  42. */
  43. type State = {
  44. /**
  45. * The RTP stats section.
  46. */
  47. stats: {
  48. /**
  49. * The local bitrate.
  50. */
  51. bitrate: {
  52. /**
  53. * The local download RTP bitrate.
  54. */
  55. download: number,
  56. /**
  57. * The local upload RTP bitrate.
  58. */
  59. upload: number
  60. }
  61. }
  62. }
  63. /**
  64. * The component will expose some of the app state to the jitsi-meet-torture
  65. * through the UI accessibility layer which is visible to the tests. The Web
  66. * tests currently will execute JavaScript and access globals variables to learn
  67. * this information, but there's no such option on React Native(maybe that's
  68. * a good thing).
  69. */
  70. class TestConnectionInfo extends Component<Props, State> {
  71. _onStatsUpdated: Object => void;
  72. /**
  73. * Initializes new <tt>TestConnectionInfo</tt> instance.
  74. *
  75. * @param {Object} props - The read-only properties with which the new
  76. * instance is to be initialized.
  77. */
  78. constructor(props: Props) {
  79. super(props);
  80. this._onStatsUpdated = this._onStatsUpdated.bind(this);
  81. this.state = {
  82. stats: {
  83. bitrate: {
  84. download: 0,
  85. upload: 0
  86. }
  87. }
  88. };
  89. }
  90. /**
  91. * The {@link statsEmitter} callback hoked up for the local participant.
  92. *
  93. * @param {Object} stats - These are the RTP stats. Look in
  94. * the lib-jitsi-meet for more details on the actual structure or add
  95. * a console print and figure out there.
  96. * @returns {void}
  97. * @private
  98. */
  99. _onStatsUpdated(stats = {}) {
  100. this.setState({
  101. stats: {
  102. bitrate: {
  103. download: stats.bitrate?.download || 0,
  104. upload: stats.bitrate?.upload || 0
  105. }
  106. }
  107. });
  108. }
  109. /**
  110. * Starts listening for the local RTP stat updates.
  111. *
  112. * @inheritdoc
  113. * returns {void}
  114. */
  115. componentDidMount() {
  116. statsEmitter.subscribeToClientStats(
  117. this.props._localUserId, this._onStatsUpdated);
  118. }
  119. /**
  120. * Updates which user's stats are being listened to (the local participant's
  121. * id changes).
  122. *
  123. * @inheritdoc
  124. * returns {void}
  125. */
  126. componentDidUpdate(prevProps: Props) {
  127. if (prevProps._localUserId !== this.props._localUserId) {
  128. statsEmitter.unsubscribeToClientStats(
  129. prevProps._localUserId, this._onStatsUpdated);
  130. statsEmitter.subscribeToClientStats(
  131. this.props._localUserId, this._onStatsUpdated);
  132. }
  133. }
  134. /**
  135. * Removes the local stats listener.
  136. *
  137. * @private
  138. * @returns {void}
  139. */
  140. componentWillUnmount() {
  141. statsEmitter.unsubscribeToClientStats(
  142. this.props._localUserId, this._onStatsUpdated);
  143. }
  144. /**
  145. * Renders the component if the app is currently running in the test mode
  146. * (config.testing.testMode == true).
  147. *
  148. * @returns {ReactElement|null}
  149. */
  150. render() {
  151. if (!this.props._testMode) {
  152. return null;
  153. }
  154. return (
  155. <Fragment accessible = { false } >
  156. <TestHint
  157. id = 'org.jitsi.meet.conference.connectionState'
  158. value = { this.props._conferenceConnectionState } />
  159. <TestHint
  160. id = 'org.jitsi.meet.conference.joinedState'
  161. value = { this.props._conferenceJoinedState } />
  162. <TestHint
  163. id = 'org.jitsi.meet.conference.grantModeratorAvailable'
  164. value = { true } />
  165. <TestHint
  166. id = 'org.jitsi.meet.conference.localParticipantRole'
  167. value = { this.props._localUserRole } />
  168. <TestHint
  169. id = 'org.jitsi.meet.stats.rtp'
  170. value = { JSON.stringify(this.state.stats) } />
  171. </Fragment>
  172. );
  173. }
  174. }
  175. /**
  176. * Maps (parts of) the Redux state to the associated TestConnectionInfo's props.
  177. *
  178. * @param {Object} state - The Redux state.
  179. * @private
  180. * @returns {Props}
  181. */
  182. function _mapStateToProps(state) {
  183. const conferenceJoined
  184. = Boolean(state['features/base/conference'].conference);
  185. const localParticipant = getLocalParticipant(state);
  186. return {
  187. _conferenceConnectionState: state['features/testing'].connectionState,
  188. _conferenceJoinedState: conferenceJoined.toString(),
  189. _localUserId: localParticipant?.id,
  190. _localUserRole: localParticipant?.role,
  191. _testMode: isTestModeEnabled(state)
  192. };
  193. }
  194. export default connect(_mapStateToProps)(TestConnectionInfo);