Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Prevent errors on dispose

Chocobozzza056da87a4ce
diff --git a/client/src/standalone/player/src/shared/metrics/metrics-plugin.ts b/client/src/standalone/player/src/shared/metrics/metrics-plugin.ts
index b60bf780c2..23e0b0ebcf 100644
--- a/client/src/standalone/player/src/shared/metrics/metrics-plugin.ts
+++ b/client/src/standalone/player/src/shared/metrics/metrics-plugin.ts
@@ -88,11 +88,15 @@ class MetricsPlugin extends Plugin {
if (!this.options_.metricsUrl()) return
this.metricsInterval = setInterval(() => {
+ const player = this.player
+
+ if (!player) return
+
let resolution: number
let fps: number
- if (this.player.usingPlugin('p2pMediaLoader')) {
- const level = this.player.p2pMediaLoader().getCurrentLevel()
+ if (player.usingPlugin('p2pMediaLoader')) {
+ const level = player.p2pMediaLoader().getCurrentLevel()
if (!level) return
resolution = Math.min(level.height || 0, level.width || 0)
@@ -101,8 +105,8 @@ class MetricsPlugin extends Plugin {
fps = framerate
? parseInt(framerate, 10)
: undefined
- } else if (this.player.usingPlugin('webVideo')) {
- const videoFile = this.player.webVideo().getCurrentVideoFile()
+ } else if (player.usingPlugin('webVideo')) {
+ const videoFile = player.webVideo().getCurrentVideoFile()
if (!videoFile) return
resolution = videoFile.resolution.id
diff --git a/client/src/standalone/player/src/shared/p2p-media-loader/p2p-media-loader-plugin.ts b/client/src/standalone/player/src/shared/p2p-media-loader/p2p-media-loader-plugin.ts
index b17ce60caf..486e0e7ed2 100644
--- a/client/src/standalone/player/src/shared/p2p-media-loader/p2p-media-loader-plugin.ts
+++ b/client/src/standalone/player/src/shared/p2p-media-loader/p2p-media-loader-plugin.ts
@@ -249,6 +249,11 @@ class P2pMediaLoaderPlugin extends Plugin {
})
this.networkInfoInterval = setInterval(() => {
+ const player = this.player
+ const hlsjs = this.hlsjs
+
+ if (!player || !hlsjs) return
+
const p2pDownloadSpeed = this.arraySum(this.statsP2PBytes.pendingDownload)
const p2pUploadSpeed = this.arraySum(this.statsP2PBytes.pendingUpload)
@@ -258,9 +263,9 @@ class P2pMediaLoaderPlugin extends Plugin {
this.statsP2PBytes.pendingUpload = []
this.statsHTTPBytes.pendingDownload = []
- return this.player.trigger('network-info', {
+ return player.trigger('network-info', {
source: 'p2p-media-loader',
- bandwidthEstimate: (this.hlsjs as any).bandwidthEstimate / 8,
+ bandwidthEstimate: (hlsjs as any).bandwidthEstimate / 8,
http: {
downloadSpeed: httpDownloadSpeed,
downloaded: this.statsHTTPBytes.totalDownload
diff --git a/client/src/standalone/player/src/shared/peertube/peertube-plugin.ts b/client/src/standalone/player/src/shared/peertube/peertube-plugin.ts
index 03bfe91bef..4413319c42 100644
--- a/client/src/standalone/player/src/shared/peertube/peertube-plugin.ts
+++ b/client/src/standalone/player/src/shared/peertube/peertube-plugin.ts
@@ -405,9 +405,11 @@ class PeerTubePlugin extends Plugin {
this.player.one('ended', this.videoViewOnEndedHandler)
this.videoViewInterval = setInterval(() => {
- if (ended) return
+ const player = this.player
- const currentTime = Math.floor(this.player.currentTime())
+ if (!player || ended) return
+
+ const currentTime = Math.floor(player.currentTime())
// No need to update
if (currentTime === lastCurrentTime) return
diff --git a/client/src/standalone/player/src/shared/stats/stats-card.ts b/client/src/standalone/player/src/shared/stats/stats-card.ts
index ef27355d98..6ddef7adbf 100644
--- a/client/src/standalone/player/src/shared/stats/stats-card.ts
+++ b/client/src/standalone/player/src/shared/stats/stats-card.ts
@@ -141,13 +141,17 @@ class StatsCard extends Component {
this.containerEl.style.display = 'block'
this.updateInterval = setInterval(async () => {
- if (!this.mode) return
+ const player = this.player()
+
+ if (!player || !this.mode) return
try {
const options = this.mode === 'p2p-media-loader'
? this.buildHLSOptions()
: await this.buildWebVideoOptions() // Default
+ if (!this.player()) return
+
this.populateInfoValues(options)
} catch (err) {
logger.error('Cannot update stats.', err)
diff --git a/client/src/standalone/player/src/shared/web-video/web-video-plugin.ts b/client/src/standalone/player/src/shared/web-video/web-video-plugin.ts
index ac0eb863ec..8486db5a44 100644
--- a/client/src/standalone/player/src/shared/web-video/web-video-plugin.ts
+++ b/client/src/standalone/player/src/shared/web-video/web-video-plugin.ts
@@ -175,10 +175,14 @@ class WebVideoPlugin extends Plugin {
private setupNetworkInfoInterval () {
this.networkInfoInterval = setInterval(() => {
- return this.player.trigger('network-info', {
+ const player = this.player
+
+ if (!player) return
+
+ return player.trigger('network-info', {
source: 'web-video',
http: {
- downloaded: this.player.bufferedPercent() * this.currentVideoFile?.size
+ downloaded: player.bufferedPercent() * this.currentVideoFile?.size
}
} as PlayerNetworkInfo)
}, 1000)