Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xgplayer-streaming-shared

Package Overview
Dependencies
Maintainers
4
Versions
206
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xgplayer-streaming-shared - npm Package Compare versions

Comparing version 3.0.0-alpha.5-14 to 3.0.0-alpha.5-15

3

es/net/fetch.js

@@ -99,5 +99,2 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';

this._vid = vid || url;
this._logger.debug('【fetchLoader task】, range', this._range);
var init = {

@@ -104,0 +101,0 @@ method: method,

2

es/net/speed-sampler.js

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

var durationSeconds = (this._now() - this._lastCheckpoint) / 1000;
if (durationSeconds == 0) durationSeconds = 1;
if (durationSeconds === 0) durationSeconds = 1;
return this._intervalBytes / durationSeconds / 1024;

@@ -82,0 +82,0 @@ }

@@ -47,9 +47,6 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';

_context.prev = 0;
_this._logger.debug('[task request ready to load]', rest.range);
_context.next = 4;
_context.next = 3;
return _this._loader.load(rest);
case 4:
case 3:
response = _context.sent;

@@ -59,7 +56,7 @@

_context.next = 29;
_context.next = 28;
break;
case 8:
_context.prev = 8;
case 7:
_context.prev = 7;
_context.t0 = _context["catch"](0);

@@ -71,3 +68,3 @@ _this._loader.running = false;

if (!_this._canceled) {
_context.next = 14;
_context.next = 13;
break;

@@ -78,5 +75,5 @@ }

case 14:
case 13:
if (!(_context.t0.response && _context.t0.response.status >= 400 && _context.t0.response.status <= 599)) {
_context.next = 17;
_context.next = 16;
break;

@@ -89,3 +86,3 @@ }

case 17:
case 16:
_context.t0.loaderType = _this._loaderType;

@@ -103,3 +100,3 @@ _context.t0.retryCount = _this._retryCount;

if (!(_this._retryCount <= retry)) {
_context.next = 28;
_context.next = 27;
break;

@@ -115,6 +112,6 @@ }

case 28:
case 27:
_this.promise.reject(error);
case 29:
case 28:
case "end":

@@ -124,3 +121,3 @@ return _context.stop();

}
}, _callee, null, [[0, 8]]);
}, _callee, null, [[0, 7]]);
}));

@@ -133,4 +130,2 @@

this._logger.debug('[task request start]', this._config.range);
request();

@@ -137,0 +132,0 @@ return this.promise;

@@ -19,3 +19,2 @@ export class XhrLoader {

_startTime: number;
_firstByteTime: number;
_speedSampler: SpeedSampler;

@@ -27,5 +26,13 @@ _loadCompleteResolve: any;

_vid: string;
_responseType: any;
_credentials: any;
_method: any;
_transformResponse: any;
_firstRtt: any;
_subRangeStartTime: any;
load(req: any): Promise<any>;
_openSubRange(): void;
_internalOpen(url: any, range: any): void;
_onTimeout: any;
_request: any;
_startLoad(): void;
_internalOpen(range: any): void;
_running: any;

@@ -32,0 +39,0 @@ _onReadyStatechange(e: any): void;

@@ -62,4 +62,2 @@ import 'core-js/modules/es.symbol.js';

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var SubRangeStartTime = -1;
var FirstRtt = -1;
var XhrLoader = /*#__PURE__*/function () {

@@ -103,4 +101,2 @@ function XhrLoader() {

_defineProperty(this, "_firstByteTime", -1);
_defineProperty(this, "_speedSampler", new SpeedSampler());

@@ -117,2 +113,14 @@

_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);
}

@@ -132,172 +140,62 @@

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('【xhrLoader task】, range', this._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,
index = req.index,
range = req.range,
request = req.request;
var isTimeout = false;
this._timeout = timeout || null;
this._runing = true;
this._vid = req.vid || url;
this._url = setUrlParams(url, params);
this._url = setUrlParams(req.url, req.params);
var startTime = Date.now();
return new Promise(function (resolve, reject) {
_this._loadCompleteResolve = resolve;
_this._loadCompleteReject = reject;
if (this._onProgress && range.length > 1 && range[1] && range[1] - range[0] > this._currentChunkSizeKB * 1024) {
this._logger.debug('【xhrLoader】, task', this._range, ', need to sub range');
_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;
SubRangeStartTime = startTime;
return new Promise(function (resolve, reject) {
_this._loadCompleteResolve = resolve;
_this._loadCompleteReject = reject;
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];
_this._openSubRange();
}).catch(function (error) {
clearTimeout(_this._timeoutTimer);
_this._runing = false;
if (_this._aborted) return;
error = error instanceof NetError ? error : new NetError(url, request);
error.startTime = startTime;
error.endTime = Date.now();
throw error;
});
} else {
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';
var rangeValue = getRangeValue(range);
var headers = null;
if (rangeValue) {
headers = _this._headers || {};
headers.Range = rangeValue;
if (chunkSize < this._range[1] - from) {
to = from + chunkSize;
}
if (headers) {
Object.keys(headers).forEach(function (k) {
xhr.setRequestHeader(k, headers[k]);
});
}
range = [from, to];
if (timeout) {
_this._timeoutTimer = setTimeout(function () {
isTimeout = true;
this._logger.debug('[xhr_loader->],tast :', this._range, ', SubRange, ', range);
} else {
range = this._range;
_this.cancel();
if (onTimeout) {
var error = new NetError(url, request);
error.isTimeout = true;
onTimeout(error);
}
}, timeout);
}
xhr.onerror = function (event) {
return reject(event);
};
xhr.onreadystatechange = function () {
if (xhr.readyState >= 2) {
clearTimeout(_this._timeoutTimer);
var firstByteTime = Date.now();
FirstRtt < 0 && (FirstRtt = firstByteTime);
if (xhr.readyState === 4) {
xhr.onreadystatechange = null;
if (_this._aborted) return;
var status = xhr.status;
var response = {
ok: status >= 200 && status < 300,
status: 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 (isArraybuffer) {
var costTime = Date.now() - startTime;
SpeedSampler.netSampling({
mTime: costTime,
mBytes: data.byteLength,
mSpeedInbPS: data.byteLength * 8 / (costTime / 1000),
mRTT: FirstRtt - startTime
});
}
if (onProgress) {
onProgress(isArraybuffer ? data : undefined, true, {
range: _this._range,
index: _this._index,
startTime: startTime,
endTime: Date.now()
}, response);
}
_this._runing = false;
resolve(createResponse(data, true, response, response.headers['content-length'], response.headers.age, startTime, firstByteTime, index, _this._range, _this._vid));
}
}
};
xhr.send(body);
}).catch(function (error) {
clearTimeout(_this._timeoutTimer);
_this._runing = false;
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;
});
this._logger.debug('[xhr_loader->],tast :', this._range, ', allRange, ', range);
}
}
}
}, {
key: "_openSubRange",
value: function _openSubRange() {
var chunkSize = this._currentChunkSizeKB * 1024;
var from = this._range[0] + this._receivedLength;
this._logger.debug('[xhr_loader->] ,tast: ', this._range, ',subRangeFrom ', from, ', currentReceivedLength, ', this._receivedLength);
var to = this._range[1];
if (chunkSize < this._range[1] - from) {
to = from + chunkSize;
}
var range = [from, to];
this._logger.debug('[xhr_loader->],tast :', this._range, ', SubRange, ', range);
this._internalOpen(this._url, range);
this._internalOpen(range);
}
}, {
key: "_internalOpen",
value: function _internalOpen(url, range) {
value: function _internalOpen(range) {
var _this2 = this;

@@ -308,6 +206,6 @@

var xhr = this._xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.open(this._method || 'GET', this._url, true);
xhr.responseType = this._responseType;
this._timeout && (xhr.timeout = this._timeout);
xhr.withCredentials = this._withCredentials;
xhr.withCredentials = this._credentials;
xhr.onload = this._onLoad.bind(this);

@@ -323,4 +221,11 @@ xhr.onreadystatechange = this._onReadyStatechange.bind(this);

xhr.ontimeout = function (event) {
_this2._running = false;
_this2.cancel();
if (_this2._onTimeout) {
var error = new NetError(_this2._url, _this2._request);
error.isTimeout = true;
_this2._onTimeout(error);
}
_this2._loadCompleteReject(event);

@@ -346,4 +251,4 @@ };

xhr.send();
} catch (error) {
throw error;
} catch (e) {
this._loadCompleteReject(e);
}

@@ -357,3 +262,3 @@ }

if (xhr.readyState === 2) {
FirstRtt < 0 && (FirstRtt = Date.now());
this._firstRtt < 0 && (this._firstRtt = Date.now());
}

@@ -392,21 +297,54 @@ }

var chunk = new Uint8Array(e.target.response);
if (this._firstByteTime) this._firstByteTime = Date.now();
var byteStart = this._range[0] + this._receivedLength;
this._receivedLength += chunk ? chunk.byteLength : 0;
var data = null;
var done = false;
var byteStart;
this._logger.debug('[xhr load done->], tast :', this._range, ', from', byteStart, 'end ', this._range[0] + this._receivedLength, ',dataLen,', chunk ? chunk.byteLength : 0, ',receivedLength', this._receivedLength);
if (this._responseType === ResponseType.ARRAY_BUFFER) {
var chunk = new Uint8Array(e.target.response);
byteStart = this._range[0] + this._receivedLength;
var reportComplete;
if (chunk && chunk.byteLength > 0) {
this._receivedLength += chunk.byteLength;
if (this._range.length > 1 && this._range[1] && this._receivedLength < this._range[1] - this._range[0]) {
reportComplete = false;
var costTime = Date.now() - this._subRangeStartTime;
this._speedSampler.addBytes(chunk.byteLength);
SpeedSampler.netSampling({
mTime: costTime,
mBytes: this._receivedLength,
mSpeedInbPS: this._receivedLength * 8 / (costTime / 1000),
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 {
reportComplete = true;
done = true;
data = e.target.response;
}
var response = {
ok: status >= 200 && status < 300,
status: 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._logger.debug('[xhr onDataArrivalCall],tast :', this._range, ',start, ', byteStart, ',end, ', this._range[0] + this._receivedLength, ',index,', this._index);
this._onProgress(chunk, reportComplete, {
this._onProgress(data, done, {
index: this._index,

@@ -417,30 +355,10 @@ vid: this._vid,

endTime: Date.now()
}, null);
}, response);
}
if (chunk && chunk.byteLength > 0) {
var costTime = Date.now() - SubRangeStartTime;
SpeedSampler.netSampling({
mTime: costTime,
mBytes: this._receivedLength,
mSpeedInbPS: this._receivedLength * 8 / (costTime / 1000),
mRTT: FirstRtt - SubRangeStartTime
});
}
if (!reportComplete) {
this._speedSampler.addBytes(chunk.byteLength);
this._openSubRange();
if (!done) {
this._startLoad();
} else {
this._runing = false;
var response = {
ok: status >= 200 && status < 300,
status: status,
statusText: this._xhr.statusText,
url: this._xhr.responseURL,
headers: this._getHeaders(this._xhr),
body: this._xhr.response
};
this._loadCompleteResolve && this._loadCompleteResolve(createResponse(null, true, response, response.headers['content-length'], response.headers.age, this._startTime, this._firstByteTime, this._index, this._range, this._vid));
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));
}

@@ -447,0 +365,0 @@ }

{
"name": "xgplayer-streaming-shared",
"version": "3.0.0-alpha.5-14",
"version": "3.0.0-alpha.5-15",
"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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc