diff options
author | Vincent Petry <vincent@nextcloud.com> | 2021-06-14 15:47:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-14 15:47:24 +0300 |
commit | bbea16e523f5d5c9a19c6aa3a2e970b33bcf1175 (patch) | |
tree | 63e8d6cf1c7d3a0c3b6b4b57939c6c14e9196e67 | |
parent | ebe5348472c5ef074f36251812be8eaa0947efd7 (diff) | |
parent | df63caa17b27b7eea4f09f2ea70a70c5036602d2 (diff) |
Merge pull request #5751 from nextcloud/fix-connection-quality-stats-not-reset-when-setting-a-new-peer-connection
Fix connection quality stats not reset when setting a new peer connection
-rw-r--r-- | src/utils/webrtc/analyzers/ParticipantAnalyzer.js | 6 | ||||
-rw-r--r-- | src/utils/webrtc/analyzers/PeerConnectionAnalyzer.js | 31 |
2 files changed, 27 insertions, 10 deletions
diff --git a/src/utils/webrtc/analyzers/ParticipantAnalyzer.js b/src/utils/webrtc/analyzers/ParticipantAnalyzer.js index 8b28af680..02151d828 100644 --- a/src/utils/webrtc/analyzers/ParticipantAnalyzer.js +++ b/src/utils/webrtc/analyzers/ParticipantAnalyzer.js @@ -257,12 +257,18 @@ ParticipantAnalyzer.prototype = { this._senderScreenPeerConnectionAnalyzer.setPeerConnection(this._screenPeer.pc, PEER_DIRECTION.SENDER) this._senderScreenPeerConnectionAnalyzer.on('change:connectionQualityVideo', this._handleConnectionQualityScreenChangeBound) + + this._senderScreenPeerConnectionAnalyzer.setAnalysisEnabledAudio(false) + this._senderScreenPeerConnectionAnalyzer.setAnalysisEnabledVideo(true) } if (this._callParticipantModel) { this._receiverScreenPeerConnectionAnalyzer.setPeerConnection(this._screenPeer.pc, PEER_DIRECTION.RECEIVER) this._receiverScreenPeerConnectionAnalyzer.on('change:connectionQualityVideo', this._handleConnectionQualityScreenChangeBound) + + this._receiverScreenPeerConnectionAnalyzer.setAnalysisEnabledAudio(false) + this._receiverScreenPeerConnectionAnalyzer.setAnalysisEnabledVideo(true) } }, diff --git a/src/utils/webrtc/analyzers/PeerConnectionAnalyzer.js b/src/utils/webrtc/analyzers/PeerConnectionAnalyzer.js index 9aff77463..d5074ed1f 100644 --- a/src/utils/webrtc/analyzers/PeerConnectionAnalyzer.js +++ b/src/utils/webrtc/analyzers/PeerConnectionAnalyzer.js @@ -204,11 +204,7 @@ PeerConnectionAnalyzer.prototype = { if (!analysisEnabledAudio) { this._setConnectionQualityAudio(CONNECTION_QUALITY.UNKNOWN) } else { - this._packets['audio'].reset() - this._packetsLost['audio'].reset() - this._packetsLostRatio['audio'].reset() - this._packetsPerSecond['audio'].reset() - this._timestamps['audio'].reset() + this._resetStats('audio') } }, @@ -218,14 +214,18 @@ PeerConnectionAnalyzer.prototype = { if (!analysisEnabledVideo) { this._setConnectionQualityVideo(CONNECTION_QUALITY.UNKNOWN) } else { - this._packets['video'].reset() - this._packetsLost['video'].reset() - this._packetsLostRatio['video'].reset() - this._packetsPerSecond['video'].reset() - this._timestamps['video'].reset() + this._resetStats('video') } }, + _resetStats: function(kind) { + this._packets[kind].reset() + this._packetsLost[kind].reset() + this._packetsLostRatio[kind].reset() + this._packetsPerSecond[kind].reset() + this._timestamps[kind].reset() + }, + _handleIceConnectionStateChanged: function() { // Note that even if the ICE connection state is "disconnected" the // connection is actually active, media is still transmitted, and the @@ -244,6 +244,17 @@ PeerConnectionAnalyzer.prototype = { return } + // When a connection is started the stats must be reset, as a different + // peer connection could have been used before and its stats would be + // unrelated to the new one. + // When a connection is restarted the reported stats continue from the + // last values. However, during the reconnection the stats will not be + // updated, so the timestamps will suddenly increase once the connection + // is ready again. This could cause a wrong analysis, so the stats + // should be reset too in that case. + this._resetStats('audio') + this._resetStats('video') + this._getStatsInterval = window.setInterval(() => { this._peerConnection.getStats().then(this._processStatsBound) }, 1000) |