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.

TestConnectionInfo.js 6.1KB

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