xgplayer-streaming-shared
Advanced tools
Comparing version 3.0.18 to 3.0.19-rc.0
export class BandwidthService { | ||
_chunkSpeeds: any[]; | ||
/** | ||
* @typedef {{ | ||
* chunkCountForSpeed?: number, | ||
* skipChunkSize?: number, | ||
* longtimeNoReceived?: number | ||
* }} Opts | ||
* | ||
* @param {Opts} opts | ||
*/ | ||
constructor(opts: { | ||
chunkCountForSpeed?: number; | ||
skipChunkSize?: number; | ||
longtimeNoReceived?: number; | ||
}); | ||
_chunkSpeed: number; | ||
_chunkCache: any[]; | ||
_speeds: any[]; | ||
_totalSize: number; | ||
_totalCost: number; | ||
_opts: { | ||
chunkCountForSpeed?: number; | ||
skipChunkSize?: number; | ||
longtimeNoReceived?: number; | ||
}; | ||
addRecord(totalByte: any, ms: any): void; | ||
addChunkRecord(totalByte: any, ms: any): void; | ||
/** | ||
* | ||
* @returns { number } | ||
*/ | ||
getAvgSpeed(): number; | ||
getLatestSpeed(): any; | ||
/** | ||
* | ||
* @returns { number } | ||
*/ | ||
getLatestSpeed(): number; | ||
/** | ||
* | ||
* @returns { number } | ||
*/ | ||
getTotalSize(): number; | ||
/** | ||
* | ||
* @returns { number } | ||
*/ | ||
getTotalCost(): number; | ||
reset(): void; | ||
} |
import { createClass as _createClass, classCallCheck as _classCallCheck, defineProperty as _defineProperty } from "../_virtual/_rollupPluginBabelHelpers.js"; | ||
var SKIP_SMALL_CHUNK = 1e3; | ||
var MAX_CHUNK_SAVE_SIZE = 50; | ||
var MAX_SEGMENT_SAVE_SIZE = 3; | ||
var LONGTIME_NO_RECEIVE = 3e3; | ||
var BandwidthService = /* @__PURE__ */ function() { | ||
function BandwidthService2() { | ||
function BandwidthService2(opts) { | ||
_classCallCheck(this, BandwidthService2); | ||
_defineProperty(this, "_chunkSpeeds", []); | ||
_defineProperty(this, "_chunkSpeed", 0); | ||
_defineProperty(this, "_chunkCache", []); | ||
_defineProperty(this, "_speeds", []); | ||
_defineProperty(this, "_totalSize", 0); | ||
_defineProperty(this, "_totalCost", 0); | ||
this._opts = opts || {}; | ||
} | ||
@@ -14,3 +22,3 @@ _createClass(BandwidthService2, [{ | ||
this._speeds.push(8e3 * totalByte / ms); | ||
this._speeds = this._speeds.slice(-3); | ||
this._speeds = this._speeds.slice(-MAX_SEGMENT_SAVE_SIZE); | ||
} | ||
@@ -20,6 +28,17 @@ }, { | ||
value: function addChunkRecord(totalByte, ms) { | ||
if (!totalByte || !ms) | ||
var _this$_opts, _this$_opts2; | ||
if (!totalByte || !ms || totalByte < (((_this$_opts = this._opts) === null || _this$_opts === void 0 ? void 0 : _this$_opts.skipChunkSize) || SKIP_SMALL_CHUNK)) | ||
return; | ||
this._chunkSpeeds.push(8e3 * totalByte / ms); | ||
this._chunkSpeeds = this._chunkSpeeds.slice(-100); | ||
this._totalSize += totalByte; | ||
this._totalCost += ms; | ||
this._chunkSpeed = 8e3 * totalByte / ms; | ||
this._chunkCache.push({ | ||
size: totalByte, | ||
duration: ms, | ||
timestamp: performance.now() | ||
}); | ||
var size = ((_this$_opts2 = this._opts) === null || _this$_opts2 === void 0 ? void 0 : _this$_opts2.chunkCountForSpeed) || MAX_CHUNK_SAVE_SIZE; | ||
if (this._chunkCache.length > size) { | ||
this._chunkCache = this._chunkCache.slice(-size); | ||
} | ||
} | ||
@@ -29,3 +48,4 @@ }, { | ||
value: function getAvgSpeed() { | ||
if (!this._chunkSpeeds.length && !this._speeds.length) | ||
var _this$_opts3; | ||
if (!this._chunkCache.length && !this._speeds.length) | ||
return 0; | ||
@@ -37,5 +57,18 @@ if (this._speeds.length) { | ||
} | ||
return this._chunkSpeeds.reduce(function(a, c) { | ||
return a += c; | ||
}) / this._chunkSpeeds.length; | ||
var lastSample = this._chunkCache[this._chunkCache.length - 1]; | ||
var cost = performance.now() - lastSample.timestamp; | ||
if (cost > (((_this$_opts3 = this._opts) === null || _this$_opts3 === void 0 ? void 0 : _this$_opts3.longtimeNoReceived) || LONGTIME_NO_RECEIVE)) { | ||
this._chunkCache.push({ | ||
size: 0, | ||
duration: cost, | ||
timestamp: performance.now() | ||
}); | ||
} | ||
var totalSize = this._chunkCache.reduce(function(a, c) { | ||
return a += c.size; | ||
}, 0); | ||
var totalDuration = this._chunkCache.reduce(function(a, c) { | ||
return a += c.duration; | ||
}, 0); | ||
return 8e3 * totalSize / totalDuration; | ||
} | ||
@@ -45,3 +78,3 @@ }, { | ||
value: function getLatestSpeed() { | ||
if (!this._chunkSpeeds.length && !this._speeds.length) | ||
if (!this._chunkCache.length && !this._speeds.length) | ||
return 0; | ||
@@ -51,9 +84,21 @@ if (this._speeds.length) { | ||
} | ||
return this._chunkSpeeds[this._chunkSpeeds.length - 1]; | ||
return this._chunkSpeed; | ||
} | ||
}, { | ||
key: "getTotalSize", | ||
value: function getTotalSize() { | ||
return this._totalSize; | ||
} | ||
}, { | ||
key: "getTotalCost", | ||
value: function getTotalCost() { | ||
return this._totalCost; | ||
} | ||
}, { | ||
key: "reset", | ||
value: function reset() { | ||
this._chunkSpeeds = []; | ||
this._chunkCache = []; | ||
this._speeds = []; | ||
this._totalSize = 0; | ||
this._totalCost = 0; | ||
} | ||
@@ -60,0 +105,0 @@ }]); |
@@ -131,3 +131,3 @@ import { createClass as _createClass, classCallCheck as _classCallCheck, defineProperty as _defineProperty, objectSpread2 as _objectSpread2 } from "../_virtual/_rollupPluginBabelHelpers.js"; | ||
value: function getStats() { | ||
var _this$_core, _this$_core2, _this$_core2$speedInf, _this$_core3, _this$_core3$speedInf, _this$_core4, _this$_core4$bufferIn; | ||
var _this$_core, _this$_core2, _this$_core2$speedInf, _this$_core3, _this$_core3$speedInf, _this$_core4, _this$_core4$speedInf, _this$_core5, _this$_core5$speedInf, _this$_core6, _this$_core6$bufferIn; | ||
var _ref2 = ((_this$_core = this._core) === null || _this$_core === void 0 ? void 0 : _this$_core.media) || {}, _ref2$currentTime = _ref2.currentTime, currentTime = _ref2$currentTime === void 0 ? 0 : _ref2$currentTime, _ref2$decodeFps = _ref2.decodeFps, decodeFps = _ref2$decodeFps === void 0 ? 0 : _ref2$decodeFps; | ||
@@ -137,4 +137,6 @@ return _objectSpread2(_objectSpread2({}, this._stats.getStats()), {}, { | ||
avgSpeed: ((_this$_core3 = this._core) === null || _this$_core3 === void 0 ? void 0 : (_this$_core3$speedInf = _this$_core3.speedInfo) === null || _this$_core3$speedInf === void 0 ? void 0 : _this$_core3$speedInf.call(_this$_core3).avgSpeed) || 0, | ||
totalReceivedByte: ((_this$_core4 = this._core) === null || _this$_core4 === void 0 ? void 0 : (_this$_core4$speedInf = _this$_core4.speedInfo) === null || _this$_core4$speedInf === void 0 ? void 0 : _this$_core4$speedInf.call(_this$_core4).totalSize) || 0, | ||
totalReceivedCost: ((_this$_core5 = this._core) === null || _this$_core5 === void 0 ? void 0 : (_this$_core5$speedInf = _this$_core5.speedInfo) === null || _this$_core5$speedInf === void 0 ? void 0 : _this$_core5$speedInf.call(_this$_core5).totalCost) || 0, | ||
currentTime, | ||
bufferEnd: ((_this$_core4 = this._core) === null || _this$_core4 === void 0 ? void 0 : (_this$_core4$bufferIn = _this$_core4.bufferInfo()) === null || _this$_core4$bufferIn === void 0 ? void 0 : _this$_core4$bufferIn.remaining) || 0, | ||
bufferEnd: ((_this$_core6 = this._core) === null || _this$_core6 === void 0 ? void 0 : (_this$_core6$bufferIn = _this$_core6.bufferInfo()) === null || _this$_core6$bufferIn === void 0 ? void 0 : _this$_core6$bufferIn.remaining) || 0, | ||
decodeFps | ||
@@ -141,0 +143,0 @@ }); |
{ | ||
"name": "xgplayer-streaming-shared", | ||
"version": "3.0.18", | ||
"version": "3.0.19-rc.0", | ||
"main": "dist/index.min.js", | ||
@@ -18,3 +18,3 @@ "module": "es/index.js", | ||
"access": "public", | ||
"tag": "latest" | ||
"tag": "rc" | ||
}, | ||
@@ -21,0 +21,0 @@ "license": "MIT", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
372256
4829
3