xgplayer-streaming-shared
Advanced tools
Comparing version 3.0.0-next.10 to 3.0.0-next.11
@@ -13,3 +13,3 @@ function ownKeys(object, enumerableOnly) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), true).forEach(function(key) { | ||
@@ -24,7 +24,6 @@ _defineProperty(target, key, source[key]); | ||
function _regeneratorRuntime() { | ||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ | ||
_regeneratorRuntime = function() { | ||
return exports; | ||
}; | ||
var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = typeof Symbol == "function" ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
function define(obj, key, value) { | ||
@@ -50,6 +49,6 @@ return Object.defineProperty(obj, key, { | ||
return function(method, arg) { | ||
if (state === "executing") | ||
if ("executing" === state) | ||
throw new Error("Generator is already running"); | ||
if (state === "completed") { | ||
if (method === "throw") | ||
if ("completed" === state) { | ||
if ("throw" === method) | ||
throw arg; | ||
@@ -68,13 +67,13 @@ return doneResult(); | ||
} | ||
if (context2.method === "next") | ||
if ("next" === context2.method) | ||
context2.sent = context2._sent = context2.arg; | ||
else if (context2.method === "throw") { | ||
if (state === "suspendedStart") | ||
else if ("throw" === context2.method) { | ||
if ("suspendedStart" === state) | ||
throw state = "completed", context2.arg; | ||
context2.dispatchException(context2.arg); | ||
} else | ||
context2.method === "return" && context2.abrupt("return", context2.arg); | ||
"return" === context2.method && context2.abrupt("return", context2.arg); | ||
state = "executing"; | ||
var record = tryCatch(innerFn2, self2, context2); | ||
if (record.type === "normal") { | ||
if ("normal" === record.type) { | ||
if (state = context2.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) | ||
@@ -87,3 +86,3 @@ continue; | ||
} | ||
record.type === "throw" && (state = "completed", context2.method = "throw", context2.arg = record.arg); | ||
"throw" === record.type && (state = "completed", context2.method = "throw", context2.arg = record.arg); | ||
} | ||
@@ -131,5 +130,5 @@ }; | ||
var record = tryCatch(generator[method], generator, arg); | ||
if (record.type !== "throw") { | ||
if ("throw" !== record.type) { | ||
var result = record.arg, value = result.value; | ||
return value && typeof value == "object" && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function(value2) { | ||
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function(value2) { | ||
invoke("next", value2, resolve, reject); | ||
@@ -158,5 +157,5 @@ }, function(err) { | ||
var method = delegate.iterator[context.method]; | ||
if (method === void 0) { | ||
if (context.delegate = null, context.method === "throw") { | ||
if (delegate.iterator.return && (context.method = "return", context.arg = void 0, maybeInvokeDelegate(delegate, context), context.method === "throw")) | ||
if (void 0 === method) { | ||
if (context.delegate = null, "throw" === context.method) { | ||
if (delegate.iterator.return && (context.method = "return", context.arg = void 0, maybeInvokeDelegate(delegate, context), "throw" === context.method)) | ||
return ContinueSentinel; | ||
@@ -168,6 +167,6 @@ context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
if (record.type === "throw") | ||
if ("throw" === record.type) | ||
return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; | ||
var info = record.arg; | ||
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, context.method !== "return" && (context.method = "next", context.arg = void 0), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); | ||
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = void 0), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); | ||
} | ||
@@ -194,3 +193,3 @@ function pushTryEntry(locs) { | ||
return iteratorMethod.call(iterable); | ||
if (typeof iterable.next == "function") | ||
if ("function" == typeof iterable.next) | ||
return iterable; | ||
@@ -218,4 +217,4 @@ if (!isNaN(iterable.length)) { | ||
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function(genFun) { | ||
var ctor = typeof genFun == "function" && genFun.constructor; | ||
return !!ctor && (ctor === GeneratorFunction || (ctor.displayName || ctor.name) === "GeneratorFunction"); | ||
var ctor = "function" == typeof genFun && genFun.constructor; | ||
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); | ||
}, exports.mark = function(genFun) { | ||
@@ -230,3 +229,3 @@ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; | ||
}), exports.AsyncIterator = AsyncIterator, exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) { | ||
PromiseImpl === void 0 && (PromiseImpl = Promise); | ||
void 0 === PromiseImpl && (PromiseImpl = Promise); | ||
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); | ||
@@ -257,3 +256,3 @@ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function(result) { | ||
for (var name in this) | ||
name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = void 0); | ||
"t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = void 0); | ||
}, | ||
@@ -263,3 +262,3 @@ stop: function() { | ||
var rootRecord = this.tryEntries[0].completion; | ||
if (rootRecord.type === "throw") | ||
if ("throw" === rootRecord.type) | ||
throw rootRecord.arg; | ||
@@ -277,3 +276,3 @@ return this.rval; | ||
var entry = this.tryEntries[i], record = entry.completion; | ||
if (entry.tryLoc === "root") | ||
if ("root" === entry.tryLoc) | ||
return handle("end"); | ||
@@ -307,3 +306,3 @@ if (entry.tryLoc <= this.prev) { | ||
} | ||
finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); | ||
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); | ||
var record = finallyEntry ? finallyEntry.completion : {}; | ||
@@ -313,5 +312,5 @@ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); | ||
complete: function(record, afterLoc) { | ||
if (record.type === "throw") | ||
if ("throw" === record.type) | ||
throw record.arg; | ||
return record.type === "break" || record.type === "continue" ? this.next = record.arg : record.type === "return" ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : record.type === "normal" && afterLoc && (this.next = afterLoc), ContinueSentinel; | ||
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; | ||
}, | ||
@@ -330,3 +329,3 @@ finish: function(finallyLoc) { | ||
var record = entry.completion; | ||
if (record.type === "throw") { | ||
if ("throw" === record.type) { | ||
var thrown = record.arg; | ||
@@ -345,3 +344,3 @@ resetTryEntry(entry); | ||
nextLoc | ||
}, this.method === "next" && (this.arg = void 0), ContinueSentinel; | ||
}, "next" === this.method && (this.arg = void 0), ContinueSentinel; | ||
} | ||
@@ -352,6 +351,6 @@ }, exports; | ||
"@babel/helpers - typeof"; | ||
return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(obj2) { | ||
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) { | ||
return typeof obj2; | ||
} : function(obj2) { | ||
return obj2 && typeof Symbol == "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2; | ||
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2; | ||
}, _typeof(obj); | ||
@@ -358,0 +357,0 @@ } |
import { createClass as _createClass, classCallCheck as _classCallCheck } from "./_virtual/_rollupPluginBabelHelpers.js"; | ||
import "core-js/modules/es.array.push.js"; | ||
import "core-js/modules/es.object.to-string.js"; | ||
@@ -3,0 +4,0 @@ var Buffer = /* @__PURE__ */ function() { |
import { typeof as _typeof } from "./_virtual/_rollupPluginBabelHelpers.js"; | ||
import "core-js/modules/es.object.to-string.js"; | ||
import "core-js/modules/es.object.get-prototype-of.js"; | ||
import "core-js/modules/es.number.is-nan.js"; | ||
import "core-js/modules/es.number.constructor.js"; | ||
var toString = Object.prototype.toString; | ||
@@ -5,0 +7,0 @@ function isObject(a) { |
import { defineProperty as _defineProperty, createClass as _createClass, classCallCheck as _classCallCheck } from "./_virtual/_rollupPluginBabelHelpers.js"; | ||
import "core-js/modules/es.function.name.js"; | ||
import "core-js/modules/es.array.concat.js"; | ||
import "core-js/modules/esnext.array.group.js"; | ||
var Logger = /* @__PURE__ */ function() { | ||
@@ -5,0 +6,0 @@ function Logger2(name) { |
@@ -1,2 +0,2 @@ | ||
import { defineProperty as _defineProperty, inherits as _inherits, createSuper as _createSuper, classCallCheck as _classCallCheck, createClass as _createClass, wrapNativeSuper as _wrapNativeSuper, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from "./_virtual/_rollupPluginBabelHelpers.js"; | ||
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"; | ||
import "core-js/modules/es.error.cause.js"; | ||
@@ -12,2 +12,3 @@ import "core-js/modules/es.array.iterator.js"; | ||
import "core-js/modules/es.promise.js"; | ||
import "core-js/modules/es.array.push.js"; | ||
import "core-js/modules/es.regexp.exec.js"; | ||
@@ -14,0 +15,0 @@ import { createPublicPromise } from "./utils.js"; |
@@ -8,7 +8,15 @@ export class FetchLoader { | ||
_aborted: boolean; | ||
load({ url, timeout, responseType, onProgress, onTimeout, range, transformResponse, request, params, method, headers, body, mode, credentials, cache, redirect, referrer, referrerPolicy }: { | ||
_index: number; | ||
_range: any; | ||
_receivedLength: number; | ||
_running: boolean; | ||
_logger: any; | ||
_vid: string; | ||
load({ url, vid, timeout, responseType, onProgress, index, onTimeout, range, transformResponse, request, params, logger, method, headers, body, mode, credentials, cache, redirect, referrer, referrerPolicy }: { | ||
url: any; | ||
vid: any; | ||
timeout: any; | ||
responseType: any; | ||
onProgress: any; | ||
index: any; | ||
onTimeout: any; | ||
@@ -19,2 +27,3 @@ range: any; | ||
params: any; | ||
logger: any; | ||
method: any; | ||
@@ -30,4 +39,9 @@ headers: any; | ||
}): any; | ||
resolve: any; | ||
reject: any; | ||
cancel(): any; | ||
_loadChunk(response: any, onProgress: any): void; | ||
_loadChunk(response: any, onProgress: any, st: any, firstByteTime: any): void; | ||
get receiveLen(): number; | ||
set running(arg: boolean); | ||
get running(): boolean; | ||
} |
@@ -13,2 +13,4 @@ import { createClass as _createClass, classCallCheck as _classCallCheck, defineProperty as _defineProperty, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from "../_virtual/_rollupPluginBabelHelpers.js"; | ||
import "core-js/modules/es.typed-array.find-index.js"; | ||
import "core-js/modules/es.typed-array.find-last.js"; | ||
import "core-js/modules/es.typed-array.find-last-index.js"; | ||
import "core-js/modules/es.typed-array.for-each.js"; | ||
@@ -31,7 +33,9 @@ import "core-js/modules/es.typed-array.includes.js"; | ||
import "core-js/modules/es.typed-array.to-string.js"; | ||
import "core-js/modules/esnext.typed-array.find-last.js"; | ||
import "core-js/modules/esnext.typed-array.find-last-index.js"; | ||
import "core-js/modules/esnext.typed-array.to-reversed.js"; | ||
import "core-js/modules/esnext.typed-array.to-sorted.js"; | ||
import "core-js/modules/esnext.typed-array.with.js"; | ||
import { NetError } from "./error.js"; | ||
import { setUrlParams, getRangeValue, createResponse } from "./helper.js"; | ||
import { ResponseType } from "./types.js"; | ||
import SpeedSampler from "./speed-sampler.js"; | ||
var FetchLoader = /* @__PURE__ */ function() { | ||
@@ -45,2 +49,8 @@ function FetchLoader2() { | ||
_defineProperty(this, "_aborted", false); | ||
_defineProperty(this, "_index", -1); | ||
_defineProperty(this, "_range", null); | ||
_defineProperty(this, "_receivedLength", 0); | ||
_defineProperty(this, "_running", false); | ||
_defineProperty(this, "_logger", null); | ||
_defineProperty(this, "_vid", ""); | ||
} | ||
@@ -51,5 +61,10 @@ _createClass(FetchLoader2, [{ | ||
var _this$_abortControlle, _this = this; | ||
var url = _ref.url, timeout = _ref.timeout, responseType = _ref.responseType, onProgress = _ref.onProgress, onTimeout = _ref.onTimeout, range = _ref.range, transformResponse = _ref.transformResponse, request = _ref.request, params = _ref.params, method = _ref.method, headers = _ref.headers, body = _ref.body, mode = _ref.mode, credentials = _ref.credentials, cache = _ref.cache, redirect = _ref.redirect, referrer = _ref.referrer, referrerPolicy = _ref.referrerPolicy; | ||
var url = _ref.url, vid = _ref.vid, timeout = _ref.timeout, responseType = _ref.responseType, onProgress = _ref.onProgress, index = _ref.index, onTimeout = _ref.onTimeout, range = _ref.range, transformResponse = _ref.transformResponse, request = _ref.request, params = _ref.params, logger = _ref.logger, method = _ref.method, headers = _ref.headers, body = _ref.body, mode = _ref.mode, credentials = _ref.credentials, cache = _ref.cache, redirect = _ref.redirect, referrer = _ref.referrer, referrerPolicy = _ref.referrerPolicy; | ||
this._logger = logger; | ||
this._aborted = false; | ||
this._abortController = typeof AbortController !== "undefined" && new AbortController(); | ||
this._running = true; | ||
this._index = index; | ||
this._range = range || [0, 0]; | ||
this._vid = vid || url; | ||
var init = { | ||
@@ -95,83 +110,97 @@ method, | ||
var startTime = Date.now(); | ||
return fetch(request || url, request ? void 0 : init).then(/* @__PURE__ */ function() { | ||
var _ref2 = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee(response) { | ||
var firstByteTime, data; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
clearTimeout(_this._timeoutTimer); | ||
_this._response = response; | ||
if (!_this._aborted) { | ||
_context.next = 4; | ||
this._logger.debug("[fetch load start], index,", index, ",range,", range); | ||
return new Promise(function(resolve, reject) { | ||
fetch(request || url, request ? void 0 : init).then(/* @__PURE__ */ function() { | ||
var _ref2 = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee(response) { | ||
var firstByteTime, data, costTime; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
clearTimeout(_this._timeoutTimer); | ||
_this._response = response; | ||
if (!(_this._aborted || !_this._running)) { | ||
_context.next = 4; | ||
break; | ||
} | ||
return _context.abrupt("return"); | ||
case 4: | ||
if (transformResponse) { | ||
response = transformResponse(response, url) || response; | ||
} | ||
if (!response.ok) { | ||
_this._running = false; | ||
reject(NetError(url, init, response, "bad network response")); | ||
} | ||
firstByteTime = Date.now(); | ||
if (!(responseType === ResponseType.TEXT)) { | ||
_context.next = 14; | ||
break; | ||
} | ||
_context.next = 10; | ||
return response.text(); | ||
case 10: | ||
data = _context.sent; | ||
_this._running = false; | ||
_context.next = 35; | ||
break; | ||
} | ||
return _context.abrupt("return"); | ||
case 4: | ||
if (transformResponse) { | ||
response = transformResponse(response, url) || response; | ||
} | ||
if (response.ok) { | ||
_context.next = 7; | ||
case 14: | ||
if (!(responseType === ResponseType.JSON)) { | ||
_context.next = 21; | ||
break; | ||
} | ||
_context.next = 17; | ||
return response.json(); | ||
case 17: | ||
data = _context.sent; | ||
_this._running = false; | ||
_context.next = 35; | ||
break; | ||
} | ||
throw new NetError(url, init, response, "bad network response"); | ||
case 7: | ||
firstByteTime = Date.now(); | ||
if (!(responseType === ResponseType.TEXT)) { | ||
_context.next = 14; | ||
break; | ||
} | ||
_context.next = 11; | ||
return response.text(); | ||
case 11: | ||
data = _context.sent; | ||
_context.next = 28; | ||
break; | ||
case 14: | ||
if (!(responseType === ResponseType.JSON)) { | ||
_context.next = 20; | ||
break; | ||
} | ||
_context.next = 17; | ||
return response.json(); | ||
case 17: | ||
data = _context.sent; | ||
_context.next = 28; | ||
break; | ||
case 20: | ||
if (!onProgress) { | ||
_context.next = 24; | ||
break; | ||
} | ||
_this._loadChunk(response, onProgress); | ||
_context.next = 28; | ||
break; | ||
case 24: | ||
_context.next = 26; | ||
return response.arrayBuffer(); | ||
case 26: | ||
data = _context.sent; | ||
data = new Uint8Array(data); | ||
case 28: | ||
return _context.abrupt("return", createResponse(data, response, response.headers.get("Content-Length"), response.headers.get("age"), startTime, firstByteTime)); | ||
case 29: | ||
case "end": | ||
return _context.stop(); | ||
case 21: | ||
if (!onProgress) { | ||
_context.next = 28; | ||
break; | ||
} | ||
_this.resolve = resolve; | ||
_this.reject = reject; | ||
_this._loadChunk(response, onProgress, startTime, firstByteTime); | ||
return _context.abrupt("return"); | ||
case 28: | ||
_context.next = 30; | ||
return response.arrayBuffer(); | ||
case 30: | ||
data = _context.sent; | ||
data = new Uint8Array(data); | ||
_this._running = false; | ||
costTime = Date.now() - startTime; | ||
SpeedSampler.netSampling({ | ||
mTime: costTime, | ||
mBytes: data.byteLength, | ||
mSpeedInbPS: data.byteLength * 8 / (costTime / 1e3), | ||
mRTT: firstByteTime - startTime | ||
}); | ||
case 35: | ||
_this._logger.debug("[fetch load end], index,", index, ",range,", range); | ||
resolve(createResponse(data, true, response, response.headers.get("Content-Length"), response.headers.get("age"), startTime, firstByteTime, index, range, _this._vid)); | ||
case 37: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function(_x) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}()).catch(function(error) { | ||
clearTimeout(_this._timeoutTimer); | ||
if (_this._aborted && !isTimeout) | ||
return; | ||
error = error instanceof NetError ? error : new NetError(url, init); | ||
error.startTime = startTime; | ||
error.endTime = Date.now(); | ||
error.isTimeout = isTimeout; | ||
throw error; | ||
}, _callee); | ||
})); | ||
return function(_x) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}()).catch(function(error) { | ||
clearTimeout(_this._timeoutTimer); | ||
_this._running = false; | ||
if (_this._aborted && !isTimeout) | ||
return; | ||
error = error instanceof NetError ? error : new NetError(url, init); | ||
error.startTime = startTime; | ||
error.endTime = Date.now(); | ||
error.isTimeout = isTimeout; | ||
reject(error); | ||
}); | ||
}); | ||
@@ -194,22 +223,23 @@ } | ||
this._aborted = true; | ||
this._running = false; | ||
if (!this._response) { | ||
_context2.next = 13; | ||
_context2.next = 14; | ||
break; | ||
} | ||
_context2.prev = 4; | ||
_context2.prev = 5; | ||
if (!this._reader) { | ||
_context2.next = 8; | ||
_context2.next = 9; | ||
break; | ||
} | ||
_context2.next = 8; | ||
_context2.next = 9; | ||
return this._reader.cancel(); | ||
case 8: | ||
_context2.next = 12; | ||
case 9: | ||
_context2.next = 13; | ||
break; | ||
case 10: | ||
_context2.prev = 10; | ||
_context2.t0 = _context2["catch"](4); | ||
case 12: | ||
case 11: | ||
_context2.prev = 11; | ||
_context2.t0 = _context2["catch"](5); | ||
case 13: | ||
this._response = this._reader = null; | ||
case 13: | ||
case 14: | ||
if (this._abortController) { | ||
@@ -222,3 +252,3 @@ try { | ||
} | ||
case 14: | ||
case 15: | ||
case "end": | ||
@@ -228,3 +258,3 @@ return _context2.stop(); | ||
} | ||
}, _callee2, this, [[4, 10]]); | ||
}, _callee2, this, [[5, 11]]); | ||
})); | ||
@@ -238,4 +268,9 @@ function cancel() { | ||
key: "_loadChunk", | ||
value: function _loadChunk(response, onProgress) { | ||
value: function _loadChunk(response, onProgress, st, firstByteTime) { | ||
var _this2 = this; | ||
if (!response.body || !response.body.getReader) { | ||
this._running = false; | ||
this.reject(NetError(response.url, "", response, "onProgress of bad response.body.getReader")); | ||
return; | ||
} | ||
var reader = this._reader = response.body.getReader(); | ||
@@ -247,2 +282,3 @@ var data; | ||
var _ref3 = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee3() { | ||
var startByte, costTime; | ||
return _regeneratorRuntime().wrap(function _callee3$(_context3) { | ||
@@ -265,13 +301,18 @@ while (1) { | ||
endTime = Date.now(); | ||
onProgress(void 0, true, { | ||
startTime, | ||
endTime | ||
}, response); | ||
if (!_this2._aborted) { | ||
_this2._running = false; | ||
_this2.reject(_context3.t0); | ||
} | ||
return _context3.abrupt("return"); | ||
case 13: | ||
startByte = _this2._range[0] + _this2._receivedLength; | ||
if (!_this2._aborted) { | ||
_context3.next = 16; | ||
_context3.next = 18; | ||
break; | ||
} | ||
onProgress(void 0, true, { | ||
_this2._running = false; | ||
onProgress(void 0, false, { | ||
range: [startByte, startByte], | ||
vid: _this2._vid, | ||
index: _this2._index, | ||
startTime, | ||
@@ -281,11 +322,28 @@ endTime | ||
return _context3.abrupt("return"); | ||
case 16: | ||
case 18: | ||
_this2._receivedLength += data.value ? data.value.byteLength : 0; | ||
_this2._logger.debug("\u3010fetchLoader,onProgress call\u3011,task,", _this2._range, ", start,", startByte, ", end,", _this2._range[0] + _this2._receivedLength, ", done,", data.done); | ||
onProgress(data.value, data.done, { | ||
range: [startByte, _this2._range[0] + _this2._receivedLength], | ||
vid: _this2._vid, | ||
index: _this2._index, | ||
startTime, | ||
endTime | ||
}, response); | ||
costTime = Date.now() - st; | ||
_this2._logger.debug("[fetchLoader SPEED], fetch speed(b/s),", _this2._receivedLength * 8 / (costTime / 1e3)); | ||
SpeedSampler.netSampling({ | ||
mTime: costTime, | ||
mBytes: _this2._receivedLength, | ||
mSpeedInbPS: _this2._receivedLength * 8 / (costTime / 1e3), | ||
mRTT: firstByteTime - st | ||
}); | ||
if (!data.done) { | ||
pump(); | ||
} else { | ||
_this2._running = false; | ||
_this2._logger.debug("[fetchLoader onProgress end],task,", _this2._range, ",done,", data.done); | ||
_this2.resolve(createResponse(data, true, response, response.headers.get("Content-Length"), response.headers.get("age"), startTime, firstByteTime, _this2._index, _this2._range, _this2._vid)); | ||
} | ||
case 18: | ||
case 25: | ||
case "end": | ||
@@ -303,2 +361,15 @@ return _context3.stop(); | ||
} | ||
}, { | ||
key: "receiveLen", | ||
get: function get() { | ||
return this._receivedLength; | ||
} | ||
}, { | ||
key: "running", | ||
get: function get() { | ||
return this._running; | ||
}, | ||
set: function set(status) { | ||
this._running = status; | ||
} | ||
}], [{ | ||
@@ -305,0 +376,0 @@ key: "isSupported", |
export function getRangeValue(value: any): string; | ||
export function setUrlParams(url: any, params: any): any; | ||
export function createResponse(data: any, response: any, contentLength: any, age: any, startTime: any, firstByteTime: any): { | ||
export function createResponse(data: any, done: any, response: any, contentLength: any, age: any, startTime: any, firstByteTime: any, index: any, range: any, vid: any): { | ||
data: any; | ||
done: any; | ||
option: { | ||
range: any; | ||
vid: any; | ||
index: any; | ||
contentLength: any; | ||
age: any; | ||
startTime: any; | ||
firstByteTime: any; | ||
endTime: any; | ||
}; | ||
response: any; | ||
contentLength: any; | ||
age: any; | ||
startTime: any; | ||
firstByteTime: any; | ||
endTime: any; | ||
}; |
@@ -11,5 +11,7 @@ import "core-js/modules/es.regexp.exec.js"; | ||
import "core-js/modules/es.array.slice.js"; | ||
import "core-js/modules/es.number.is-nan.js"; | ||
import "core-js/modules/es.number.constructor.js"; | ||
import { isDate, isObject } from "../is.js"; | ||
function getRangeValue(value) { | ||
if (!value || value[0] == null || value[0] === 0 && value[1] == null) { | ||
if (!value || value[0] === null || value[0] === void 0 || value[0] === 0 && (value[1] === null || value[1] === void 0)) { | ||
return; | ||
@@ -33,3 +35,3 @@ } | ||
v = params[k]; | ||
if (v == null) | ||
if (v === null || v === void 0) | ||
return; | ||
@@ -59,10 +61,11 @@ if (Array.isArray(v)) { | ||
} | ||
function createResponse(data, response, contentLength, age, startTime, firstByteTime) { | ||
age = age != null ? parseFloat(age) : null; | ||
function createResponse(data, done, response, contentLength, age, startTime, firstByteTime, index, range, vid) { | ||
age = age !== null && age !== void 0 ? parseFloat(age) : null; | ||
contentLength = parseInt(contentLength || "0", 10); | ||
if (isNaN(contentLength)) | ||
if (Number.isNaN(contentLength)) | ||
contentLength = 0; | ||
return { | ||
data, | ||
response, | ||
var option = { | ||
range, | ||
vid, | ||
index, | ||
contentLength, | ||
@@ -74,3 +77,9 @@ age, | ||
}; | ||
return { | ||
data, | ||
done, | ||
option, | ||
response | ||
}; | ||
} | ||
export { createResponse, getRangeValue, setUrlParams }; |
export class NetLoader { | ||
static isFetchSupport(): boolean; | ||
static getSpeed(): number; | ||
static getRealTimeSpeed(): number; | ||
static getRTT(): any; | ||
constructor(cfg: any); | ||
@@ -9,2 +12,3 @@ type: string; | ||
_config: any; | ||
log: any; | ||
isFetch(): boolean; | ||
@@ -11,0 +15,0 @@ load(url: any, config?: {}): any; |
import { createClass as _createClass, classCallCheck as _classCallCheck, defineProperty as _defineProperty, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from "../_virtual/_rollupPluginBabelHelpers.js"; | ||
import "core-js/modules/es.object.assign.js"; | ||
import "core-js/modules/es.array.push.js"; | ||
import "core-js/modules/es.array.concat.js"; | ||
@@ -19,2 +20,3 @@ import "core-js/modules/es.array.map.js"; | ||
import { sleep } from "../streaming-helper.js"; | ||
import SpeedSampler from "./speed-sampler.js"; | ||
var NetLoader = /* @__PURE__ */ function() { | ||
@@ -31,2 +33,3 @@ function NetLoader2(cfg) { | ||
} | ||
this.log = cfg.logger; | ||
} | ||
@@ -57,5 +60,6 @@ _createClass(NetLoader2, [{ | ||
} | ||
config.logger = this.log; | ||
var task = new Task(this.type, config); | ||
this._queue.push(task); | ||
if (this._queue.length === 1) { | ||
if (this._queue.length === 1 && (!this._currentTask || !this._currentTask.running)) { | ||
this._processTask(); | ||
@@ -111,4 +115,3 @@ } | ||
} | ||
this._currentTask.exec().catch(function() { | ||
}).finally(function() { | ||
this._currentTask.exec().finally(function() { | ||
_this._processTask(); | ||
@@ -122,2 +125,17 @@ }); | ||
} | ||
}, { | ||
key: "getSpeed", | ||
value: function getSpeed() { | ||
return SpeedSampler.getSpeed(); | ||
} | ||
}, { | ||
key: "getRealTimeSpeed", | ||
value: function getRealTimeSpeed() { | ||
return SpeedSampler.getRealTimeSpeed(); | ||
} | ||
}, { | ||
key: "getRTT", | ||
value: function getRTT() { | ||
return SpeedSampler.getRTT(); | ||
} | ||
}]); | ||
@@ -124,0 +142,0 @@ return NetLoader2; |
@@ -11,6 +11,8 @@ export class Task { | ||
_canceled: boolean; | ||
_logger: any; | ||
exec(): any; | ||
cancel(): unknown; | ||
get running(): any; | ||
} | ||
import { FetchLoader } from "./fetch"; | ||
import { XhrLoader } from "./xhr"; |
@@ -6,2 +6,3 @@ import { createClass as _createClass, objectWithoutProperties as _objectWithoutProperties, classCallCheck as _classCallCheck, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from "../_virtual/_rollupPluginBabelHelpers.js"; | ||
import { createPublicPromise } from "../utils.js"; | ||
import { Logger } from "../logger.js"; | ||
var _excluded = ["retry", "retryDelay", "onRetryError", "transformError"]; | ||
@@ -13,2 +14,3 @@ var Task = /* @__PURE__ */ function() { | ||
this.alive = !!config.onProgress; | ||
!config.logger && (config.logger = new Logger("Loader")); | ||
this._loaderType = type; | ||
@@ -20,2 +22,3 @@ this._loader = type === LoaderType.FETCH ? new FetchLoader() : new XhrLoader(); | ||
this._canceled = false; | ||
this._logger = config.logger; | ||
} | ||
@@ -40,3 +43,3 @@ _createClass(Task2, [{ | ||
_this.promise.resolve(response); | ||
_context.next = 22; | ||
_context.next = 28; | ||
break; | ||
@@ -46,8 +49,17 @@ case 7: | ||
_context.t0 = _context["catch"](0); | ||
_this._loader.running = false; | ||
_this._logger.debug("[task request catch err]", _context.t0); | ||
if (!_this._canceled) { | ||
_context.next = 11; | ||
_context.next = 13; | ||
break; | ||
} | ||
return _context.abrupt("return"); | ||
case 11: | ||
case 13: | ||
if (!(_context.t0.response && _context.t0.response.status >= 400 && _context.t0.response.status <= 599)) { | ||
_context.next = 16; | ||
break; | ||
} | ||
_this.promise.reject(_context.t0); | ||
return _context.abrupt("return"); | ||
case 16: | ||
_context.t0.loaderType = _this._loaderType; | ||
@@ -63,11 +75,12 @@ _context.t0.retryCount = _this._retryCount; | ||
if (!(_this._retryCount <= retry)) { | ||
_context.next = 21; | ||
_context.next = 27; | ||
break; | ||
} | ||
clearTimeout(_this._retryTimer); | ||
_this._logger.debug("[task request setTimeout],retry", _this._retryCount, ",retry range,", rest.range); | ||
_this._retryTimer = setTimeout(request, retryDelay); | ||
return _context.abrupt("return"); | ||
case 21: | ||
case 27: | ||
_this.promise.reject(error); | ||
case 22: | ||
case 28: | ||
case "end": | ||
@@ -96,4 +109,5 @@ return _context.stop(); | ||
this._canceled = true; | ||
this._loader.running = false; | ||
return _context2.abrupt("return", this._loader.cancel()); | ||
case 3: | ||
case 4: | ||
case "end": | ||
@@ -110,2 +124,7 @@ return _context2.stop(); | ||
}() | ||
}, { | ||
key: "running", | ||
get: function get() { | ||
return this._loader && this._loader.running; | ||
} | ||
}]); | ||
@@ -112,0 +131,0 @@ return Task2; |
@@ -6,5 +6,42 @@ export class XhrLoader { | ||
_timeoutTimer: any; | ||
_range: any; | ||
_receivedLength: number; | ||
_url: any; | ||
_onProgress: any; | ||
_index: number; | ||
_headers: any; | ||
_chunkSizeKBList: number[]; | ||
_currentChunkSizeKB: number; | ||
_currentSpeedNormalized: number; | ||
_zeroSpeedChunkCount: number; | ||
_timeout: any; | ||
_withCredentials: any; | ||
_startTime: number; | ||
_speedSampler: SpeedSampler; | ||
_loadCompleteResolve: any; | ||
_loadCompleteReject: any; | ||
_runing: boolean; | ||
_logger: boolean; | ||
_vid: string; | ||
_responseType: any; | ||
_credentials: any; | ||
_method: any; | ||
_transformResponse: any; | ||
_firstRtt: any; | ||
_subRangeStartTime: any; | ||
load(req: any): any; | ||
_onTimeout: any; | ||
_request: any; | ||
_startLoad(): void; | ||
_internalOpen(range: any): void; | ||
_running: any; | ||
_onReadyStatechange(e: any): void; | ||
_onLoad(e: any): any; | ||
_normalizeSpeed(input: any): any; | ||
cancel(): any; | ||
get receiveLen(): number; | ||
set running(arg: any); | ||
get running(): any; | ||
_getHeaders(xhr: any): {}; | ||
} | ||
import SpeedSampler from "./speed-sampler"; |
@@ -1,2 +0,2 @@ | ||
import { createClass as _createClass, createForOfIteratorHelper as _createForOfIteratorHelper, classCallCheck as _classCallCheck, defineProperty as _defineProperty } from "../_virtual/_rollupPluginBabelHelpers.js"; | ||
import { createClass as _createClass, objectSpread2 as _objectSpread2, createForOfIteratorHelper as _createForOfIteratorHelper, classCallCheck as _classCallCheck, defineProperty as _defineProperty } from "../_virtual/_rollupPluginBabelHelpers.js"; | ||
import "core-js/modules/es.object.to-string.js"; | ||
@@ -15,2 +15,4 @@ import "core-js/modules/es.promise.js"; | ||
import "core-js/modules/es.typed-array.find-index.js"; | ||
import "core-js/modules/es.typed-array.find-last.js"; | ||
import "core-js/modules/es.typed-array.find-last-index.js"; | ||
import "core-js/modules/es.typed-array.for-each.js"; | ||
@@ -33,6 +35,5 @@ import "core-js/modules/es.typed-array.includes.js"; | ||
import "core-js/modules/es.typed-array.to-string.js"; | ||
import "core-js/modules/esnext.typed-array.find-last.js"; | ||
import "core-js/modules/esnext.typed-array.find-last-index.js"; | ||
import "core-js/modules/es.regexp.exec.js"; | ||
import "core-js/modules/es.string.split.js"; | ||
import "core-js/modules/esnext.typed-array.to-reversed.js"; | ||
import "core-js/modules/esnext.typed-array.to-sorted.js"; | ||
import "core-js/modules/esnext.typed-array.with.js"; | ||
import "core-js/modules/es.string.trim.js"; | ||
@@ -44,2 +45,3 @@ import "core-js/modules/es.array.join.js"; | ||
import { ResponseType } from "./types.js"; | ||
import SpeedSampler from "./speed-sampler.js"; | ||
var XhrLoader = /* @__PURE__ */ function() { | ||
@@ -51,2 +53,28 @@ function XhrLoader2() { | ||
_defineProperty(this, "_timeoutTimer", null); | ||
_defineProperty(this, "_range", null); | ||
_defineProperty(this, "_receivedLength", 0); | ||
_defineProperty(this, "_url", null); | ||
_defineProperty(this, "_onProgress", null); | ||
_defineProperty(this, "_index", -1); | ||
_defineProperty(this, "_headers", null); | ||
_defineProperty(this, "_chunkSizeKBList", [128, 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192]); | ||
_defineProperty(this, "_currentChunkSizeKB", 384); | ||
_defineProperty(this, "_currentSpeedNormalized", 0); | ||
_defineProperty(this, "_zeroSpeedChunkCount", 0); | ||
_defineProperty(this, "_timeout", null); | ||
_defineProperty(this, "_xhr", null); | ||
_defineProperty(this, "_withCredentials", null); | ||
_defineProperty(this, "_startTime", -1); | ||
_defineProperty(this, "_speedSampler", new SpeedSampler()); | ||
_defineProperty(this, "_loadCompleteResolve", null); | ||
_defineProperty(this, "_loadCompleteReject", null); | ||
_defineProperty(this, "_runing", false); | ||
_defineProperty(this, "_logger", false); | ||
_defineProperty(this, "_vid", ""); | ||
_defineProperty(this, "_responseType", void 0); | ||
_defineProperty(this, "_credentials", void 0); | ||
_defineProperty(this, "_method", void 0); | ||
_defineProperty(this, "_transformResponse", void 0); | ||
_defineProperty(this, "_firstRtt", void 0); | ||
_defineProperty(this, "_subRangeStartTime", void 0); | ||
} | ||
@@ -58,14 +86,87 @@ _createClass(XhrLoader2, [{ | ||
clearTimeout(this._timeoutTimer); | ||
var url = req.url, params = req.params, timeout = req.timeout, responseType = req.responseType, onTimeout = req.onTimeout, transformResponse = req.transformResponse, onProgress = req.onProgress, method = req.method, credentials = req.credentials, body = req.body, headers = req.headers, range = req.range, request = req.request; | ||
var isTimeout = false; | ||
url = setUrlParams(url, params); | ||
this._logger = req.logger; | ||
this._range = req.range || [0, 0]; | ||
this._onProgress = req.onProgress; | ||
this._index = req.index; | ||
this._headers = req.headers; | ||
this._withCredentials = req.credentials === "include" || req.credentials === "same-origin"; | ||
this._timeout = req.timeout || null; | ||
this._runing = true; | ||
this._vid = req.vid || req.url; | ||
this._responseType = req.responseType; | ||
this._firstRtt = -1; | ||
this._onTimeout = req.onTimeout; | ||
this._request = req.request; | ||
this._credentials = req.credentials; | ||
this._logger.debug("\u3010xhrLoader task\u3011, range", this._range); | ||
this._url = setUrlParams(req.url, req.params); | ||
var startTime = Date.now(); | ||
return new Promise(function(resolve, reject) { | ||
var xhr = _this._xhr = new XMLHttpRequest(); | ||
xhr.open(method || "GET", url, true); | ||
xhr.responseType = responseType; | ||
xhr.withCredentials = credentials === "include" || credentials === "same-origin"; | ||
_this._loadCompleteResolve = resolve; | ||
_this._loadCompleteReject = reject; | ||
_this._startLoad(); | ||
}).catch(function(error) { | ||
clearTimeout(_this._timeoutTimer); | ||
_this._runing = false; | ||
if (_this._aborted) | ||
return; | ||
error = error instanceof NetError ? error : new NetError(_this._url, _this._request); | ||
error.startTime = startTime; | ||
error.endTime = Date.now(); | ||
throw error; | ||
}); | ||
} | ||
}, { | ||
key: "_startLoad", | ||
value: function _startLoad() { | ||
var range = null; | ||
if (this._range && this._range.length > 1) { | ||
if (this._onProgress) { | ||
this._subRangeStartTime = Date.now(); | ||
this._firstRtt = -1; | ||
var chunkSize = this._currentChunkSizeKB * 1024; | ||
var from = this._range[0] + this._receivedLength; | ||
var to = this._range[1]; | ||
if (chunkSize < this._range[1] - from) { | ||
to = from + chunkSize; | ||
} | ||
range = [from, to]; | ||
this._logger.debug("[xhr_loader->],tast :", this._range, ", SubRange, ", range); | ||
} else { | ||
range = this._range; | ||
this._logger.debug("[xhr_loader->],tast :", this._range, ", allRange, ", range); | ||
} | ||
} | ||
this._internalOpen(range); | ||
} | ||
}, { | ||
key: "_internalOpen", | ||
value: function _internalOpen(range) { | ||
var _this2 = this; | ||
try { | ||
this._startTime = Date.now(); | ||
var xhr = this._xhr = new XMLHttpRequest(); | ||
xhr.open(this._method || "GET", this._url, true); | ||
xhr.responseType = this._responseType; | ||
this._timeout && (xhr.timeout = this._timeout); | ||
xhr.withCredentials = this._credentials; | ||
xhr.onload = this._onLoad.bind(this); | ||
xhr.onreadystatechange = this._onReadyStatechange.bind(this); | ||
xhr.onerror = function(event) { | ||
_this2._running = false; | ||
_this2._loadCompleteReject(event); | ||
}; | ||
xhr.ontimeout = function(event) { | ||
_this2.cancel(); | ||
if (_this2._onTimeout) { | ||
var error = new NetError(_this2._url, _this2._request); | ||
error.isTimeout = true; | ||
_this2._onTimeout(error); | ||
} | ||
_this2._loadCompleteReject(event); | ||
}; | ||
var rangeValue = getRangeValue(range); | ||
var headers = null; | ||
if (rangeValue) { | ||
headers = headers || {}; | ||
headers = this._headers || {}; | ||
headers.Range = rangeValue; | ||
@@ -78,64 +179,117 @@ } | ||
} | ||
if (timeout) { | ||
_this._timeoutTimer = setTimeout(function() { | ||
isTimeout = true; | ||
_this.cancel(); | ||
if (onTimeout) { | ||
var error = new NetError(url, request); | ||
error.isTimeout = true; | ||
onTimeout(error); | ||
} | ||
}, timeout); | ||
this._logger.debug("[xhr.send->] tast,", this._range, ",load sub range, ", range); | ||
xhr.send(); | ||
} catch (e) { | ||
this._loadCompleteReject(e); | ||
} | ||
} | ||
}, { | ||
key: "_onReadyStatechange", | ||
value: function _onReadyStatechange(e) { | ||
var xhr = e.target; | ||
if (xhr.readyState === 2) { | ||
this._firstRtt < 0 && (this._firstRtt = Date.now()); | ||
} | ||
} | ||
}, { | ||
key: "_onLoad", | ||
value: function _onLoad(e) { | ||
var status = e.target.status; | ||
if (status < 200 || status > 299) { | ||
return this._loadCompleteReject(new NetError(this._url, null, _objectSpread2(_objectSpread2({}, e.target.response), {}, { | ||
status | ||
}), "bad response,status:" + status)); | ||
} | ||
var KBps = this._speedSampler.lastSecondKBps; | ||
if (KBps === 0) { | ||
this._zeroSpeedChunkCount++; | ||
if (this._zeroSpeedChunkCount >= 3) { | ||
KBps = this._speedSampler.currentKBps; | ||
} | ||
xhr.onerror = function(event) { | ||
return reject(event); | ||
}; | ||
xhr.onreadystatechange = function() { | ||
if (xhr.readyState >= 2) { | ||
clearTimeout(_this._timeoutTimer); | ||
var firstByteTime = Date.now(); | ||
if (xhr.readyState === 4) { | ||
xhr.onreadystatechange = null; | ||
if (_this._aborted) | ||
return; | ||
var status = xhr.status; | ||
var response = { | ||
ok: status >= 200 && status < 300, | ||
status, | ||
statusText: xhr.statusText, | ||
url: xhr.responseURL, | ||
headers: _this._getHeaders(xhr), | ||
body: xhr.response | ||
}; | ||
if (transformResponse) { | ||
response = transformResponse(response, url) || response; | ||
} | ||
if (!response.ok) { | ||
return reject(new NetError(url, request, response, "bad network response")); | ||
} | ||
var isArraybuffer = xhr.responseType === ResponseType.ARRAY_BUFFER; | ||
var data = isArraybuffer ? new Uint8Array(xhr.response) : xhr.response; | ||
if (onProgress) { | ||
onProgress(isArraybuffer ? data : void 0, true, { | ||
startTime, | ||
endTime: Date.now() | ||
}, response); | ||
} | ||
resolve(createResponse(data, response, response.headers["content-length"], response.headers.age, startTime, firstByteTime)); | ||
} | ||
} | ||
}; | ||
xhr.send(body); | ||
}).catch(function(error) { | ||
clearTimeout(_this._timeoutTimer); | ||
if (_this._aborted && !isTimeout) | ||
return; | ||
error = error instanceof NetError ? error : new NetError(url, request); | ||
error.startTime = startTime; | ||
error.endTime = Date.now(); | ||
error.isTimeout = isTimeout; | ||
throw error; | ||
}); | ||
} | ||
if (KBps !== 0) { | ||
var normalized = this._normalizeSpeed(KBps); | ||
if (this._currentSpeedNormalized !== normalized) { | ||
this._currentSpeedNormalized = normalized; | ||
this._currentChunkSizeKB = normalized; | ||
} | ||
} | ||
var data = null; | ||
var done = false; | ||
var byteStart; | ||
if (this._responseType === ResponseType.ARRAY_BUFFER) { | ||
var chunk = new Uint8Array(e.target.response); | ||
byteStart = this._range[0] + this._receivedLength; | ||
if (chunk && chunk.byteLength > 0) { | ||
this._receivedLength += chunk.byteLength; | ||
var costTime = Date.now() - this._subRangeStartTime; | ||
this._speedSampler.addBytes(chunk.byteLength); | ||
SpeedSampler.netSampling({ | ||
mTime: costTime, | ||
mBytes: this._receivedLength, | ||
mSpeedInbPS: this._receivedLength * 8 / (costTime / 1e3), | ||
mRTT: this._firstRtt - this._subRangeStartTime | ||
}); | ||
} | ||
data = chunk; | ||
if (this._range.length > 1 && this._range[1] && this._receivedLength < this._range[1] - this._range[0]) { | ||
done = false; | ||
} else { | ||
done = true; | ||
} | ||
this._logger.debug("[xhr load done->], tast :", this._range, ", start", byteStart, "end ", this._range[0] + this._receivedLength, ",dataLen,", chunk ? chunk.byteLength : 0, ",receivedLength", this._receivedLength, ",index,", this._index, ", done,", done); | ||
} else { | ||
done = true; | ||
data = e.target.response; | ||
} | ||
var response = { | ||
ok: status >= 200 && status < 300, | ||
status, | ||
statusText: this._xhr.statusText, | ||
url: this._xhr.responseURL, | ||
headers: this._getHeaders(this._xhr), | ||
body: this._xhr.response | ||
}; | ||
if (this._transformResponse) { | ||
response = this._transformResponse(response, this._url) || response; | ||
} | ||
if (this._onProgress) { | ||
this._onProgress(data, done, { | ||
index: this._index, | ||
vid: this._vid, | ||
range: [byteStart, this._range[0] + this._receivedLength], | ||
startTime: this._startTime, | ||
endTime: Date.now() | ||
}, response); | ||
} | ||
if (!done) { | ||
this._startLoad(); | ||
} else { | ||
this._runing = false; | ||
this._loadCompleteResolve && this._loadCompleteResolve(createResponse(this._onProgress ? null : data, done, response, response.headers["content-length"], response.headers.age, this._startTime, -1, this._index, this._range, this._vid)); | ||
} | ||
} | ||
}, { | ||
key: "_normalizeSpeed", | ||
value: function _normalizeSpeed(input) { | ||
var list = this._chunkSizeKBList; | ||
var last = list.length - 1; | ||
var mid = 0; | ||
var lbound = 0; | ||
var ubound = last; | ||
if (input < list[0]) { | ||
return list[0]; | ||
} | ||
while (lbound <= ubound) { | ||
mid = lbound + Math.floor((ubound - lbound) / 2); | ||
if (mid === last || input >= list[mid] && input < list[mid + 1]) { | ||
return list[mid]; | ||
} else if (list[mid] < input) { | ||
lbound = mid + 1; | ||
} else { | ||
ubound = mid - 1; | ||
} | ||
} | ||
} | ||
}, { | ||
key: "cancel", | ||
@@ -146,7 +300,21 @@ value: function cancel() { | ||
this._aborted = true; | ||
this._runing = false; | ||
if (this._xhr) { | ||
return this._xhr.cancel(); | ||
return this._xhr.abort(); | ||
} | ||
} | ||
}, { | ||
key: "receiveLen", | ||
get: function get() { | ||
return this._receivedLength; | ||
} | ||
}, { | ||
key: "running", | ||
get: function get() { | ||
return this._running; | ||
}, | ||
set: function set(status) { | ||
this._running = status; | ||
} | ||
}, { | ||
key: "_getHeaders", | ||
@@ -153,0 +321,0 @@ value: function _getHeaders(xhr) { |
import { createClass as _createClass, classCallCheck as _classCallCheck, defineProperty as _defineProperty } from "../_virtual/_rollupPluginBabelHelpers.js"; | ||
import "core-js/modules/es.array.push.js"; | ||
import "core-js/modules/es.array.slice.js"; | ||
@@ -24,3 +25,3 @@ import "core-js/modules/es.object.to-string.js"; | ||
this._chunkSpeeds.push(8e3 * totalByte / ms); | ||
this._chunkSpeeds = this._chunkSpeeds.slice(-10); | ||
this._chunkSpeeds = this._chunkSpeeds.slice(-100); | ||
} | ||
@@ -27,0 +28,0 @@ }, { |
@@ -8,2 +8,3 @@ import { createClass as _createClass, classCallCheck as _classCallCheck, defineProperty as _defineProperty } from "../_virtual/_rollupPluginBabelHelpers.js"; | ||
import "core-js/modules/web.dom-collections.for-each.js"; | ||
import "core-js/modules/es.array.push.js"; | ||
import { EVENT } from "../event.js"; | ||
@@ -25,3 +26,3 @@ var SeiService = /* @__PURE__ */ function() { | ||
var _this2 = this; | ||
if (currentTime == null || !this._seiSet.size) | ||
if (currentTime === null || currentTime === void 0 || !this._seiSet.size) | ||
return; | ||
@@ -28,0 +29,0 @@ var min = currentTime - 0.2; |
@@ -12,2 +12,4 @@ import "core-js/modules/es.array.filter.js"; | ||
import "core-js/modules/es.typed-array.find-index.js"; | ||
import "core-js/modules/es.typed-array.find-last.js"; | ||
import "core-js/modules/es.typed-array.find-last-index.js"; | ||
import "core-js/modules/es.typed-array.for-each.js"; | ||
@@ -30,4 +32,5 @@ import "core-js/modules/es.typed-array.includes.js"; | ||
import "core-js/modules/es.typed-array.to-string.js"; | ||
import "core-js/modules/esnext.typed-array.find-last.js"; | ||
import "core-js/modules/esnext.typed-array.find-last-index.js"; | ||
import "core-js/modules/esnext.typed-array.to-reversed.js"; | ||
import "core-js/modules/esnext.typed-array.to-sorted.js"; | ||
import "core-js/modules/esnext.typed-array.with.js"; | ||
import "core-js/modules/web.dom-collections.for-each.js"; | ||
@@ -34,0 +37,0 @@ import "core-js/modules/es.promise.js"; |
{ | ||
"name": "xgplayer-streaming-shared", | ||
"version": "3.0.0-next.10", | ||
"version": "3.0.0-next.11", | ||
"main": "dist/index.min.js", | ||
@@ -5,0 +5,0 @@ "module": "es/index.js", |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3601
2
125246