Rebuild, fix null error with null

auto_join_3.3
Roman Drozd 2020-05-07 02:39:23 +02:00
parent 9a1646a39d
commit 71562cf57d
1 changed files with 27 additions and 17 deletions

View File

@ -59,8 +59,9 @@ class NetworkIndicator extends React.Component
currBitrate : 0, currBitrate : 0,
maxBitrate : 0, maxBitrate : 0,
avgBitrate : 0, avgBitrate : 0,
medBitrate : 1, medBitrate : 0,
probeCount : 0 probeCount : 1,
probeLimit : 3
}; };
} }
@ -116,22 +117,19 @@ class NetworkIndicator extends React.Component
{ {
const rc = this.props.roomClient; const rc = this.props.roomClient;
const recv = await rc.getTransportStats(rc._recvTransport.id); var probe = [ ...this.state.probe ]; // clone
var probeCount = this.state.probeCount
const send = await rc.getTransportStats(rc._sendTransport.id); var probeLimit = this.state.probeLimit
// current var currBitrate = this.state.currBitrate
const currBitrate = Math.round(send[0].recvBitrate / 1024 / 8); // in kb
// probe var recv = this.state.recv
const probe = [ ...this.state.probe ]; // clone
if (this.state.probeCount < 5) var send = this.state.send
this.setState({ probeCount: this.state.probeCount + 1});
else
this.setState({ probeCount: 1 });
probe[this.state.probeCount] = currBitrate; // add/update next element probe[probeCount] = currBitrate; // add/update next element
// median // median
const med = (arr) => const med = (arr) =>
@ -155,13 +153,25 @@ class NetworkIndicator extends React.Component
.reduce((a, b) => a + b); .reduce((a, b) => a + b);
const percent = const percent =
await Math.round(this.state.currBitrate / this.state.medBitrate * 100); await Math.round(currBitrate / medBitrate * 100);
var x = (rc._recvTransport) ? (await rc.getTransportStats(rc._recvTransport.id)) : null
var y = (rc._sendTransport) ? (await rc.getTransportStats(rc._sendTransport.id)) : null
if(x && y )
{
this.setState({
recv : x[0],
send : y[0]
});
}
this.setState({ this.setState({
recv : recv[0],
send : send[0],
probe, probe,
currBitrate, probeCount: (probeCount < probeLimit) ? probeCount + 1 : 1 ,
currBitrate : (send) ? Math.round(send.recvBitrate / 1024 / 8) : 0,
maxBitrate, maxBitrate,
avgBitrate, avgBitrate,
medBitrate, medBitrate,