Stop playback metrics on player unmount

This commit is contained in:
Gabe Kangas
2022-10-12 18:08:14 -07:00
parent 4eb5bff3db
commit d40e66b7ef
2 changed files with 10 additions and 3 deletions

View File

@@ -291,6 +291,7 @@ export const OwncastPlayer: FC<OwncastPlayerProps> = ({ source, online }) => {
useEffect( useEffect(
() => () => { () => () => {
stopLatencyCompensator(); stopLatencyCompensator();
playbackMetrics.stop();
}, },
[], [],
); );

View File

@@ -49,6 +49,7 @@ class PlaybackMetrics {
this.send = this.send.bind(this); this.send = this.send.bind(this);
this.collectPlaybackMetrics = this.collectPlaybackMetrics.bind(this); this.collectPlaybackMetrics = this.collectPlaybackMetrics.bind(this);
this.handleNoLongerBuffering = this.handleNoLongerBuffering.bind(this); this.handleNoLongerBuffering = this.handleNoLongerBuffering.bind(this);
this.sendMetricsTimer = 0;
this.player.on('canplaythrough', this.handleNoLongerBuffering); this.player.on('canplaythrough', this.handleNoLongerBuffering);
this.player.on('error', this.handleError); this.player.on('error', this.handleError);
@@ -81,11 +82,16 @@ class PlaybackMetrics {
this.videoJSReady(); this.videoJSReady();
setInterval(() => { this.sendMetricsTimer = setInterval(() => {
this.send(); this.send();
}, METRICS_SEND_INTERVAL); }, METRICS_SEND_INTERVAL);
} }
stop() {
clearInterval(this.sendMetricsTimer);
this.player.off();
}
// Keep our client clock in sync with the server clock to determine // Keep our client clock in sync with the server clock to determine
// accurate latency calculations. // accurate latency calculations.
setClockSkew(skewMs) { setClockSkew(skewMs) {
@@ -249,12 +255,12 @@ class PlaybackMetrics {
bandwidth: roundedAverageBandwidth, bandwidth: roundedAverageBandwidth,
latency: roundedAverageLatency, latency: roundedAverageLatency,
downloadDuration: roundedAverageDownloadDuration, downloadDuration: roundedAverageDownloadDuration,
errors: errorCount + this.isBuffering ? 1 : 0, errors: errorCount + (this.isBuffering ? 1 : 0),
qualityVariantChanges: this.qualityVariantChanges, qualityVariantChanges: this.qualityVariantChanges,
}; };
} else { } else {
data = { data = {
errors: errorCount + this.isBuffering ? 1 : 0, errors: errorCount + (this.isBuffering ? 1 : 0),
}; };
} }