]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
add 'total downloaded' stats from server and peers in player (#3394)
authorFlorian CUNY <poslovitch@bentobox.world>
Fri, 4 Dec 2020 15:30:01 +0000 (16:30 +0100)
committerGitHub <noreply@github.com>
Fri, 4 Dec 2020 15:30:01 +0000 (16:30 +0100)
Implements https://github.com/Chocobozzz/PeerTube/issues/3384
This will only work with HLS. The display for Webtorrent is left untouched.

Co-authored-by: Rigel Kent <par@rigelk.eu>
client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts
client/src/assets/player/peertube-videojs-typings.ts
client/src/assets/player/videojs-components/p2p-info-button.ts
client/src/assets/player/webtorrent/webtorrent-plugin.ts

index f8116f4bc0d094617ae1d8ab9150be56e77a4dad..e97925ab50bb3512aab7263422a49e1d26ed6080 100644 (file)
@@ -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,
index a359b8595f4c553f351fbec7be9f5cce5e9777b3..f1e61449928e6f21be6577568912f190f4d6dd68 100644 (file)
@@ -175,6 +175,8 @@ type AutoResolutionUpdateData = {
 }
 
 type PlayerNetworkInfo = {
+  source: 'webtorrent' | 'p2p-media-loader'
+
   http: {
     downloadSpeed: number
     uploadSpeed: number
index db6806fed121d9605c53647b6f5598164187666d..b1f7cd7512ecfad9e2232b8e6c4b35a9f62dde27 100644 (file)
@@ -84,8 +84,17 @@ 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 ]
index 782c91cbdc7f3e2fc94e7a53c5edcaca852fa51a..96ba497a05dce8dba66c70574bb9d14efd801583 100644 (file)
@@ -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,