From 27dcefb90e99ed9098c20c70b3813820964d8f29 Mon Sep 17 00:00:00 2001 From: Poslovitch Date: Thu, 3 Dec 2020 14:37:58 +0000 Subject: [PATCH 1/2] Added 'total downloaded' from server and peers in the player Implements https://github.com/Chocobozzz/PeerTube/issues/3384 This will only work with HLS. The display for Webtorrent is left untouched. --- .../p2p-media-loader/p2p-media-loader-plugin.ts | 1 + client/src/assets/player/peertube-videojs-typings.ts | 2 ++ .../player/videojs-components/p2p-info-button.ts | 11 +++++++++-- .../src/assets/player/webtorrent/webtorrent-plugin.ts | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts b/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts index f8116f4bc0d..e97925ab50b 100644 --- a/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts +++ b/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts @@ -153,6 +153,7 @@ class P2pMediaLoaderPlugin extends Plugin { this.statsHTTPBytes.pendingUpload = [] return this.player.trigger('p2pInfo', { + source: 'p2p-media-loader', http: { downloadSpeed: httpDownloadSpeed, uploadSpeed: httpUploadSpeed, diff --git a/client/src/assets/player/peertube-videojs-typings.ts b/client/src/assets/player/peertube-videojs-typings.ts index a359b8595f4..f1e61449928 100644 --- a/client/src/assets/player/peertube-videojs-typings.ts +++ b/client/src/assets/player/peertube-videojs-typings.ts @@ -175,6 +175,8 @@ type AutoResolutionUpdateData = { } type PlayerNetworkInfo = { + source: 'webtorrent' | 'p2p-media-loader' + http: { downloadSpeed: number uploadSpeed: number diff --git a/client/src/assets/player/videojs-components/p2p-info-button.ts b/client/src/assets/player/videojs-components/p2p-info-button.ts index db6806fed12..0d769ab1094 100644 --- a/client/src/assets/player/videojs-components/p2p-info-button.ts +++ b/client/src/assets/player/videojs-components/p2p-info-button.ts @@ -84,8 +84,15 @@ class P2pInfoButton extends Button { const totalUploaded = bytes(p2pStats.uploaded + httpStats.uploaded) const numPeers = p2pStats.numPeers - subDivWebtorrent.title = this.player().localize('Total downloaded: ') + totalDownloaded.join(' ') + '\n' + - this.player().localize('Total uploaded: ' + totalUploaded.join(' ')) + subDivWebtorrent.title = this.player().localize('Total downloaded: ') + totalDownloaded.join(' ') + '\n' + if (data.source == 'p2p-media-loader') { + const downloadedFromServer = bytes(httpStats.downloaded).join(' ') + const downloadedFromPeers = bytes(p2pStats.downloaded).join(' ') + + subDivWebtorrent.title += '* ' + this.player().localize('From the server: ') + downloadedFromServer + '\n' + + '* ' + this.player().localize('From peers: ') + downloadedFromPeers + '\n' + } + subDivWebtorrent.title += this.player().localize('Total uploaded: ' + totalUploaded.join(' ')) downloadSpeedNumber.textContent = downloadSpeed[ 0 ] downloadSpeedUnit.textContent = ' ' + downloadSpeed[ 1 ] diff --git a/client/src/assets/player/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/webtorrent/webtorrent-plugin.ts index 782c91cbdc7..96ba497a05d 100644 --- a/client/src/assets/player/webtorrent/webtorrent-plugin.ts +++ b/client/src/assets/player/webtorrent/webtorrent-plugin.ts @@ -487,6 +487,7 @@ class WebTorrentPlugin extends Plugin { if (this.webtorrent.downloadSpeed !== 0) this.downloadSpeeds.push(this.webtorrent.downloadSpeed) return this.player.trigger('p2pInfo', { + source: 'webtorrent', http: { downloadSpeed: 0, uploadSpeed: 0, From 17848ae5eb887506959cde706f9041f568ec98f4 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Fri, 4 Dec 2020 16:28:08 +0100 Subject: [PATCH 2/2] Apply suggestions from code review --- .../assets/player/videojs-components/p2p-info-button.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client/src/assets/player/videojs-components/p2p-info-button.ts b/client/src/assets/player/videojs-components/p2p-info-button.ts index 0d769ab1094..b1f7cd7512e 100644 --- a/client/src/assets/player/videojs-components/p2p-info-button.ts +++ b/client/src/assets/player/videojs-components/p2p-info-button.ts @@ -85,14 +85,16 @@ class P2pInfoButton extends Button { const numPeers = p2pStats.numPeers subDivWebtorrent.title = this.player().localize('Total downloaded: ') + totalDownloaded.join(' ') + '\n' - if (data.source == 'p2p-media-loader') { + + if (data.source === 'p2p-media-loader') { const downloadedFromServer = bytes(httpStats.downloaded).join(' ') const downloadedFromPeers = bytes(p2pStats.downloaded).join(' ') - subDivWebtorrent.title += '* ' + this.player().localize('From the server: ') + downloadedFromServer + '\n' + + subDivWebtorrent.title += + '* ' + this.player().localize('From the server: ') + downloadedFromServer + '\n' + '* ' + this.player().localize('From peers: ') + downloadedFromPeers + '\n' } - subDivWebtorrent.title += this.player().localize('Total uploaded: ' + totalUploaded.join(' ')) + subDivWebtorrent.title += this.player().localize('Total uploaded: ') + totalUploaded.join(' ') downloadSpeedNumber.textContent = downloadSpeed[ 0 ] downloadSpeedUnit.textContent = ' ' + downloadSpeed[ 1 ]