xgplayer-streaming-shared
Advanced tools
Comparing version 3.0.18-alpha.3 to 3.0.18-rc.0
@@ -23,2 +23,3 @@ export namespace ERR { | ||
const MSE_FULL: string; | ||
const MSE_CHANGE_TYPE: string; | ||
const OPTION: string; | ||
@@ -61,2 +62,3 @@ const DASH: string; | ||
MSE_HIJACK?: undefined; | ||
MSE_CHANGE_TYPE?: undefined; | ||
EME_HIJACK?: undefined; | ||
@@ -86,2 +88,3 @@ LICENSE?: undefined; | ||
MSE_HIJACK?: undefined; | ||
MSE_CHANGE_TYPE?: undefined; | ||
EME_HIJACK?: undefined; | ||
@@ -111,2 +114,3 @@ LICENSE?: undefined; | ||
MSE_HIJACK?: undefined; | ||
MSE_CHANGE_TYPE?: undefined; | ||
EME_HIJACK?: undefined; | ||
@@ -130,2 +134,3 @@ LICENSE?: undefined; | ||
MSE_HIJACK: number; | ||
MSE_CHANGE_TYPE: number; | ||
EME_HIJACK: number; | ||
@@ -163,2 +168,3 @@ HLS?: undefined; | ||
MSE_HIJACK?: undefined; | ||
MSE_CHANGE_TYPE?: undefined; | ||
EME_HIJACK?: undefined; | ||
@@ -189,2 +195,3 @@ NO_CANPLAY_ERROR?: undefined; | ||
MSE_HIJACK?: undefined; | ||
MSE_CHANGE_TYPE?: undefined; | ||
EME_HIJACK?: undefined; | ||
@@ -191,0 +198,0 @@ LICENSE?: undefined; |
@@ -25,2 +25,3 @@ import { defineProperty as _defineProperty, inherits as _inherits, createSuper as _createSuper, createClass as _createClass, classCallCheck as _classCallCheck, wrapNativeSuper as _wrapNativeSuper } from "./_virtual/_rollupPluginBabelHelpers.js"; | ||
MSE_FULL: "MSE_FULL", | ||
MSE_CHANGE_TYPE: "MSE_CHANGE_TYPE", | ||
OPTION: "OPTION", | ||
@@ -68,2 +69,3 @@ DASH: "DASH", | ||
MSE_HIJACK: 5204, | ||
MSE_CHANGE_TYPE: 5205, | ||
EME_HIJACK: 5301 | ||
@@ -70,0 +72,0 @@ }), _defineProperty(_ERR_CODE, ERR.DRM, { |
@@ -75,2 +75,3 @@ declare var _default: { | ||
MSE_FULL: string; | ||
MSE_CHANGE_TYPE: string; | ||
OPTION: string; | ||
@@ -113,2 +114,3 @@ DASH: string; | ||
MSE_HIJACK?: undefined; | ||
MSE_CHANGE_TYPE?: undefined; | ||
EME_HIJACK?: undefined; | ||
@@ -138,2 +140,3 @@ LICENSE?: undefined; | ||
MSE_HIJACK?: undefined; | ||
MSE_CHANGE_TYPE?: undefined; | ||
EME_HIJACK?: undefined; | ||
@@ -163,2 +166,3 @@ LICENSE?: undefined; | ||
MSE_HIJACK?: undefined; | ||
MSE_CHANGE_TYPE?: undefined; | ||
EME_HIJACK?: undefined; | ||
@@ -182,2 +186,3 @@ LICENSE?: undefined; | ||
MSE_HIJACK: number; | ||
MSE_CHANGE_TYPE: number; | ||
EME_HIJACK: number; | ||
@@ -215,2 +220,3 @@ HLS?: undefined; | ||
MSE_HIJACK?: undefined; | ||
MSE_CHANGE_TYPE?: undefined; | ||
EME_HIJACK?: undefined; | ||
@@ -241,2 +247,3 @@ NO_CANPLAY_ERROR?: undefined; | ||
MSE_HIJACK?: undefined; | ||
MSE_CHANGE_TYPE?: undefined; | ||
EME_HIJACK?: undefined; | ||
@@ -243,0 +250,0 @@ LICENSE?: undefined; |
@@ -352,6 +352,11 @@ import { defineProperty as _defineProperty, inherits as _inherits, createSuper as _createSuper, createClass as _createClass, classCallCheck as _classCallCheck, wrapNativeSuper as _wrapNativeSuper, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from "./_virtual/_rollupPluginBabelHelpers.js"; | ||
return Promise.resolve(); | ||
if (typeof sb.changeType !== "function") | ||
return Promise.reject(); | ||
if (typeof sb.changeType !== "function") { | ||
return Promise.reject(new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_CHANGE_TYPE, new Error("changeType is not a function"))); | ||
} | ||
return this._enqueueOp(type, function() { | ||
sb.changeType(mimeType); | ||
try { | ||
sb.changeType(mimeType); | ||
} catch (e) { | ||
throw new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_CHANGE_TYPE, e); | ||
} | ||
sb.mimeType = mimeType; | ||
@@ -610,3 +615,3 @@ _this8._onSBUpdateEnd(type); | ||
this._logger.error(error); | ||
op.promise.reject(new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_OTHER, error)); | ||
op.promise.reject(error.constructor === StreamingError ? error : new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_OTHER, error)); | ||
queue.shift(); | ||
@@ -613,0 +618,0 @@ this._startQueue(type); |
export class BandwidthService { | ||
/** | ||
* @typedef {{ | ||
* chunkCountForSpeed?: number, | ||
* skipChunkSize?: number, | ||
* longtimeNoReceived?: number | ||
* }} Opts | ||
* | ||
* @param {Opts} opts | ||
*/ | ||
constructor(opts: { | ||
chunkCountForSpeed?: number; | ||
skipChunkSize?: number; | ||
longtimeNoReceived?: number; | ||
}); | ||
_chunkSpeed: number; | ||
_chunkCache: any[]; | ||
_chunkSpeeds: any[]; | ||
_speeds: any[]; | ||
_opts: { | ||
chunkCountForSpeed?: number; | ||
skipChunkSize?: number; | ||
longtimeNoReceived?: number; | ||
}; | ||
addRecord(totalByte: any, ms: any): void; | ||
@@ -25,0 +5,0 @@ addChunkRecord(totalByte: any, ms: any): 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(opts) { | ||
function BandwidthService2() { | ||
_classCallCheck(this, BandwidthService2); | ||
_defineProperty(this, "_chunkSpeed", 0); | ||
_defineProperty(this, "_chunkCache", []); | ||
_defineProperty(this, "_chunkSpeeds", []); | ||
_defineProperty(this, "_speeds", []); | ||
this._opts = opts || {}; | ||
} | ||
@@ -20,3 +14,3 @@ _createClass(BandwidthService2, [{ | ||
this._speeds.push(8e3 * totalByte / ms); | ||
this._speeds = this._speeds.slice(-MAX_SEGMENT_SAVE_SIZE); | ||
this._speeds = this._speeds.slice(-3); | ||
} | ||
@@ -26,15 +20,6 @@ }, { | ||
value: function addChunkRecord(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)) | ||
if (!totalByte || !ms) | ||
return; | ||
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); | ||
} | ||
this._chunkSpeeds.push(8e3 * totalByte / ms); | ||
this._chunkSpeeds = this._chunkSpeeds.slice(-100); | ||
} | ||
@@ -44,4 +29,3 @@ }, { | ||
value: function getAvgSpeed() { | ||
var _this$_opts3; | ||
if (!this._chunkCache.length && !this._speeds.length) | ||
if (!this._chunkSpeeds.length && !this._speeds.length) | ||
return 0; | ||
@@ -53,18 +37,5 @@ if (this._speeds.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; | ||
return this._chunkSpeeds.reduce(function(a, c) { | ||
return a += c; | ||
}) / this._chunkSpeeds.length; | ||
} | ||
@@ -74,3 +45,3 @@ }, { | ||
value: function getLatestSpeed() { | ||
if (!this._chunkCache.length && !this._speeds.length) | ||
if (!this._chunkSpeeds.length && !this._speeds.length) | ||
return 0; | ||
@@ -80,3 +51,3 @@ if (this._speeds.length) { | ||
} | ||
return this._chunkSpeed; | ||
return this._chunkSpeeds[this._chunkSpeeds.length - 1]; | ||
} | ||
@@ -86,3 +57,3 @@ }, { | ||
value: function reset() { | ||
this._chunkCache = []; | ||
this._chunkSpeeds = []; | ||
this._speeds = []; | ||
@@ -89,0 +60,0 @@ } |
{ | ||
"name": "xgplayer-streaming-shared", | ||
"version": "3.0.18-alpha.3", | ||
"version": "3.0.18-rc.0", | ||
"main": "dist/index.min.js", | ||
@@ -18,3 +18,3 @@ "module": "es/index.js", | ||
"access": "public", | ||
"tag": "alpha" | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51
363885
4731