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

xgplayer-streaming-shared

Package Overview
Dependencies
Maintainers
5
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-20 to 3.0.0-alpha.5-21

1

es/event.d.ts

@@ -30,2 +30,3 @@ export namespace EVENT {

const MAX_DTS_DELTA_WITH_NEXT_SEGMENT_DETECT: string;
const REAL_TIME_SPEED: string;
}

3

es/event.js

@@ -29,4 +29,5 @@ var EVENT = {

AUDIO_OVERLAP_DETECT: "AUDIO_OVERLAP_DETECT",
MAX_DTS_DELTA_WITH_NEXT_SEGMENT_DETECT: "MAX_DTS_DELTA_WITH_NEXT_SEGMENT_DETECT"
MAX_DTS_DELTA_WITH_NEXT_SEGMENT_DETECT: "MAX_DTS_DELTA_WITH_NEXT_SEGMENT_DETECT",
REAL_TIME_SPEED: "real_time_speed"
};
export { EVENT };

@@ -47,2 +47,3 @@ declare var _default: {

MAX_DTS_DELTA_WITH_NEXT_SEGMENT_DETECT: string;
REAL_TIME_SPEED: string;
};

@@ -49,0 +50,0 @@ ERR: {

@@ -15,3 +15,3 @@ export class FetchLoader {

_onProcessMinLen: number;
load({ url, vid, timeout, responseType, onProgress, index, onTimeout, range, transformResponse, request, params, logger, method, headers, body, mode, credentials, cache, redirect, referrer, referrerPolicy, onProcessMinLen, }: {
load({ url, vid, timeout, responseType, onProgress, index, onTimeout, range, transformResponse, request, params, logger, method, headers, body, mode, credentials, cache, redirect, referrer, referrerPolicy, onProcessMinLen }: {
url: any;

@@ -18,0 +18,0 @@ vid: any;

@@ -37,5 +37,6 @@ import { createClass as _createClass, classCallCheck as _classCallCheck, defineProperty as _defineProperty, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from "../_virtual/_rollupPluginBabelHelpers.js";

import { NetError } from "./error.js";
import { setUrlParams, getRangeValue, createResponse } from "./helper.js";
import { setUrlParams, getRangeValue, createResponse, calculateSpeed } from "./helper.js";
import { ResponseType } from "./types.js";
import SpeedSampler from "./speed-sampler.js";
import { EVENT } from "../event.js";
import EventEmitter from "event-emitter";
var CACHESIZE = 2 * 1024 * 1024;

@@ -57,2 +58,3 @@ var FetchLoader = /* @__PURE__ */ function() {

_defineProperty(this, "_onProcessMinLen", 0);
EventEmitter(this);
}

@@ -116,3 +118,3 @@ _createClass(FetchLoader2, [{

var _ref2 = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee(response) {
var firstByteTime, data, costTime;
var firstByteTime, data, costTime, speed;
return _regeneratorRuntime().wrap(function _callee$(_context) {

@@ -149,3 +151,3 @@ while (1) {

_this._running = false;
_context.next = 36;
_context.next = 37;
break;

@@ -162,3 +164,3 @@ case 15:

_this._running = false;
_context.next = 36;
_context.next = 37;
break;

@@ -182,12 +184,10 @@ case 22:

costTime = Date.now() - startTime;
SpeedSampler.netSampling({
mTime: costTime,
mBytes: data.byteLength,
mSpeedInbPS: data.byteLength * 8 / (costTime / 1e3),
mRTT: firstByteTime - startTime
speed = calculateSpeed(data.byteLength, costTime);
_this.emit(EVENT.REAL_TIME_SPEED, {
speed
});
case 36:
case 37:
_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 38:
case 39:
case "end":

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

var _ref3 = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee3() {
var startByte, curLen, retData, temp, costTime;
var startByte, curLen, retData, temp, costTime, speed;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {

@@ -368,8 +368,5 @@ while (1) {

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
speed = calculateSpeed(_this2._receivedLength, costTime);
_this2.emit(EVENT.REAL_TIME_SPEED, {
speed
});

@@ -376,0 +373,0 @@ if (!data.done) {

@@ -18,1 +18,2 @@ export function getRangeValue(value: any): string;

};
export function calculateSpeed(byteLen: any, millisec: any): any;

@@ -81,2 +81,5 @@ import "core-js/modules/es.regexp.exec.js";

}
export { createResponse, getRangeValue, setUrlParams };
function calculateSpeed(byteLen, millisec) {
return Math.round(byteLen * 8 * 1e3 / millisec);
}
export { calculateSpeed, createResponse, getRangeValue, setUrlParams };
export class NetLoader {
static isFetchSupport(): boolean;
static getSpeed(): number;
static getRealTimeSpeed(): number;
static getRTT(): any;
constructor(cfg: any);

@@ -7,0 +4,0 @@ type: string;

@@ -20,3 +20,4 @@ import { createClass as _createClass, classCallCheck as _classCallCheck, defineProperty as _defineProperty, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from "../_virtual/_rollupPluginBabelHelpers.js";

import { sleep } from "../streaming-helper.js";
import SpeedSampler from "./speed-sampler.js";
import { EVENT } from "../event.js";
import EventEmitter from "event-emitter";
var NetLoader = /* @__PURE__ */ function() {

@@ -29,2 +30,3 @@ function NetLoader2(cfg) {

_defineProperty(this, "_currentTask", null);
EventEmitter(this);
this._config = getConfig(cfg);

@@ -44,2 +46,3 @@ if (this._config.loaderType === LoaderType.XHR || !FetchLoader.isSupported()) {

value: function load(url) {
var _this = this;
var config = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};

@@ -63,2 +66,5 @@ if (typeof url === "string" || !url) {

var task = new Task(this.type, config);
task.loader.on(EVENT.REAL_TIME_SPEED, function(data) {
_this.emit(EVENT.REAL_TIME_SPEED, data);
});
this._queue.push(task);

@@ -109,3 +115,3 @@ if (this._queue.length === 1 && (!this._currentTask || !this._currentTask.running)) {

value: function _processTask() {
var _this = this;
var _this2 = this;
this._currentTask = this._queue.shift();

@@ -119,3 +125,3 @@ if (!this._currentTask)

}).finally(function() {
_this._processTask();
_this2._processTask();
});

@@ -128,17 +134,2 @@ }

}
}, {
key: "getSpeed",
value: function getSpeed() {
return SpeedSampler.getSpeed();
}
}, {
key: "getRealTimeSpeed",
value: function getRealTimeSpeed() {
return SpeedSampler.getRealTimeSpeed();
}
}, {
key: "getRTT",
value: function getRTT() {
return SpeedSampler.getRTT();
}
}]);

@@ -145,0 +136,0 @@ return NetLoader2;

@@ -15,4 +15,5 @@ export class Task {

get running(): any;
get loader(): FetchLoader | XhrLoader;
}
import { FetchLoader } from "./fetch";
import { XhrLoader } from "./xhr";

@@ -122,2 +122,7 @@ import { createClass as _createClass, objectWithoutProperties as _objectWithoutProperties, classCallCheck as _classCallCheck, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from "../_virtual/_rollupPluginBabelHelpers.js";

}
}, {
key: "loader",
get: function get() {
return this._loader;
}
}]);

@@ -124,0 +129,0 @@ return Task2;

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

_headers: any;
_chunkSizeKBList: number[];
_currentChunkSizeKB: number;

@@ -20,3 +19,2 @@ _currentSpeedNormalized: number;

_startTime: number;
_speedSampler: SpeedSampler;
_loadCompleteResolve: any;

@@ -41,3 +39,2 @@ _loadCompleteReject: any;

_onLoad(e: any): any;
_normalizeSpeed(input: any): any;
cancel(): any;

@@ -49,2 +46,1 @@ get receiveLen(): number;

}
import SpeedSampler from "./speed-sampler";

@@ -41,5 +41,6 @@ import { createClass as _createClass, objectSpread2 as _objectSpread2, createForOfIteratorHelper as _createForOfIteratorHelper, classCallCheck as _classCallCheck, defineProperty as _defineProperty } from "../_virtual/_rollupPluginBabelHelpers.js";

import { NetError } from "./error.js";
import { setUrlParams, getRangeValue, createResponse } from "./helper.js";
import { setUrlParams, getRangeValue, calculateSpeed, createResponse } from "./helper.js";
import { ResponseType } from "./types.js";
import SpeedSampler from "./speed-sampler.js";
import { EVENT } from "../event.js";
import EventEmitter from "event-emitter";
var XhrLoader = /* @__PURE__ */ function() {

@@ -57,3 +58,2 @@ function XhrLoader2() {

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

@@ -66,3 +66,2 @@ _defineProperty(this, "_currentSpeedNormalized", 0);

_defineProperty(this, "_startTime", -1);
_defineProperty(this, "_speedSampler", new SpeedSampler());
_defineProperty(this, "_loadCompleteResolve", null);

@@ -79,2 +78,3 @@ _defineProperty(this, "_loadCompleteReject", null);

_defineProperty(this, "_subRangeStartTime", void 0);
EventEmitter(this);
}

@@ -201,16 +201,2 @@ _createClass(XhrLoader2, [{

}
var KBps = this._speedSampler.lastSecondKBps;
if (KBps === 0) {
this._zeroSpeedChunkCount++;
if (this._zeroSpeedChunkCount >= 3) {
KBps = this._speedSampler.currentKBps;
}
}
if (KBps !== 0) {
var normalized = this._normalizeSpeed(KBps);
if (this._currentSpeedNormalized !== normalized) {
this._currentSpeedNormalized = normalized;
this._currentChunkSizeKB = normalized;
}
}
var data = null;

@@ -225,8 +211,5 @@ var done = false;

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
var speed = calculateSpeed(this._receivedLength, costTime);
this.emit(EVENT.REAL_TIME_SPEED, {
speed
});

@@ -273,24 +256,2 @@ }

}, {
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",

@@ -297,0 +258,0 @@ value: function cancel() {

{
"name": "xgplayer-streaming-shared",
"version": "3.0.0-alpha.5-20",
"version": "3.0.0-alpha.5-21",
"main": "dist/index.min.js",

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

"license": "MIT",
"dependencies": {
"event-emitter": "^0.3.5"
},
"unpkgFiles": [

@@ -23,0 +26,0 @@ "dist"

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