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