Socket
Socket
Sign inDemoInstall

xgplayer-streaming-shared

Package Overview
Dependencies
3
Maintainers
1
Versions
178
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0-next.1 to 3.0.0-next.2

es/is.d.ts

6

es/event.d.ts

@@ -8,2 +8,6 @@ export namespace EVENT {

const LOAD_RETRY: string;
const SOURCEBUFFER_CREATED: string;
const ANALYZE_DURATION_EXCEEDED: string;
const REMOVE_BUFFER: string;
const BUFFEREOS: string;
const KEYFRAME: string;

@@ -18,2 +22,4 @@ const METADATA_PARSED: string;

const SPEED: string;
const HLS_MANIFEST_LOADED: string;
const HLS_LEVEL_LOADED: string;
const STREAM_EXCEPTION: string;

@@ -20,0 +26,0 @@ const LARGE_AV_FIRST_FRAME_GAP_DETECT: string;

@@ -8,2 +8,6 @@ var EVENT = {

LOAD_RETRY: 'core.loadretry',
SOURCEBUFFER_CREATED: 'core.sourcebuffercreated',
ANALYZE_DURATION_EXCEEDED: 'core.analyzedurationexceeded',
REMOVE_BUFFER: 'core.removebuffer',
BUFFEREOS: 'core.buffereos',
KEYFRAME: 'core.keyframe',

@@ -18,2 +22,4 @@ METADATA_PARSED: 'core.metadataparsed',

SPEED: 'core.speed',
HLS_MANIFEST_LOADED: 'core.hlsmanifestloaded',
HLS_LEVEL_LOADED: 'core.hlslevelloaded',
STREAM_EXCEPTION: 'core.streamexception',

@@ -20,0 +26,0 @@ LARGE_AV_FIRST_FRAME_GAP_DETECT: 'LARGE_AV_FIRST_FRAME_GAP_DETECT',

2

es/index.js

@@ -8,4 +8,2 @@ export { MSE, MSEError, MSEErrorType } from './mse.js';

export { Logger } from './logger.js';
export { FetchLoader } from './net/fetch.js';
export { XhrLoader } from './net/xhr.js';
export { LoaderType, ResponseType } from './net/types.js';

@@ -12,0 +10,0 @@ export { GapService } from './services/gap.js';

@@ -32,2 +32,3 @@ export type MSEErrorType = string;

_sourceBuffer: any;
get isOpened(): boolean;
get duration(): number;

@@ -34,0 +35,0 @@ /**

@@ -108,8 +108,15 @@ import 'core-js/modules/es.reflect.construct.js';

_createClass(MSE, [{
key: "duration",
key: "isOpened",
get: function get() {
var _this$mediaSource;
return ((_this$mediaSource = this.mediaSource) === null || _this$mediaSource === void 0 ? void 0 : _this$mediaSource.duration) || -1;
return ((_this$mediaSource = this.mediaSource) === null || _this$mediaSource === void 0 ? void 0 : _this$mediaSource.readyState) === 'open';
}
}, {
key: "duration",
get: function get() {
var _this$mediaSource2;
return ((_this$mediaSource2 = this.mediaSource) === null || _this$mediaSource2 === void 0 ? void 0 : _this$mediaSource2.duration) || -1;
}
/**

@@ -134,2 +141,17 @@ * @param { number } duration

value: function open() {
var _this4 = this;
if (this._openPromise.used && !this.isOpened && this.mediaSource) {
var ms = this.mediaSource;
var onOpen = function onOpen() {
ms.removeEventListener('sourceopen', onOpen);
_this4._openPromise.resolve();
};
ms.addEventListener('sourceopen', onOpen);
this._openPromise = createPublicPromise();
}
return this._openPromise;

@@ -146,3 +168,3 @@ }

var _bindMedia = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(media) {
var _this4 = this;
var _this5 = this;

@@ -179,3 +201,3 @@ var ms, onOpen;

_this4._openPromise.resolve();
_this5._openPromise.resolve();
};

@@ -206,3 +228,3 @@

var _unbindMedia = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
var _this5 = this;
var _this6 = this;

@@ -214,2 +236,3 @@ var ms;

case 0:
if (!this._openPromise.used) this._openPromise.resolve();
ms = this.mediaSource;

@@ -219,3 +242,3 @@

Object.keys(this._queue).forEach(function (t) {
var queue = _this5._queue[t];
var queue = _this6._queue[t];

@@ -238,3 +261,3 @@ if (queue) {

try {
ms.removeSourceBuffer(_this5._sourceBuffer[k]);
ms.removeSourceBuffer(_this6._sourceBuffer[k]);
} catch (error) {// ignore

@@ -261,3 +284,3 @@ }

case 7:
case 8:
case "end":

@@ -326,3 +349,3 @@ return _context2.stop();

value: function append(type, buffer) {
var _this6 = this;
var _this7 = this;

@@ -333,6 +356,7 @@ if (!buffer || !buffer.byteLength) {

if (!this._sourceBuffer[type]) return Promise.resolve();
return this._enqueueOp(type, function () {
if (!_this6.mediaSource) return;
if (!_this7.mediaSource) return;
_this6._sourceBuffer[type].appendBuffer(buffer);
_this7._sourceBuffer[type].appendBuffer(buffer);
});

@@ -350,10 +374,10 @@ }

value: function remove(type, startTime, endTime) {
var _this7 = this;
var _this8 = this;
return this._enqueueOp(type, function () {
if (!_this7.mediaSource) return;
var sb = _this7._sourceBuffer[type];
if (!_this8.mediaSource) return;
var sb = _this8._sourceBuffer[type];
if (startTime >= endTime || !sb) {
_this7._onSBUpdateEnd(type);
_this8._onSBUpdateEnd(type);

@@ -369,9 +393,9 @@ return;

value: function clearAllBuffer() {
var _this8 = this;
var _this9 = this;
var p;
Object.keys(this._sourceBuffer).forEach(function (k) {
p = _this8._enqueueOp(k, function () {
if (!_this8.mediaSource) return;
var sb = _this8._sourceBuffer[k];
p = _this9._enqueueOp(k, function () {
if (!_this9.mediaSource) return;
var sb = _this9._sourceBuffer[k];
sb.remove(0, Buffer.end(Buffer.get(sb)));

@@ -390,7 +414,7 @@ });

value: function endOfStream(reason) {
var _this9 = this;
var _this10 = this;
if (!this.mediaSource || this.mediaSource.readyState !== 'open') return Promise.resolve();
return this._enqueueBlockingOp(function () {
var ms = _this9.mediaSource;
var ms = _this10.mediaSource;
if (!ms || ms.readyState !== 'open') return;

@@ -463,3 +487,3 @@

var _enqueueBlockingOp2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(exec) {
var _this10 = this;
var _this11 = this;

@@ -491,3 +515,3 @@ var types, waiters;

types.forEach(function (t) {
var queue = _this10._queue[t];
var queue = _this11._queue[t];
var prom = createPublicPromise();

@@ -503,3 +527,3 @@ waiters.push(prom);

if (queue.length === 1) {
_this10._startQueue(t);
_this11._startQueue(t);
}

@@ -512,8 +536,8 @@ });

types.forEach(function (t) {
var queue = _this10._queue[t];
var sb = _this10._sourceBuffer[t];
queue.shift();
var queue = _this11._queue[t];
var sb = _this11._sourceBuffer[t];
queue === null || queue === void 0 ? void 0 : queue.shift();
if (!sb || !sb.updating) {
_this10._startQueue(t);
_this11._startQueue(t);
}

@@ -520,0 +544,0 @@ });

@@ -6,2 +6,4 @@ export class NetError extends Error {

loaderType: string;
startTime: number;
endTime: number;
url: any;

@@ -8,0 +10,0 @@ request: any;

@@ -32,2 +32,6 @@ import 'core-js/modules/es.reflect.construct.js';

_defineProperty(_assertThisInitialized(_this), "startTime", 0);
_defineProperty(_assertThisInitialized(_this), "endTime", 0);
_this.url = url;

@@ -34,0 +38,0 @@ _this.request = request;

export class FetchLoader {
static isSupported(): boolean;
_abortController: any;
_stats: any;
_timeoutTimer: any;
_reader: any;
_response: any;
load({ url, timeout, responseType, onProgress, onTimeout, range, responseFilter, ...init }: {
[x: string]: any;
_aborted: boolean;
load({ url, timeout, responseType, onProgress, onTimeout, range, transformResponse, request, params, method, headers, body, mode, credentials, cache, redirect, referrer, referrerPolicy, integrity }: {
url: any;

@@ -16,13 +15,26 @@ timeout: any;

range: any;
responseFilter: any;
transformResponse: any;
request: any;
params: any;
method: any;
headers: any;
body: any;
mode: any;
credentials: any;
cache: any;
redirect: any;
referrer: any;
referrerPolicy: any;
integrity: any;
}): Promise<void | {
data: any;
response: Response;
stats: RequestStats;
contentLength: number;
age: string;
response: any;
contentLength: any;
age: any;
startTime: any;
firstByteTime: any;
endTime: number;
}>;
cancel(): Promise<void>;
_loadChunk(response: any, onProgress: any, startTime: any): Promise<any>;
_loadChunk(response: any, onProgress: any): void;
}
import { RequestStats } from "./shared";
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';

@@ -35,7 +34,5 @@ import _createClass from '@babel/runtime/helpers/createClass';

import { NetError } from './error.js';
import { RequestStats, getRangeValue } from './shared.js';
import { setUrlParams, getRangeValue, createResponse } from './helper.js';
import { ResponseType } from './types.js';
import { createPublicPromise } from '../utils.js';
var _excluded = ["url", "timeout", "responseType", "onProgress", "onTimeout", "range", "responseFilter"];
var FetchLoader = /*#__PURE__*/function () {

@@ -47,4 +44,2 @@ function FetchLoader() {

_defineProperty(this, "_stats", null);
_defineProperty(this, "_timeoutTimer", null);

@@ -55,2 +50,4 @@

_defineProperty(this, "_response", null);
_defineProperty(this, "_aborted", false);
}

@@ -69,14 +66,40 @@

range = _ref.range,
responseFilter = _ref.responseFilter,
init = _objectWithoutProperties(_ref, _excluded);
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,
integrity = _ref.integrity;
this._abortController = new AbortController();
var stats = this._stats = new RequestStats();
init.signal = this._abortController.signal;
var init = {
method: method,
headers: headers,
body: body,
mode: mode,
credentials: credentials,
cache: cache,
redirect: redirect,
referrer: referrer,
referrerPolicy: referrerPolicy,
integrity: integrity,
signal: this._abortController.signal
};
var isTimeout = false;
clearTimeout(this._timeoutTimer);
url = setUrlParams(url, params);
var rangeValue = getRangeValue(range);
if (rangeValue) {
var headers = init.headers = init.headers || new Headers();
if (request) {
headers = request.headers;
} else {
headers = init.headers = init.headers || new Headers();
}

@@ -104,6 +127,6 @@ if (headers instanceof Headers) {

var startTime = performance.now();
return fetch(url, init).then( /*#__PURE__*/function () {
var startTime = Date.now();
return fetch(request || url, request ? undefined : init).then( /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(response) {
var age, contentLength, data;
var firstByteTime, data;
return _regeneratorRuntime.wrap(function _callee$(_context) {

@@ -114,11 +137,18 @@ while (1) {

clearTimeout(_this._timeoutTimer);
stats.loadTime = performance.now() - startTime;
_this._response = response;
if (responseFilter) {
response = responseFilter(url, response, stats) || response;
if (!_this._aborted) {
_context.next = 4;
break;
}
return _context.abrupt("return");
case 4:
if (transformResponse) {
response = transformResponse(response, url) || response;
}
if (response.ok) {
_context.next = 6;
_context.next = 7;
break;

@@ -129,68 +159,55 @@ }

case 6:
age = response.headers.get('age');
age = age != null ? parseFloat(age) : null;
contentLength = parseInt(response.headers.get('Content-Length') || '0', 10);
if (isNaN(contentLength)) contentLength = 0;
case 7:
firstByteTime = Date.now();
if (!(responseType === ResponseType.TEXT)) {
_context.next = 17;
_context.next = 14;
break;
}
_context.next = 14;
_context.next = 11;
return response.text();
case 14:
case 11:
data = _context.sent;
_context.next = 33;
_context.next = 28;
break;
case 17:
case 14:
if (!(responseType === ResponseType.JSON)) {
_context.next = 23;
_context.next = 20;
break;
}
_context.next = 20;
_context.next = 17;
return response.json();
case 20:
case 17:
data = _context.sent;
_context.next = 33;
_context.next = 28;
break;
case 23:
case 20:
if (!onProgress) {
_context.next = 28;
_context.next = 24;
break;
}
_context.next = 26;
return _this._loadChunk(response, onProgress, startTime);
_this._loadChunk(response, onProgress);
case 26:
_context.next = 33;
_context.next = 28;
break;
case 28:
_context.next = 30;
case 24:
_context.next = 26;
return response.arrayBuffer();
case 30:
case 26:
data = _context.sent;
data = new Uint8Array(data);
case 33:
stats.totalTime = performance.now() - startTime;
if (stats.aborted) data = undefined;
return _context.abrupt("return", {
data: data,
response: response,
stats: stats,
contentLength: contentLength,
age: age
});
case 28:
return _context.abrupt("return", createResponse(data, response, response.headers.get('Content-Length'), response.headers.get('age'), startTime, firstByteTime));
case 36:
case 29:
case "end":

@@ -208,4 +225,6 @@ return _context.stop();

clearTimeout(_this._timeoutTimer);
if (stats.aborted && !isTimeout) return;
if (_this._aborted && !isTimeout) return;
error = error instanceof NetError ? error : new NetError(url, init);
error.startTime = startTime;
error.endTime = Date.now();
error.isTimeout = isTimeout;

@@ -223,34 +242,42 @@ throw error;

case 0:
if (this._stats) this._stats.aborted = true;
if (!this._aborted) {
_context2.next = 2;
break;
}
return _context2.abrupt("return");
case 2:
this._aborted = true;
if (!this._response) {
_context2.next = 13;
_context2.next = 15;
break;
}
_context2.prev = 2;
_context2.next = 5;
_context2.prev = 4;
_context2.next = 7;
return this._response.body.cancel();
case 5:
case 7:
if (!this._reader) {
_context2.next = 8;
_context2.next = 10;
break;
}
_context2.next = 8;
_context2.next = 10;
return this._reader.cancel();
case 8:
_context2.next = 12;
case 10:
_context2.next = 14;
break;
case 10:
_context2.prev = 10;
_context2.t0 = _context2["catch"](2);
case 12:
_context2.prev = 12;
_context2.t0 = _context2["catch"](4);
case 12:
case 14:
this._response = this._reader = null;
case 13:
case 15:
if (this._abortController) {

@@ -265,3 +292,3 @@ try {

case 14:
case 16:
case "end":

@@ -271,3 +298,3 @@ return _context2.stop();

}
}, _callee2, this, [[2, 10]]);
}, _callee2, this, [[4, 12]]);
}));

@@ -283,7 +310,8 @@

key: "_loadChunk",
value: function _loadChunk(response, onProgress, startTime) {
var stats = this._stats;
value: function _loadChunk(response, onProgress) {
var _this2 = this;
var reader = this._reader = response.body.getReader();
var data;
var prom = createPublicPromise();
var startTime;
var endTime;

@@ -297,38 +325,47 @@

case 0:
_context3.prev = 0;
_context3.next = 3;
startTime = Date.now();
_context3.prev = 1;
_context3.next = 4;
return reader.read();
case 3:
case 4:
data = _context3.sent;
_context3.next = 9;
endTime = Date.now();
_context3.next = 13;
break;
case 6:
_context3.prev = 6;
_context3.t0 = _context3["catch"](0);
return _context3.abrupt("return", prom.resolve());
case 8:
_context3.prev = 8;
_context3.t0 = _context3["catch"](1);
// request aborted
endTime = Date.now();
onProgress(undefined, true, {
startTime: startTime,
endTime: endTime
}, response);
return _context3.abrupt("return");
case 9:
if (!stats.aborted) {
_context3.next = 13;
case 13:
if (!_this2._aborted) {
_context3.next = 16;
break;
}
prom.resolve();
onProgress(undefined, true, response, stats);
onProgress(undefined, true, {
startTime: startTime,
endTime: endTime
}, response);
return _context3.abrupt("return");
case 13:
endTime = performance.now();
onProgress(data.value, data.done, response, stats, endTime - startTime);
startTime = endTime;
case 16:
onProgress(data.value, data.done, {
startTime: startTime,
endTime: endTime
}, response);
if (!data.done) {
pump();
} else {
prom.resolve();
}
case 17:
case 18:
case "end":

@@ -338,3 +375,3 @@ return _context3.stop();

}
}, _callee3, null, [[0, 6]]);
}, _callee3, null, [[1, 8]]);
}));

@@ -348,3 +385,2 @@

pump();
return prom;
}

@@ -351,0 +387,0 @@ }], [{

export class NetLoader {
static isFetchSupport(): boolean;
constructor(opts: any);
constructor(cfg: any);
type: string;
retryCount: number;
loading: boolean;
_canceled: boolean;
_retryTimer: any;
_opts: any;
loader: FetchLoader;
_queue: any[];
_alive: any[];
_currentTask: any;
_config: any;
isFetch(): boolean;
load(url: any, config?: {}): Promise<any>;
cancel(): Promise<void>;
cancel(): Promise<any[]>;
_processTask(): void;
}
import { FetchLoader } from "./fetch";
import { XhrLoader } from "./xhr";
import { LoaderType } from "./types";
import { ResponseType } from "./types";
export { FetchLoader, XhrLoader, LoaderType, ResponseType };
export { LoaderType, ResponseType };

@@ -1,20 +0,23 @@

import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
import _createClass from '@babel/runtime/helpers/createClass';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _regeneratorRuntime from '@babel/runtime/regenerator';
import 'core-js/modules/es.object.assign.js';
import 'core-js/modules/es.array.concat.js';
import 'core-js/modules/es.array.map.js';
import 'core-js/modules/es.array.iterator.js';
import 'core-js/modules/es.object.to-string.js';
import 'core-js/modules/es.promise.js';
import 'core-js/modules/es.string.iterator.js';
import 'core-js/modules/web.dom-collections.iterator.js';
import 'core-js/modules/es.promise.finally.js';
import 'core-js/modules/es.regexp.exec.js';
import { FetchLoader } from './fetch.js';
export { FetchLoader } from './fetch.js';
import { XhrLoader } from './xhr.js';
export { XhrLoader } from './xhr.js';
import { LoaderType } from './types.js';
export { LoaderType, ResponseType } from './types.js';
import { getConfig } from './config.js';
import { Task } from './task.js';
import { isPlainObject } from '../is.js';
var _excluded = ["retry", "retryDelay", "onRetryError"];
var NetLoader = /*#__PURE__*/function () {
function NetLoader(opts) {
function NetLoader(cfg) {
_classCallCheck(this, NetLoader);

@@ -24,31 +27,16 @@

_defineProperty(this, "retryCount", 0);
_defineProperty(this, "_queue", []);
_defineProperty(this, "loading", false);
_defineProperty(this, "_alive", []);
_defineProperty(this, "_canceled", false);
_defineProperty(this, "_currentTask", null);
_defineProperty(this, "_retryTimer", null);
this._config = getConfig(cfg);
this._opts = Object.assign({
retry: 0,
retryDelay: 0 // ms
}, opts);
var Loader = FetchLoader;
if (this._opts.loaderType === LoaderType.XHR || !FetchLoader.isSupported()) {
Loader = XhrLoader;
if (this._config.loaderType === LoaderType.XHR || !FetchLoader.isSupported()) {
this.type = LoaderType.XHR;
}
this.loader = new Loader();
}
_createClass(NetLoader, [{
key: "loading",
get: function get() {
return this.loader.loading;
}
}, {
key: "isFetch",

@@ -61,9 +49,6 @@ value: function isFetch() {

value: function load(url) {
var _this = this;
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (this.loading) return Promise.resolve();
if (typeof url === 'string') {
config.url = url;
if (typeof url === 'string' || !url) {
config.url = url || config.url || this._config.url;
} else {

@@ -73,92 +58,54 @@ config = url;

config = Object.assign({}, config, this._opts);
config = Object.assign({}, this._config, config);
if (config.params) config.params = Object.assign({}, config.params);
if (config.headers && isPlainObject(config.headers)) config.headers = Object.assign({}, config.headers);
if (config.body && isPlainObject(config.body)) config.body = Object.assign({}, config.body);
if (config.requestFilter) {
config = config.requestFilter(config) || config;
if (config.transformRequest) {
config = config.transformRequest(config) || config;
}
var _config = config,
retry = _config.retry,
retryDelay = _config.retryDelay,
onRetryError = _config.onRetryError,
rest = _objectWithoutProperties(_config, _excluded);
var task = new Task(this.type, config);
this.retryCount = 0;
this._canceled = false;
this.loading = true;
retry = retry || this._opts.retry;
retryDelay = retryDelay || this._opts.retryDelay;
return new Promise(function (resolve, reject) {
var request = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var response;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return _this.loader.load(rest);
this._queue.push(task);
case 3:
response = _context.sent;
_this.loading = false;
resolve(response);
_context.next = 22;
break;
if (this._queue.length === 1) {
this._processTask();
}
case 8:
_context.prev = 8;
_context.t0 = _context["catch"](0);
return task.promise;
}
}, {
key: "cancel",
value: function cancel() {
var cancels = this._queue.map(function (t) {
return t.cancel();
}).concat(this._alive.map(function (t) {
return t.cancel();
}));
if (!_this._canceled) {
_context.next = 12;
break;
}
if (this._currentTask) {
cancels.push(this._currentTask.cancel());
}
return _context.abrupt("return");
this._queue = [];
this._alive = [];
return Promise.all(cancels);
}
}, {
key: "_processTask",
value: function _processTask() {
var _this = this;
case 12:
_context.t0.loaderType = _this.type;
_context.t0.retryCount = _this.retryCount;
if (onRetryError && _this.retryCount > 0) onRetryError(_context.t0, _this.retryCount, retry);
_this.retryCount++;
this._currentTask = this._queue.shift();
if (!this._currentTask) return;
if (!(_this.retryCount <= retry)) {
_context.next = 20;
break;
}
if (this._currentTask.alive) {
this._alive.push(this._currentTask);
}
clearTimeout(_this._retryTimer);
_this._retryTimer = setTimeout(request, retryDelay);
return _context.abrupt("return");
case 20:
_this.loading = false;
reject(_context.t0);
case 22:
case "end":
return _context.stop();
}
}
}, _callee, null, [[0, 8]]);
}));
return function request() {
return _ref.apply(this, arguments);
};
}();
request();
this._currentTask.exec().finally(function () {
_this._processTask();
});
}
}, {
key: "cancel",
value: function cancel() {
clearTimeout(this._retryTimer);
this._canceled = true;
this.loading = false;
return this.loader.cancel();
}
}], [{

@@ -165,0 +112,0 @@ key: "isFetchSupport",

export class XhrLoader {
static isSupported(): boolean;
_xhr: any;
_stats: any;
_aborted: boolean;
_timeoutTimer: any;
load(request: any): Promise<any>;
load(req: any): Promise<any>;
cancel(): any;
_getHeaders(xhr: any): {};
}

@@ -46,3 +46,4 @@ import 'core-js/modules/es.function.name.js';

import { NetError } from './error.js';
import { RequestStats, getRangeValue } from './shared.js';
import { setUrlParams, getRangeValue, createResponse } from './helper.js';
import { ResponseType } from './types.js';

@@ -60,3 +61,3 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }

_defineProperty(this, "_stats", null);
_defineProperty(this, "_aborted", false);

@@ -68,19 +69,22 @@ _defineProperty(this, "_timeoutTimer", null);

key: "load",
value: function load(request) {
value: function load(req) {
var _this = this;
var stats = this._stats = new RequestStats();
clearTimeout(this._timeoutTimer);
var url = request.url,
timeout = request.timeout,
responseType = request.responseType,
onTimeout = request.onTimeout,
responseFilter = request.responseFilter,
onProgress = request.onProgress,
method = request.method,
credentials = request.credentials,
body = request.body,
headers = request.headers,
range = request.range;
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);
var startTime = Date.now();
return new Promise(function (resolve, reject) {

@@ -95,3 +99,3 @@ var xhr = _this._xhr = new XMLHttpRequest();

headers = headers || {};
headers.range = rangeValue;
headers.Range = rangeValue;
}

@@ -119,4 +123,2 @@

var startTime = performance.now();
xhr.onerror = function (event) {

@@ -129,10 +131,7 @@ return reject(event);

clearTimeout(_this._timeoutTimer);
var firstByteTime = Date.now();
if (!stats.loadTime) {
stats.loadTime = performance.now() - startTime;
}
if (xhr.readyState === 4) {
xhr.onreadystatechange = null;
stats.totalTime = performance.now() - startTime;
if (_this._aborted) return;
var status = xhr.status;

@@ -143,3 +142,3 @@ var response = {

statusText: xhr.statusText,
url: url,
url: xhr.responseURL,
headers: _this._getHeaders(xhr),

@@ -149,4 +148,4 @@ body: xhr.response

if (responseFilter) {
response = responseFilter(url, response) || response;
if (transformResponse) {
response = transformResponse(response, url) || response;
}

@@ -158,24 +157,13 @@

var isArraybuffer = xhr.responseType === 'arraybuffer';
var isArraybuffer = xhr.responseType === ResponseType.ARRAY_BUFFER;
var data = isArraybuffer ? new Uint8Array(xhr.response) : xhr.response;
var contentLength = parseInt(response.headers.get('content-length') || '0', 10);
if (isNaN(contentLength)) contentLength = 0;
if (isArraybuffer && !contentLength) {
contentLength = data.byteLength;
}
if (stats.aborted) data = undefined;
if (onProgress) {
onProgress(isArraybuffer ? data : undefined, true, response, stats, stats.totalTime);
onProgress(isArraybuffer ? data : undefined, true, {
startTime: startTime,
endTime: Date.now()
}, response);
}
resolve({
data: data,
response: response,
stats: stats,
contentLength: contentLength,
age: response.headers.age && parseFloat(response.headers.age)
});
resolve(createResponse(data, response, response.headers['content-length'], response.headers.age, startTime, firstByteTime));
}

@@ -188,4 +176,6 @@ }

clearTimeout(_this._timeoutTimer);
if (stats.aborted && !isTimeout) return;
if (_this._aborted && !isTimeout) return;
error = error instanceof NetError ? error : new NetError(url, request);
error.startTime = startTime;
error.endTime = Date.now();
error.isTimeout = isTimeout;

@@ -198,3 +188,4 @@ throw error;

value: function cancel() {
if (this._stats) this._stats.aborted = true;
if (this._aborted) return;
this._aborted = true;

@@ -201,0 +192,0 @@ if (this._xhr) {

export class GapService {
_prevCurrentTime: number;
do(media: any, maxJumpDistance: number, isLive: any): void;
do(media: any, maxJumpDistance: number, isLive: any, seekThreshold?: number): void;
}

@@ -18,2 +18,3 @@ import _classCallCheck from '@babel/runtime/helpers/classCallCheck';

var isLive = arguments.length > 2 ? arguments[2] : undefined;
var seekThreshold = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
if (!media) return;

@@ -29,3 +30,3 @@ var currentTime = media.currentTime;

jumpTo = info.nextStart + 0.1;
} else if (info.end && info.end - currentTime > 0.1 && !media.seeking) {
} else if (info.end && info.end - currentTime > seekThreshold && !media.seeking) {
jumpTo = currentTime + 0.1;

@@ -32,0 +33,0 @@ }

@@ -10,4 +10,14 @@ import 'core-js/modules/es.object.to-string.js';

});
promise.resolve = res;
promise.reject = rej;
promise.used = false;
promise.resolve = function () {
promise.used = true;
return res.apply(void 0, arguments);
};
promise.reject = function () {
promise.used = true;
return rej.apply(void 0, arguments);
};
return promise;

@@ -14,0 +24,0 @@ }

{
"name": "xgplayer-streaming-shared",
"version": "3.0.0-next.1",
"version": "3.0.0-next.2",
"main": "dist/index.min.js",

@@ -5,0 +5,0 @@ "module": "es/index.js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc