X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fassets%2Fplayer%2Fshared%2Fmetrics%2Fmetrics-plugin.ts;h=2aae3e90a51bfabb0e757bf1134384af4d40427d;hb=89fc0142625126b0a2923c9d625be5d201354bb7;hp=2844828daf71688f49dc8172b9cecc56f3c94005;hpb=6a02dd1c3d250130404cd22e3691f4e681208e15;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/assets/player/shared/metrics/metrics-plugin.ts b/client/src/assets/player/shared/metrics/metrics-plugin.ts index 2844828da..2aae3e90a 100644 --- a/client/src/assets/player/shared/metrics/metrics-plugin.ts +++ b/client/src/assets/player/shared/metrics/metrics-plugin.ts @@ -1,6 +1,7 @@ import videojs from 'video.js' import { PlaybackMetricCreate } from '../../../../../../shared/models' import { MetricsPluginOptions, PlayerMode, PlayerNetworkInfo } from '../../types' +import { logger } from '@root-helpers/logger' const Plugin = videojs.getPlugin('plugin') @@ -99,11 +100,14 @@ class MetricsPlugin extends Plugin { const headers = new Headers({ 'Content-type': 'application/json; charset=UTF-8' }) return fetch(this.metricsUrl, { method: 'POST', body: JSON.stringify(body), headers }) + .catch(err => logger.error('Cannot send metrics to the server.', err)) }, this.CONSTANTS.METRICS_INTERVAL) } private trackBytes () { this.player.on('p2pInfo', (_event, data: PlayerNetworkInfo) => { + if (!data) return + this.downloadedBytesHTTP += data.http.downloaded - (this.lastPlayerNetworkInfo?.http.downloaded || 0) this.downloadedBytesP2P += data.p2p.downloaded - (this.lastPlayerNetworkInfo?.p2p.downloaded || 0)