Tracking de l'application VApp (IHM du jeu)
This commit is contained in:
62
VApp/node_modules/@videojs/xhr/lib/http-handler.js
generated
vendored
Normal file
62
VApp/node_modules/@videojs/xhr/lib/http-handler.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
"use strict";
|
||||
|
||||
var window = require('global/window');
|
||||
|
||||
var httpResponseHandler = function httpResponseHandler(callback, decodeResponseBody) {
|
||||
if (decodeResponseBody === void 0) {
|
||||
decodeResponseBody = false;
|
||||
}
|
||||
|
||||
return function (err, response, responseBody) {
|
||||
// if the XHR failed, return that error
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
} // if the HTTP status code is 4xx or 5xx, the request also failed
|
||||
|
||||
|
||||
if (response.statusCode >= 400 && response.statusCode <= 599) {
|
||||
var cause = responseBody;
|
||||
|
||||
if (decodeResponseBody) {
|
||||
if (window.TextDecoder) {
|
||||
var charset = getCharset(response.headers && response.headers['content-type']);
|
||||
|
||||
try {
|
||||
cause = new TextDecoder(charset).decode(responseBody);
|
||||
} catch (e) {}
|
||||
} else {
|
||||
cause = String.fromCharCode.apply(null, new Uint8Array(responseBody));
|
||||
}
|
||||
}
|
||||
|
||||
callback({
|
||||
cause: cause
|
||||
});
|
||||
return;
|
||||
} // otherwise, request succeeded
|
||||
|
||||
|
||||
callback(null, responseBody);
|
||||
};
|
||||
};
|
||||
|
||||
function getCharset(contentTypeHeader) {
|
||||
if (contentTypeHeader === void 0) {
|
||||
contentTypeHeader = '';
|
||||
}
|
||||
|
||||
return contentTypeHeader.toLowerCase().split(';').reduce(function (charset, contentType) {
|
||||
var _contentType$split = contentType.split('='),
|
||||
type = _contentType$split[0],
|
||||
value = _contentType$split[1];
|
||||
|
||||
if (type.trim() === 'charset') {
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
return charset;
|
||||
}, 'utf-8');
|
||||
}
|
||||
|
||||
module.exports = httpResponseHandler;
|
369
VApp/node_modules/@videojs/xhr/lib/index.js
generated
vendored
Normal file
369
VApp/node_modules/@videojs/xhr/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,369 @@
|
||||
"use strict";
|
||||
|
||||
var window = require("global/window");
|
||||
|
||||
var _extends = require("@babel/runtime/helpers/extends");
|
||||
|
||||
var isFunction = require('is-function');
|
||||
|
||||
var InterceptorsStorage = require('./interceptors.js');
|
||||
|
||||
var RetryManager = require("./retry.js");
|
||||
|
||||
createXHR.httpHandler = require('./http-handler.js');
|
||||
createXHR.requestInterceptorsStorage = new InterceptorsStorage();
|
||||
createXHR.responseInterceptorsStorage = new InterceptorsStorage();
|
||||
createXHR.retryManager = new RetryManager();
|
||||
/**
|
||||
* @license
|
||||
* slighly modified parse-headers 2.0.2 <https://github.com/kesla/parse-headers/>
|
||||
* Copyright (c) 2014 David Björklund
|
||||
* Available under the MIT license
|
||||
* <https://github.com/kesla/parse-headers/blob/master/LICENCE>
|
||||
*/
|
||||
|
||||
var parseHeaders = function parseHeaders(headers) {
|
||||
var result = {};
|
||||
|
||||
if (!headers) {
|
||||
return result;
|
||||
}
|
||||
|
||||
headers.trim().split('\n').forEach(function (row) {
|
||||
var index = row.indexOf(':');
|
||||
var key = row.slice(0, index).trim().toLowerCase();
|
||||
var value = row.slice(index + 1).trim();
|
||||
|
||||
if (typeof result[key] === 'undefined') {
|
||||
result[key] = value;
|
||||
} else if (Array.isArray(result[key])) {
|
||||
result[key].push(value);
|
||||
} else {
|
||||
result[key] = [result[key], value];
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = createXHR; // Allow use of default import syntax in TypeScript
|
||||
|
||||
module.exports.default = createXHR;
|
||||
createXHR.XMLHttpRequest = window.XMLHttpRequest || noop;
|
||||
createXHR.XDomainRequest = "withCredentials" in new createXHR.XMLHttpRequest() ? createXHR.XMLHttpRequest : window.XDomainRequest;
|
||||
forEachArray(["get", "put", "post", "patch", "head", "delete"], function (method) {
|
||||
createXHR[method === "delete" ? "del" : method] = function (uri, options, callback) {
|
||||
options = initParams(uri, options, callback);
|
||||
options.method = method.toUpperCase();
|
||||
return _createXHR(options);
|
||||
};
|
||||
});
|
||||
|
||||
function forEachArray(array, iterator) {
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
iterator(array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function isEmpty(obj) {
|
||||
for (var i in obj) {
|
||||
if (obj.hasOwnProperty(i)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function initParams(uri, options, callback) {
|
||||
var params = uri;
|
||||
|
||||
if (isFunction(options)) {
|
||||
callback = options;
|
||||
|
||||
if (typeof uri === "string") {
|
||||
params = {
|
||||
uri: uri
|
||||
};
|
||||
}
|
||||
} else {
|
||||
params = _extends({}, options, {
|
||||
uri: uri
|
||||
});
|
||||
}
|
||||
|
||||
params.callback = callback;
|
||||
return params;
|
||||
}
|
||||
|
||||
function createXHR(uri, options, callback) {
|
||||
options = initParams(uri, options, callback);
|
||||
return _createXHR(options);
|
||||
}
|
||||
|
||||
function _createXHR(options) {
|
||||
if (typeof options.callback === "undefined") {
|
||||
throw new Error("callback argument missing");
|
||||
} // call all registered request interceptors for a given request type:
|
||||
|
||||
|
||||
if (options.requestType && createXHR.requestInterceptorsStorage.getIsEnabled()) {
|
||||
var requestInterceptorPayload = {
|
||||
uri: options.uri || options.url,
|
||||
headers: options.headers || {},
|
||||
body: options.body,
|
||||
metadata: options.metadata || {},
|
||||
retry: options.retry,
|
||||
timeout: options.timeout
|
||||
};
|
||||
var updatedPayload = createXHR.requestInterceptorsStorage.execute(options.requestType, requestInterceptorPayload);
|
||||
options.uri = updatedPayload.uri;
|
||||
options.headers = updatedPayload.headers;
|
||||
options.body = updatedPayload.body;
|
||||
options.metadata = updatedPayload.metadata;
|
||||
options.retry = updatedPayload.retry;
|
||||
options.timeout = updatedPayload.timeout;
|
||||
}
|
||||
|
||||
var called = false;
|
||||
|
||||
var callback = function cbOnce(err, response, body) {
|
||||
if (!called) {
|
||||
called = true;
|
||||
options.callback(err, response, body);
|
||||
}
|
||||
};
|
||||
|
||||
function readystatechange() {
|
||||
// do not call load 2 times when response interceptors are enabled
|
||||
// why do we even need this 2nd load?
|
||||
if (xhr.readyState === 4 && !createXHR.responseInterceptorsStorage.getIsEnabled()) {
|
||||
setTimeout(loadFunc, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function getBody() {
|
||||
// Chrome with requestType=blob throws errors arround when even testing access to responseText
|
||||
var body = undefined;
|
||||
|
||||
if (xhr.response) {
|
||||
body = xhr.response;
|
||||
} else {
|
||||
body = xhr.responseText || getXml(xhr);
|
||||
}
|
||||
|
||||
if (isJson) {
|
||||
try {
|
||||
body = JSON.parse(body);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
function errorFunc(evt) {
|
||||
clearTimeout(timeoutTimer);
|
||||
clearTimeout(options.retryTimeout);
|
||||
|
||||
if (!(evt instanceof Error)) {
|
||||
evt = new Error("" + (evt || "Unknown XMLHttpRequest Error"));
|
||||
}
|
||||
|
||||
evt.statusCode = 0; // we would like to retry on error:
|
||||
|
||||
if (!aborted && createXHR.retryManager.getIsEnabled() && options.retry && options.retry.shouldRetry()) {
|
||||
options.retryTimeout = setTimeout(function () {
|
||||
options.retry.moveToNextAttempt(); // we want to re-use the same options and the same xhr object:
|
||||
|
||||
options.xhr = xhr;
|
||||
|
||||
_createXHR(options);
|
||||
}, options.retry.getCurrentFuzzedDelay());
|
||||
return;
|
||||
} // call all registered response interceptors for a given request type:
|
||||
|
||||
|
||||
if (options.requestType && createXHR.responseInterceptorsStorage.getIsEnabled()) {
|
||||
var responseInterceptorPayload = {
|
||||
headers: failureResponse.headers || {},
|
||||
body: failureResponse.body,
|
||||
responseUrl: xhr.responseURL,
|
||||
responseType: xhr.responseType
|
||||
};
|
||||
|
||||
var _updatedPayload = createXHR.responseInterceptorsStorage.execute(options.requestType, responseInterceptorPayload);
|
||||
|
||||
failureResponse.body = _updatedPayload.body;
|
||||
failureResponse.headers = _updatedPayload.headers;
|
||||
}
|
||||
|
||||
return callback(evt, failureResponse);
|
||||
} // will load the data & process the response in a special response object
|
||||
|
||||
|
||||
function loadFunc() {
|
||||
if (aborted) return;
|
||||
var status;
|
||||
clearTimeout(timeoutTimer);
|
||||
clearTimeout(options.retryTimeout);
|
||||
|
||||
if (options.useXDR && xhr.status === undefined) {
|
||||
//IE8 CORS GET successful response doesn't have a status field, but body is fine
|
||||
status = 200;
|
||||
} else {
|
||||
status = xhr.status === 1223 ? 204 : xhr.status;
|
||||
}
|
||||
|
||||
var response = failureResponse;
|
||||
var err = null;
|
||||
|
||||
if (status !== 0) {
|
||||
response = {
|
||||
body: getBody(),
|
||||
statusCode: status,
|
||||
method: method,
|
||||
headers: {},
|
||||
url: uri,
|
||||
rawRequest: xhr
|
||||
};
|
||||
|
||||
if (xhr.getAllResponseHeaders) {
|
||||
//remember xhr can in fact be XDR for CORS in IE
|
||||
response.headers = parseHeaders(xhr.getAllResponseHeaders());
|
||||
}
|
||||
} else {
|
||||
err = new Error("Internal XMLHttpRequest Error");
|
||||
} // call all registered response interceptors for a given request type:
|
||||
|
||||
|
||||
if (options.requestType && createXHR.responseInterceptorsStorage.getIsEnabled()) {
|
||||
var responseInterceptorPayload = {
|
||||
headers: response.headers || {},
|
||||
body: response.body,
|
||||
responseUrl: xhr.responseURL,
|
||||
responseType: xhr.responseType
|
||||
};
|
||||
|
||||
var _updatedPayload2 = createXHR.responseInterceptorsStorage.execute(options.requestType, responseInterceptorPayload);
|
||||
|
||||
response.body = _updatedPayload2.body;
|
||||
response.headers = _updatedPayload2.headers;
|
||||
}
|
||||
|
||||
return callback(err, response, response.body);
|
||||
}
|
||||
|
||||
var xhr = options.xhr || null;
|
||||
|
||||
if (!xhr) {
|
||||
if (options.cors || options.useXDR) {
|
||||
xhr = new createXHR.XDomainRequest();
|
||||
} else {
|
||||
xhr = new createXHR.XMLHttpRequest();
|
||||
}
|
||||
}
|
||||
|
||||
var key;
|
||||
var aborted;
|
||||
var uri = xhr.url = options.uri || options.url;
|
||||
var method = xhr.method = options.method || "GET";
|
||||
var body = options.body || options.data;
|
||||
var headers = xhr.headers = options.headers || {};
|
||||
var sync = !!options.sync;
|
||||
var isJson = false;
|
||||
var timeoutTimer;
|
||||
var failureResponse = {
|
||||
body: undefined,
|
||||
headers: {},
|
||||
statusCode: 0,
|
||||
method: method,
|
||||
url: uri,
|
||||
rawRequest: xhr
|
||||
};
|
||||
|
||||
if ("json" in options && options.json !== false) {
|
||||
isJson = true;
|
||||
headers["accept"] || headers["Accept"] || (headers["Accept"] = "application/json"); //Don't override existing accept header declared by user
|
||||
|
||||
if (method !== "GET" && method !== "HEAD") {
|
||||
headers["content-type"] || headers["Content-Type"] || (headers["Content-Type"] = "application/json"); //Don't override existing accept header declared by user
|
||||
|
||||
body = JSON.stringify(options.json === true ? body : options.json);
|
||||
}
|
||||
}
|
||||
|
||||
xhr.onreadystatechange = readystatechange;
|
||||
xhr.onload = loadFunc;
|
||||
xhr.onerror = errorFunc; // IE9 must have onprogress be set to a unique function.
|
||||
|
||||
xhr.onprogress = function () {// IE must die
|
||||
};
|
||||
|
||||
xhr.onabort = function () {
|
||||
aborted = true;
|
||||
clearTimeout(options.retryTimeout);
|
||||
};
|
||||
|
||||
xhr.ontimeout = errorFunc;
|
||||
xhr.open(method, uri, !sync, options.username, options.password); //has to be after open
|
||||
|
||||
if (!sync) {
|
||||
xhr.withCredentials = !!options.withCredentials;
|
||||
} // Cannot set timeout with sync request
|
||||
// not setting timeout on the xhr object, because of old webkits etc. not handling that correctly
|
||||
// both npm's request and jquery 1.x use this kind of timeout, so this is being consistent
|
||||
|
||||
|
||||
if (!sync && options.timeout > 0) {
|
||||
timeoutTimer = setTimeout(function () {
|
||||
if (aborted) return;
|
||||
aborted = true; //IE9 may still call readystatechange
|
||||
|
||||
xhr.abort("timeout");
|
||||
var e = new Error("XMLHttpRequest timeout");
|
||||
e.code = "ETIMEDOUT";
|
||||
errorFunc(e);
|
||||
}, options.timeout);
|
||||
}
|
||||
|
||||
if (xhr.setRequestHeader) {
|
||||
for (key in headers) {
|
||||
if (headers.hasOwnProperty(key)) {
|
||||
xhr.setRequestHeader(key, headers[key]);
|
||||
}
|
||||
}
|
||||
} else if (options.headers && !isEmpty(options.headers)) {
|
||||
throw new Error("Headers cannot be set on an XDomainRequest object");
|
||||
}
|
||||
|
||||
if ("responseType" in options) {
|
||||
xhr.responseType = options.responseType;
|
||||
}
|
||||
|
||||
if ("beforeSend" in options && typeof options.beforeSend === "function") {
|
||||
options.beforeSend(xhr);
|
||||
} // Microsoft Edge browser sends "undefined" when send is called with undefined value.
|
||||
// XMLHttpRequest spec says to pass null as body to indicate no body
|
||||
// See https://github.com/naugtur/xhr/issues/100.
|
||||
|
||||
|
||||
xhr.send(body || null);
|
||||
return xhr;
|
||||
}
|
||||
|
||||
function getXml(xhr) {
|
||||
// xhr.responseXML will throw Exception "InvalidStateError" or "DOMException"
|
||||
// See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseXML.
|
||||
try {
|
||||
if (xhr.responseType === "document") {
|
||||
return xhr.responseXML;
|
||||
}
|
||||
|
||||
var firefoxBugTakenEffect = xhr.responseXML && xhr.responseXML.documentElement.nodeName === "parsererror";
|
||||
|
||||
if (xhr.responseType === "" && !firefoxBugTakenEffect) {
|
||||
return xhr.responseXML;
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function noop() {}
|
104
VApp/node_modules/@videojs/xhr/lib/interceptors.js
generated
vendored
Normal file
104
VApp/node_modules/@videojs/xhr/lib/interceptors.js
generated
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
"use strict";
|
||||
|
||||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||
|
||||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
||||
|
||||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
||||
|
||||
var InterceptorsStorage = /*#__PURE__*/function () {
|
||||
function InterceptorsStorage() {
|
||||
this.typeToInterceptorsMap_ = new Map();
|
||||
this.enabled_ = false;
|
||||
}
|
||||
|
||||
var _proto = InterceptorsStorage.prototype;
|
||||
|
||||
_proto.getIsEnabled = function getIsEnabled() {
|
||||
return this.enabled_;
|
||||
};
|
||||
|
||||
_proto.enable = function enable() {
|
||||
this.enabled_ = true;
|
||||
};
|
||||
|
||||
_proto.disable = function disable() {
|
||||
this.enabled_ = false;
|
||||
};
|
||||
|
||||
_proto.reset = function reset() {
|
||||
this.typeToInterceptorsMap_ = new Map();
|
||||
this.enabled_ = false;
|
||||
};
|
||||
|
||||
_proto.addInterceptor = function addInterceptor(type, interceptor) {
|
||||
if (!this.typeToInterceptorsMap_.has(type)) {
|
||||
this.typeToInterceptorsMap_.set(type, new Set());
|
||||
}
|
||||
|
||||
var interceptorsSet = this.typeToInterceptorsMap_.get(type);
|
||||
|
||||
if (interceptorsSet.has(interceptor)) {
|
||||
// already have this interceptor
|
||||
return false;
|
||||
}
|
||||
|
||||
interceptorsSet.add(interceptor);
|
||||
return true;
|
||||
};
|
||||
|
||||
_proto.removeInterceptor = function removeInterceptor(type, interceptor) {
|
||||
var interceptorsSet = this.typeToInterceptorsMap_.get(type);
|
||||
|
||||
if (interceptorsSet && interceptorsSet.has(interceptor)) {
|
||||
interceptorsSet.delete(interceptor);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
_proto.clearInterceptorsByType = function clearInterceptorsByType(type) {
|
||||
var interceptorsSet = this.typeToInterceptorsMap_.get(type);
|
||||
|
||||
if (!interceptorsSet) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.typeToInterceptorsMap_.delete(type);
|
||||
this.typeToInterceptorsMap_.set(type, new Set());
|
||||
return true;
|
||||
};
|
||||
|
||||
_proto.clear = function clear() {
|
||||
if (!this.typeToInterceptorsMap_.size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.typeToInterceptorsMap_ = new Map();
|
||||
return true;
|
||||
};
|
||||
|
||||
_proto.getForType = function getForType(type) {
|
||||
return this.typeToInterceptorsMap_.get(type) || new Set();
|
||||
};
|
||||
|
||||
_proto.execute = function execute(type, payload) {
|
||||
var interceptors = this.getForType(type);
|
||||
|
||||
for (var _iterator = _createForOfIteratorHelperLoose(interceptors), _step; !(_step = _iterator()).done;) {
|
||||
var interceptor = _step.value;
|
||||
|
||||
try {
|
||||
payload = interceptor(payload);
|
||||
} catch (e) {//ignore
|
||||
}
|
||||
}
|
||||
|
||||
return payload;
|
||||
};
|
||||
|
||||
return InterceptorsStorage;
|
||||
}();
|
||||
|
||||
module.exports = InterceptorsStorage;
|
133
VApp/node_modules/@videojs/xhr/lib/retry.js
generated
vendored
Normal file
133
VApp/node_modules/@videojs/xhr/lib/retry.js
generated
vendored
Normal file
@ -0,0 +1,133 @@
|
||||
"use strict";
|
||||
|
||||
var RetryManager = /*#__PURE__*/function () {
|
||||
function RetryManager() {
|
||||
this.maxAttempts_ = 1;
|
||||
this.delayFactor_ = 0.1;
|
||||
this.fuzzFactor_ = 0.1;
|
||||
this.initialDelay_ = 1000;
|
||||
this.enabled_ = false;
|
||||
}
|
||||
|
||||
var _proto = RetryManager.prototype;
|
||||
|
||||
_proto.getIsEnabled = function getIsEnabled() {
|
||||
return this.enabled_;
|
||||
};
|
||||
|
||||
_proto.enable = function enable() {
|
||||
this.enabled_ = true;
|
||||
};
|
||||
|
||||
_proto.disable = function disable() {
|
||||
this.enabled_ = false;
|
||||
};
|
||||
|
||||
_proto.reset = function reset() {
|
||||
this.maxAttempts_ = 1;
|
||||
this.delayFactor_ = 0.1;
|
||||
this.fuzzFactor_ = 0.1;
|
||||
this.initialDelay_ = 1000;
|
||||
this.enabled_ = false;
|
||||
};
|
||||
|
||||
_proto.getMaxAttempts = function getMaxAttempts() {
|
||||
return this.maxAttempts_;
|
||||
};
|
||||
|
||||
_proto.setMaxAttempts = function setMaxAttempts(maxAttempts) {
|
||||
this.maxAttempts_ = maxAttempts;
|
||||
};
|
||||
|
||||
_proto.getDelayFactor = function getDelayFactor() {
|
||||
return this.delayFactor_;
|
||||
};
|
||||
|
||||
_proto.setDelayFactor = function setDelayFactor(delayFactor) {
|
||||
this.delayFactor_ = delayFactor;
|
||||
};
|
||||
|
||||
_proto.getFuzzFactor = function getFuzzFactor() {
|
||||
return this.fuzzFactor_;
|
||||
};
|
||||
|
||||
_proto.setFuzzFactor = function setFuzzFactor(fuzzFactor) {
|
||||
this.fuzzFactor_ = fuzzFactor;
|
||||
};
|
||||
|
||||
_proto.getInitialDelay = function getInitialDelay() {
|
||||
return this.initialDelay_;
|
||||
};
|
||||
|
||||
_proto.setInitialDelay = function setInitialDelay(initialDelay) {
|
||||
this.initialDelay_ = initialDelay;
|
||||
};
|
||||
|
||||
_proto.createRetry = function createRetry(_temp) {
|
||||
var _ref = _temp === void 0 ? {} : _temp,
|
||||
maxAttempts = _ref.maxAttempts,
|
||||
delayFactor = _ref.delayFactor,
|
||||
fuzzFactor = _ref.fuzzFactor,
|
||||
initialDelay = _ref.initialDelay;
|
||||
|
||||
return new Retry({
|
||||
maxAttempts: maxAttempts || this.maxAttempts_,
|
||||
delayFactor: delayFactor || this.delayFactor_,
|
||||
fuzzFactor: fuzzFactor || this.fuzzFactor_,
|
||||
initialDelay: initialDelay || this.initialDelay_
|
||||
});
|
||||
};
|
||||
|
||||
return RetryManager;
|
||||
}();
|
||||
|
||||
var Retry = /*#__PURE__*/function () {
|
||||
function Retry(options) {
|
||||
this.maxAttempts_ = options.maxAttempts;
|
||||
this.delayFactor_ = options.delayFactor;
|
||||
this.fuzzFactor_ = options.fuzzFactor;
|
||||
this.currentDelay_ = options.initialDelay;
|
||||
this.currentAttempt_ = 1;
|
||||
}
|
||||
|
||||
var _proto2 = Retry.prototype;
|
||||
|
||||
_proto2.moveToNextAttempt = function moveToNextAttempt() {
|
||||
this.currentAttempt_++;
|
||||
var delayDelta = this.currentDelay_ * this.delayFactor_;
|
||||
this.currentDelay_ = this.currentDelay_ + delayDelta;
|
||||
};
|
||||
|
||||
_proto2.shouldRetry = function shouldRetry() {
|
||||
return this.currentAttempt_ < this.maxAttempts_;
|
||||
};
|
||||
|
||||
_proto2.getCurrentDelay = function getCurrentDelay() {
|
||||
return this.currentDelay_;
|
||||
};
|
||||
|
||||
_proto2.getCurrentMinPossibleDelay = function getCurrentMinPossibleDelay() {
|
||||
return (1 - this.fuzzFactor_) * this.currentDelay_;
|
||||
};
|
||||
|
||||
_proto2.getCurrentMaxPossibleDelay = function getCurrentMaxPossibleDelay() {
|
||||
return (1 + this.fuzzFactor_) * this.currentDelay_;
|
||||
}
|
||||
/**
|
||||
* For example fuzzFactor is 0.1
|
||||
* This means ±10% deviation
|
||||
* So if we have delay as 1000
|
||||
* This function can generate any value from 900 to 1100
|
||||
*/
|
||||
;
|
||||
|
||||
_proto2.getCurrentFuzzedDelay = function getCurrentFuzzedDelay() {
|
||||
var lowValue = this.getCurrentMinPossibleDelay();
|
||||
var highValue = this.getCurrentMaxPossibleDelay();
|
||||
return lowValue + Math.random() * (highValue - lowValue);
|
||||
};
|
||||
|
||||
return Retry;
|
||||
}();
|
||||
|
||||
module.exports = RetryManager;
|
Reference in New Issue
Block a user