diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-21 11:42:52 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-07-21 11:42:52 +0200 |
commit | c6867725fb8e3dfbc2018a37ed5a963103587cb6 (patch) | |
tree | 92e00e551c95553c6090e26a7502593e72bdcfd7 /client/src/assets/player/shared/stats/stats-card.ts | |
parent | b63c607b92fd3ec62e370b73e398062bcf317738 (diff) | |
download | PeerTube-c6867725fb8e3dfbc2018a37ed5a963103587cb6.tar.gz PeerTube-c6867725fb8e3dfbc2018a37ed5a963103587cb6.tar.zst PeerTube-c6867725fb8e3dfbc2018a37ed5a963103587cb6.zip |
Add p2p info to metrics
Diffstat (limited to 'client/src/assets/player/shared/stats/stats-card.ts')
-rw-r--r-- | client/src/assets/player/shared/stats/stats-card.ts | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/client/src/assets/player/shared/stats/stats-card.ts b/client/src/assets/player/shared/stats/stats-card.ts index 077c900e5..13334d91a 100644 --- a/client/src/assets/player/shared/stats/stats-card.ts +++ b/client/src/assets/player/shared/stats/stats-card.ts | |||
@@ -63,8 +63,7 @@ class StatsCard extends Component { | |||
63 | 63 | ||
64 | private liveLatency: InfoElement | 64 | private liveLatency: InfoElement |
65 | 65 | ||
66 | private onP2PInfoHandler: (_event: any, data: EventPlayerNetworkInfo) => void | 66 | private onNetworkInfoHandler: (_event: any, data: EventPlayerNetworkInfo) => void |
67 | private onHTTPInfoHandler: (_event: any, data: EventPlayerNetworkInfo) => void | ||
68 | 67 | ||
69 | createEl () { | 68 | createEl () { |
70 | this.containerEl = videojs.dom.createEl('div', { | 69 | this.containerEl = videojs.dom.createEl('div', { |
@@ -89,33 +88,26 @@ class StatsCard extends Component { | |||
89 | 88 | ||
90 | this.populateInfoBlocks() | 89 | this.populateInfoBlocks() |
91 | 90 | ||
92 | this.onP2PInfoHandler = (_event, data) => { | 91 | this.onNetworkInfoHandler = (_event, data) => { |
93 | this.mode = data.source | 92 | this.mode = data.source |
94 | 93 | ||
95 | const p2pStats = data.p2p | 94 | const p2pStats = data.p2p |
96 | const httpStats = data.http | 95 | const httpStats = data.http |
97 | 96 | ||
98 | this.playerNetworkInfo.downloadSpeed = bytes(p2pStats.downloadSpeed + httpStats.downloadSpeed).join(' ') | 97 | this.playerNetworkInfo.downloadSpeed = bytes((p2pStats?.downloadSpeed || 0) + (httpStats.downloadSpeed || 0)).join(' ') |
99 | this.playerNetworkInfo.uploadSpeed = bytes(p2pStats.uploadSpeed).join(' ') | 98 | this.playerNetworkInfo.uploadSpeed = bytes(p2pStats?.uploadSpeed || 0).join(' ') |
100 | this.playerNetworkInfo.totalDownloaded = bytes(p2pStats.downloaded + httpStats.downloaded).join(' ') | 99 | this.playerNetworkInfo.totalDownloaded = bytes((p2pStats?.downloaded || 0) + httpStats.downloaded).join(' ') |
101 | this.playerNetworkInfo.totalUploaded = bytes(p2pStats.uploaded).join(' ') | 100 | this.playerNetworkInfo.totalUploaded = bytes(p2pStats?.uploaded || 0).join(' ') |
102 | this.playerNetworkInfo.numPeers = p2pStats.numPeers | 101 | this.playerNetworkInfo.numPeers = p2pStats?.peersWithWebSeed |
103 | this.playerNetworkInfo.averageBandwidth = bytes(data.bandwidthEstimate).join(' ') + '/s' | ||
104 | 102 | ||
105 | if (data.source === 'p2p-media-loader') { | 103 | if (data.source === 'p2p-media-loader') { |
104 | this.playerNetworkInfo.averageBandwidth = bytes(data.bandwidthEstimate).join(' ') + '/s' | ||
106 | this.playerNetworkInfo.downloadedFromServer = bytes(httpStats.downloaded).join(' ') | 105 | this.playerNetworkInfo.downloadedFromServer = bytes(httpStats.downloaded).join(' ') |
107 | this.playerNetworkInfo.downloadedFromPeers = bytes(p2pStats.downloaded).join(' ') | 106 | this.playerNetworkInfo.downloadedFromPeers = bytes(p2pStats?.downloaded || 0).join(' ') |
108 | } | 107 | } |
109 | } | 108 | } |
110 | 109 | ||
111 | this.onHTTPInfoHandler = (_event, data) => { | 110 | this.player().on('network-info', this.onNetworkInfoHandler) |
112 | this.mode = data.source | ||
113 | |||
114 | this.playerNetworkInfo.totalDownloaded = bytes(data.http.downloaded).join(' ') | ||
115 | } | ||
116 | |||
117 | this.player().on('p2p-info', this.onP2PInfoHandler) | ||
118 | this.player().on('http-info', this.onHTTPInfoHandler) | ||
119 | 111 | ||
120 | return this.containerEl | 112 | return this.containerEl |
121 | } | 113 | } |
@@ -123,8 +115,7 @@ class StatsCard extends Component { | |||
123 | dispose () { | 115 | dispose () { |
124 | if (this.updateInterval) clearInterval(this.updateInterval) | 116 | if (this.updateInterval) clearInterval(this.updateInterval) |
125 | 117 | ||
126 | this.player().off('p2p-info', this.onP2PInfoHandler) | 118 | this.player().off('network-info', this.onNetworkInfoHandler) |
127 | this.player().off('http-info', this.onHTTPInfoHandler) | ||
128 | 119 | ||
129 | super.dispose() | 120 | super.dispose() |
130 | } | 121 | } |