Skip to content

Commit

Permalink
add 'total downloaded' stats from server and peers in player (#3394)
Browse files Browse the repository at this point in the history
Implements #3384
This will only work with HLS. The display for Webtorrent is left untouched.

Co-authored-by: Rigel Kent <[email protected]>
  • Loading branch information
Poslovitch and rigelk authored Dec 4, 2020
1 parent f8b530e commit 1715283
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions client/src/assets/player/peertube-videojs-typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ type AutoResolutionUpdateData = {
}

type PlayerNetworkInfo = {
source: 'webtorrent' | 'p2p-media-loader'

http: {
downloadSpeed: number
uploadSpeed: number
Expand Down
13 changes: 11 additions & 2 deletions client/src/assets/player/videojs-components/p2p-info-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
1 change: 1 addition & 0 deletions client/src/assets/player/webtorrent/webtorrent-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1715283

Please sign in to comment.