agora-foundation 3.8.1 → 3.9.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/decorator/log/handler.d.ts +1 -1
- package/lib/decorator/log/handler.js +57 -64
- package/lib/decorator/log/index.d.ts +26 -1
- package/lib/decorator/log/index.js +50 -5
- package/lib/decorator/log/log-serializer.d.ts +1 -1
- package/lib/decorator/log/log-serializer.js +15 -2
- package/lib/decorator/proxy.d.ts +1 -1
- package/lib/decorator/proxy.js +16 -16
- package/lib/decorator/type.d.ts +3 -2
- package/lib/decorator/type.js +2 -2
- package/lib/utilities/desc-type.d.ts +1 -0
- package/lib/utilities/desc-type.js +1 -1
- package/lib/utilities/env.d.ts +2 -1
- package/lib/utilities/env.js +1 -0
- package/lib/utilities/{agora-error.d.ts → error/agora-error.d.ts} +5 -11
- package/lib/utilities/error/agora-error.js +148 -0
- package/lib/utilities/error/error-code.d.ts +69 -0
- package/lib/utilities/error/error-code.js +81 -0
- package/lib/utilities/logger.d.ts +13 -1
- package/lib/utilities/logger.js +103 -13
- package/lib/utilities/observable.js +1 -0
- package/lib/utilities/package-info.d.ts +8 -0
- package/lib/utilities/package-info.js +85 -0
- package/lib/utilities/regex.d.ts +1 -0
- package/lib/utilities/regex.js +14 -0
- package/lib/utilities/tools.d.ts +28 -0
- package/lib/utilities/tools.js +154 -0
- package/lib/worker/worker-factory.js +22 -1
- package/lib-es/decorator/bound/index.js +12 -0
- package/lib-es/decorator/index.js +4 -0
- package/lib-es/decorator/lodash/index.js +34 -0
- package/lib-es/decorator/log/handler.js +71 -0
- package/lib-es/decorator/log/index.js +73 -0
- package/lib-es/decorator/log/log-serializer.js +28 -0
- package/lib-es/decorator/proxy.js +149 -0
- package/lib-es/decorator/type.js +7 -0
- package/lib-es/decorator/validate/index.js +32 -0
- package/lib-es/logger/common.js +45 -0
- package/lib-es/logger/constants.js +3 -0
- package/lib-es/logger/hijack.js +61 -0
- package/lib-es/logger/index.js +52 -0
- package/lib-es/logger/logger-impl.js +122 -0
- package/lib-es/logger/manager-impl.js +63 -0
- package/lib-es/logger/type.js +7 -0
- package/lib-es/restful-scheduler/scheduler.js +224 -0
- package/lib-es/schedule/index.js +3 -0
- package/lib-es/schedule/scheduler.js +102 -0
- package/lib-es/schedule/task.js +159 -0
- package/lib-es/upload/index.js +1 -0
- package/lib-es/upload/scheduler.js +145 -0
- package/lib-es/upload/type.js +1 -0
- package/lib-es/utilities/async-retry.js +177 -0
- package/lib-es/utilities/browser.js +20 -0
- package/lib-es/utilities/desc-type.js +3 -0
- package/lib-es/utilities/env.js +55 -0
- package/lib-es/utilities/error/agora-error.js +140 -0
- package/lib-es/utilities/error/error-code.js +74 -0
- package/lib-es/utilities/events.js +125 -0
- package/lib-es/utilities/file-reader.js +15 -0
- package/lib-es/utilities/interceptor.js +23 -0
- package/lib-es/utilities/logger.js +109 -0
- package/lib-es/utilities/misc.js +74 -0
- package/lib-es/utilities/observable.js +97 -0
- package/lib-es/utilities/package-info.js +78 -0
- package/lib-es/utilities/race-condition.js +17 -0
- package/lib-es/utilities/regex.js +7 -0
- package/lib-es/utilities/safely-remove-child.js +29 -0
- package/lib-es/utilities/schema.js +36 -0
- package/lib-es/utilities/tools.js +144 -0
- package/lib-es/utilities/value-check.js +3 -0
- package/lib-es/utilities/zip.js +200 -0
- package/lib-es/worker/constants.js +13 -0
- package/lib-es/worker/handler/binary.js +157 -0
- package/lib-es/worker/handler/db.js +34 -0
- package/lib-es/worker/handler/fs-log.js +149 -0
- package/lib-es/worker/handler/log-rotate-new.js +230 -0
- package/lib-es/worker/handler/log-rotate.js +80 -0
- package/lib-es/worker/handler/log.js +291 -0
- package/lib-es/worker/handler/reply.js +15 -0
- package/lib-es/worker/index.js +8 -0
- package/lib-es/worker/interactor.js +435 -0
- package/lib-es/worker/mutex.js +57 -0
- package/lib-es/worker/type.js +1 -0
- package/lib-es/worker/worker-entry.js +3 -0
- package/lib-es/worker/worker-factory.js +15 -0
- package/lib-es/worker/worker-installer.js +71 -0
- package/package.json +8 -4
- package/lib/utilities/agora-error.js +0 -128
- package/lib/worker/545.worker-factory.js +0 -1
- package/lib/worker/847.worker-factory.js +0 -2
- package/lib/worker/847.worker-factory.js.LICENSE.txt +0 -24
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
5
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
|
+
import "core-js/modules/es.error.cause.js";
|
|
7
|
+
import "core-js/modules/es.error.to-string.js";
|
|
8
|
+
import "core-js/modules/es.object.to-string.js";
|
|
9
|
+
import "core-js/modules/es.promise.js";
|
|
10
|
+
import "core-js/modules/web.timers.js";
|
|
11
|
+
export var ActionWhenTaskFail = /*#__PURE__*/function (ActionWhenTaskFail) {
|
|
12
|
+
ActionWhenTaskFail[ActionWhenTaskFail["CONTINUE"] = 0] = "CONTINUE";
|
|
13
|
+
ActionWhenTaskFail[ActionWhenTaskFail["EXIT"] = 1] = "EXIT";
|
|
14
|
+
return ActionWhenTaskFail;
|
|
15
|
+
}({});
|
|
16
|
+
var promisify = function promisify(runnable) {
|
|
17
|
+
return new Promise(/*#__PURE__*/function () {
|
|
18
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve, reject) {
|
|
19
|
+
var v, _t;
|
|
20
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
21
|
+
while (1) switch (_context.prev = _context.next) {
|
|
22
|
+
case 0:
|
|
23
|
+
_context.prev = 0;
|
|
24
|
+
_context.next = 1;
|
|
25
|
+
return runnable();
|
|
26
|
+
case 1:
|
|
27
|
+
v = _context.sent;
|
|
28
|
+
resolve(v);
|
|
29
|
+
_context.next = 3;
|
|
30
|
+
break;
|
|
31
|
+
case 2:
|
|
32
|
+
_context.prev = 2;
|
|
33
|
+
_t = _context["catch"](0);
|
|
34
|
+
reject(_t);
|
|
35
|
+
case 3:
|
|
36
|
+
case "end":
|
|
37
|
+
return _context.stop();
|
|
38
|
+
}
|
|
39
|
+
}, _callee, null, [[0, 2]]);
|
|
40
|
+
}));
|
|
41
|
+
return function (_x, _x2) {
|
|
42
|
+
return _ref.apply(this, arguments);
|
|
43
|
+
};
|
|
44
|
+
}());
|
|
45
|
+
};
|
|
46
|
+
export var PollingTask = /*#__PURE__*/function () {
|
|
47
|
+
function PollingTask(__arguments) {
|
|
48
|
+
_classCallCheck(this, PollingTask);
|
|
49
|
+
_defineProperty(this, "__running", false);
|
|
50
|
+
this.__arguments = __arguments;
|
|
51
|
+
}
|
|
52
|
+
return _createClass(PollingTask, [{
|
|
53
|
+
key: "start",
|
|
54
|
+
value: function start() {
|
|
55
|
+
var _this = this;
|
|
56
|
+
if (this.__running) {
|
|
57
|
+
throw new Error('Task is already running');
|
|
58
|
+
}
|
|
59
|
+
this.__running = true;
|
|
60
|
+
if (this.__arguments.immediate) {
|
|
61
|
+
promisify(this.__arguments.runnable).then(function () {
|
|
62
|
+
_this.poll();
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
this.poll();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "poll",
|
|
70
|
+
value: function poll() {
|
|
71
|
+
var _this2 = this;
|
|
72
|
+
if (!this.__running) {
|
|
73
|
+
return this.stop();
|
|
74
|
+
}
|
|
75
|
+
this.__timer = setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
76
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
77
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
78
|
+
case 0:
|
|
79
|
+
_context2.next = 1;
|
|
80
|
+
return promisify(_this2.__arguments.runnable)["catch"](function (err) {
|
|
81
|
+
var action = _this2.__arguments.onFail(err);
|
|
82
|
+
if (action === ActionWhenTaskFail.EXIT) {
|
|
83
|
+
_this2.__running = false;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
case 1:
|
|
87
|
+
!_this2.__arguments.once && _this2.poll();
|
|
88
|
+
case 2:
|
|
89
|
+
case "end":
|
|
90
|
+
return _context2.stop();
|
|
91
|
+
}
|
|
92
|
+
}, _callee2);
|
|
93
|
+
})), this.__arguments.interval);
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: "stop",
|
|
97
|
+
value: function stop() {
|
|
98
|
+
clearTimeout(this.__timer);
|
|
99
|
+
this.__running = false;
|
|
100
|
+
}
|
|
101
|
+
}, {
|
|
102
|
+
key: "isStopped",
|
|
103
|
+
get: function get() {
|
|
104
|
+
return !this.__running;
|
|
105
|
+
}
|
|
106
|
+
}]);
|
|
107
|
+
}();
|
|
108
|
+
export var IntervalTask = /*#__PURE__*/function () {
|
|
109
|
+
function IntervalTask(__arguments) {
|
|
110
|
+
_classCallCheck(this, IntervalTask);
|
|
111
|
+
_defineProperty(this, "__running", false);
|
|
112
|
+
this.__arguments = __arguments;
|
|
113
|
+
}
|
|
114
|
+
return _createClass(IntervalTask, [{
|
|
115
|
+
key: "start",
|
|
116
|
+
value: function start() {
|
|
117
|
+
var _this3 = this;
|
|
118
|
+
if (this.__running) {
|
|
119
|
+
throw new Error('Task is already running');
|
|
120
|
+
}
|
|
121
|
+
this.__running = true;
|
|
122
|
+
var _this$__arguments = this.__arguments,
|
|
123
|
+
immediate = _this$__arguments.immediate,
|
|
124
|
+
interval = _this$__arguments.interval;
|
|
125
|
+
if (immediate) {
|
|
126
|
+
this.poll();
|
|
127
|
+
}
|
|
128
|
+
this.__timer = setInterval(function () {
|
|
129
|
+
_this3.poll();
|
|
130
|
+
}, interval);
|
|
131
|
+
}
|
|
132
|
+
}, {
|
|
133
|
+
key: "poll",
|
|
134
|
+
value: function poll() {
|
|
135
|
+
var _this4 = this;
|
|
136
|
+
if (!this.__running) {
|
|
137
|
+
return this.stop();
|
|
138
|
+
}
|
|
139
|
+
var runnable = this.__arguments.runnable;
|
|
140
|
+
promisify(runnable)["catch"](function (err) {
|
|
141
|
+
var action = _this4.__arguments.onFail(err);
|
|
142
|
+
if (action === ActionWhenTaskFail.EXIT) {
|
|
143
|
+
_this4.__running = false;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}, {
|
|
148
|
+
key: "stop",
|
|
149
|
+
value: function stop() {
|
|
150
|
+
clearInterval(this.__timer);
|
|
151
|
+
this.__running = false;
|
|
152
|
+
}
|
|
153
|
+
}, {
|
|
154
|
+
key: "isStopped",
|
|
155
|
+
get: function get() {
|
|
156
|
+
return !this.__running;
|
|
157
|
+
}
|
|
158
|
+
}]);
|
|
159
|
+
}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AgoraUploadScheduler } from './scheduler';
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
|
+
import "core-js/modules/es.array.iterator.js";
|
|
7
|
+
import "core-js/modules/es.array.push.js";
|
|
8
|
+
import "core-js/modules/es.array.unshift.js";
|
|
9
|
+
import "core-js/modules/es.function.bind.js";
|
|
10
|
+
import "core-js/modules/es.map.js";
|
|
11
|
+
import "core-js/modules/es.object.to-string.js";
|
|
12
|
+
import "core-js/modules/es.string.iterator.js";
|
|
13
|
+
import "core-js/modules/esnext.map.delete-all.js";
|
|
14
|
+
import "core-js/modules/esnext.map.emplace.js";
|
|
15
|
+
import "core-js/modules/esnext.map.every.js";
|
|
16
|
+
import "core-js/modules/esnext.map.filter.js";
|
|
17
|
+
import "core-js/modules/esnext.map.find.js";
|
|
18
|
+
import "core-js/modules/esnext.map.find-key.js";
|
|
19
|
+
import "core-js/modules/esnext.map.includes.js";
|
|
20
|
+
import "core-js/modules/esnext.map.key-of.js";
|
|
21
|
+
import "core-js/modules/esnext.map.map-keys.js";
|
|
22
|
+
import "core-js/modules/esnext.map.map-values.js";
|
|
23
|
+
import "core-js/modules/esnext.map.merge.js";
|
|
24
|
+
import "core-js/modules/esnext.map.reduce.js";
|
|
25
|
+
import "core-js/modules/esnext.map.some.js";
|
|
26
|
+
import "core-js/modules/esnext.map.update.js";
|
|
27
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
28
|
+
import "core-js/modules/web.timers.js";
|
|
29
|
+
import { AgoraEventEmitter } from '../utilities/events';
|
|
30
|
+
export var AgoraUploadScheduler = /*#__PURE__*/function () {
|
|
31
|
+
function AgoraUploadScheduler(_uploadHandler) {
|
|
32
|
+
_classCallCheck(this, AgoraUploadScheduler);
|
|
33
|
+
_defineProperty(this, "_maxRetries", 2);
|
|
34
|
+
_defineProperty(this, "_taskRetries", new Map());
|
|
35
|
+
_defineProperty(this, "_eventEmitter", new AgoraEventEmitter());
|
|
36
|
+
_defineProperty(this, "_taskQueue", []);
|
|
37
|
+
_defineProperty(this, "_isProcessing", false);
|
|
38
|
+
_defineProperty(this, "_retryDelay", 1000);
|
|
39
|
+
_defineProperty(this, "_stopped", false);
|
|
40
|
+
this._uploadHandler = _uploadHandler;
|
|
41
|
+
this._notifyQueueChanged = this._notifyQueueChanged.bind(this);
|
|
42
|
+
}
|
|
43
|
+
return _createClass(AgoraUploadScheduler, [{
|
|
44
|
+
key: "release",
|
|
45
|
+
value: function release() {
|
|
46
|
+
this._stopped = true;
|
|
47
|
+
this._taskQueue = [];
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "setRetryDelay",
|
|
51
|
+
value: function setRetryDelay(delay) {
|
|
52
|
+
this._retryDelay = delay;
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "addUploadTask",
|
|
56
|
+
value: function addUploadTask(task) {
|
|
57
|
+
this._taskQueue.push(task);
|
|
58
|
+
this._notifyQueueChanged();
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: "prependUploadTask",
|
|
62
|
+
value: function prependUploadTask(task) {
|
|
63
|
+
this._taskQueue.unshift(task);
|
|
64
|
+
this._notifyQueueChanged();
|
|
65
|
+
}
|
|
66
|
+
}, {
|
|
67
|
+
key: "addObserver",
|
|
68
|
+
value: function addObserver(observer) {
|
|
69
|
+
if (observer.onUploadFailure) {
|
|
70
|
+
this._eventEmitter.on('upload-failure', observer.onUploadFailure);
|
|
71
|
+
}
|
|
72
|
+
if (observer.onUploadSuccess) {
|
|
73
|
+
this._eventEmitter.on('upload-success', observer.onUploadSuccess);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
key: "removeObserver",
|
|
78
|
+
value: function removeObserver(observer) {
|
|
79
|
+
if (observer.onUploadFailure) {
|
|
80
|
+
this._eventEmitter.off('upload-failure', observer.onUploadFailure);
|
|
81
|
+
}
|
|
82
|
+
if (observer.onUploadSuccess) {
|
|
83
|
+
this._eventEmitter.off('upload-success', observer.onUploadSuccess);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: "_notifyQueueChanged",
|
|
88
|
+
value: function () {
|
|
89
|
+
var _notifyQueueChanged2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
90
|
+
var task, retries, _t;
|
|
91
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
92
|
+
while (1) switch (_context.prev = _context.next) {
|
|
93
|
+
case 0:
|
|
94
|
+
if (!this._stopped) {
|
|
95
|
+
_context.next = 1;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
return _context.abrupt("return");
|
|
99
|
+
case 1:
|
|
100
|
+
if (!this._isProcessing) {
|
|
101
|
+
_context.next = 2;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
return _context.abrupt("return");
|
|
105
|
+
case 2:
|
|
106
|
+
if (!(this._taskQueue.length !== 0 && (task = this._taskQueue.shift()))) {
|
|
107
|
+
_context.next = 7;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
_context.prev = 3;
|
|
111
|
+
this._isProcessing = true;
|
|
112
|
+
_context.next = 4;
|
|
113
|
+
return this._uploadHandler.handleUpload(task);
|
|
114
|
+
case 4:
|
|
115
|
+
this._eventEmitter.emit('upload-success', task);
|
|
116
|
+
_context.next = 6;
|
|
117
|
+
break;
|
|
118
|
+
case 5:
|
|
119
|
+
_context.prev = 5;
|
|
120
|
+
_t = _context["catch"](3);
|
|
121
|
+
retries = this._taskRetries.get(task) || 0;
|
|
122
|
+
if (retries < this._maxRetries) {
|
|
123
|
+
this._taskRetries.set(task, retries + 1);
|
|
124
|
+
this._taskQueue.unshift(task);
|
|
125
|
+
} else {
|
|
126
|
+
this._eventEmitter.emit('upload-failure', _t, task);
|
|
127
|
+
}
|
|
128
|
+
case 6:
|
|
129
|
+
_context.prev = 6;
|
|
130
|
+
this._isProcessing = false;
|
|
131
|
+
setTimeout(this._notifyQueueChanged, this._retryDelay);
|
|
132
|
+
return _context.finish(6);
|
|
133
|
+
case 7:
|
|
134
|
+
case "end":
|
|
135
|
+
return _context.stop();
|
|
136
|
+
}
|
|
137
|
+
}, _callee, this, [[3, 5, 6, 7]]);
|
|
138
|
+
}));
|
|
139
|
+
function _notifyQueueChanged() {
|
|
140
|
+
return _notifyQueueChanged2.apply(this, arguments);
|
|
141
|
+
}
|
|
142
|
+
return _notifyQueueChanged;
|
|
143
|
+
}()
|
|
144
|
+
}]);
|
|
145
|
+
}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import "core-js/modules/es.symbol.js";
|
|
2
|
+
import "core-js/modules/es.array.filter.js";
|
|
3
|
+
import "core-js/modules/es.array.for-each.js";
|
|
4
|
+
import "core-js/modules/es.array.push.js";
|
|
5
|
+
import "core-js/modules/es.object.define-properties.js";
|
|
6
|
+
import "core-js/modules/es.object.define-property.js";
|
|
7
|
+
import "core-js/modules/es.object.get-own-property-descriptor.js";
|
|
8
|
+
import "core-js/modules/es.object.get-own-property-descriptors.js";
|
|
9
|
+
import "core-js/modules/es.object.keys.js";
|
|
10
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
11
|
+
import "core-js/modules/esnext.iterator.filter.js";
|
|
12
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
13
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
14
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
15
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
16
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
17
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
18
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
19
|
+
import "core-js/modules/es.object.to-string.js";
|
|
20
|
+
import "core-js/modules/es.promise.js";
|
|
21
|
+
import "core-js/modules/web.timers.js";
|
|
22
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
23
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
24
|
+
import { default as externalRetry } from "async-await-retry";
|
|
25
|
+
var Retry = /*#__PURE__*/function () {
|
|
26
|
+
/**
|
|
27
|
+
* @param fn target function
|
|
28
|
+
* @param args arguments the target function to be called with
|
|
29
|
+
* @param opts options
|
|
30
|
+
*/
|
|
31
|
+
function Retry(fn, args, opts) {
|
|
32
|
+
_classCallCheck(this, Retry);
|
|
33
|
+
this.fn = fn;
|
|
34
|
+
this.args = args;
|
|
35
|
+
this.opts = opts;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* Registers a callback to be called when the target function fails
|
|
41
|
+
* This callback function can be used to manage, by yourself, the retry system. It's called when an error occurred and before to retry. This method can have three behaviors:
|
|
42
|
+
* you can throw an error
|
|
43
|
+
* if it returns truthy value then normal retry system continues
|
|
44
|
+
* if it returns falsy value then the retry system stop
|
|
45
|
+
*
|
|
46
|
+
* @param fn callback function to be called
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
return _createClass(Retry, [{
|
|
50
|
+
key: "fail",
|
|
51
|
+
value: function fail(fn) {
|
|
52
|
+
this.onRetryAttemptFail = fn;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Registers a callback to be called when the target function and all retries fail
|
|
58
|
+
*
|
|
59
|
+
* @param fn callback function to be called
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
}, {
|
|
63
|
+
key: "abort",
|
|
64
|
+
value: function abort(fn) {
|
|
65
|
+
this.onRetryAbort = fn;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Starts executes the target function
|
|
71
|
+
* retriesMax would be 3 and maxBackoff would be 10000(10 sceonds) by default
|
|
72
|
+
*/
|
|
73
|
+
}, {
|
|
74
|
+
key: "exec",
|
|
75
|
+
value: (function () {
|
|
76
|
+
var _exec = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
77
|
+
var _this = this;
|
|
78
|
+
var _t2, _t3;
|
|
79
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
80
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
81
|
+
case 0:
|
|
82
|
+
_context3.prev = 0;
|
|
83
|
+
_context3.next = 1;
|
|
84
|
+
return externalRetry(this.fn, this.args, _objectSpread(_objectSpread({
|
|
85
|
+
retriesMax: 3,
|
|
86
|
+
maxBackoff: 10000,
|
|
87
|
+
interval: 1000
|
|
88
|
+
}, this.opts), {}, {
|
|
89
|
+
onAttemptFail: function () {
|
|
90
|
+
var _onAttemptFail = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(data) {
|
|
91
|
+
var timeFn, _t;
|
|
92
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
93
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
94
|
+
case 0:
|
|
95
|
+
timeFn = /*#__PURE__*/function () {
|
|
96
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
97
|
+
var interval;
|
|
98
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
99
|
+
while (1) switch (_context.prev = _context.next) {
|
|
100
|
+
case 0:
|
|
101
|
+
interval = data.exponential ? Math.min(Math.pow(data.factor, data.currentRetry) * data.interval, data.maxBackoff) : data.interval; // if interval is set to zero, do not use setTimeout, gain 1 event loop tick
|
|
102
|
+
if (!interval) {
|
|
103
|
+
_context.next = 1;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
_context.next = 1;
|
|
107
|
+
return new Promise(function (r) {
|
|
108
|
+
return setTimeout(r, interval + data.jitter);
|
|
109
|
+
});
|
|
110
|
+
case 1:
|
|
111
|
+
case "end":
|
|
112
|
+
return _context.stop();
|
|
113
|
+
}
|
|
114
|
+
}, _callee);
|
|
115
|
+
}));
|
|
116
|
+
return function timeFn() {
|
|
117
|
+
return _ref.apply(this, arguments);
|
|
118
|
+
};
|
|
119
|
+
}();
|
|
120
|
+
_t = _this.onRetryAttemptFail;
|
|
121
|
+
if (!_t) {
|
|
122
|
+
_context2.next = 2;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
_context2.next = 1;
|
|
126
|
+
return _this.onRetryAttemptFail(_objectSpread(_objectSpread({}, data), {}, {
|
|
127
|
+
// fix issue of currentRetry starting from 0
|
|
128
|
+
currentRetry: data.currentRetry + 1,
|
|
129
|
+
timeFn: timeFn
|
|
130
|
+
}));
|
|
131
|
+
case 1:
|
|
132
|
+
_t = _context2.sent;
|
|
133
|
+
case 2:
|
|
134
|
+
return _context2.abrupt("return", _t);
|
|
135
|
+
case 3:
|
|
136
|
+
case "end":
|
|
137
|
+
return _context2.stop();
|
|
138
|
+
}
|
|
139
|
+
}, _callee2);
|
|
140
|
+
}));
|
|
141
|
+
function onAttemptFail(_x) {
|
|
142
|
+
return _onAttemptFail.apply(this, arguments);
|
|
143
|
+
}
|
|
144
|
+
return onAttemptFail;
|
|
145
|
+
}()
|
|
146
|
+
}));
|
|
147
|
+
case 1:
|
|
148
|
+
_context3.next = 4;
|
|
149
|
+
break;
|
|
150
|
+
case 2:
|
|
151
|
+
_context3.prev = 2;
|
|
152
|
+
_t2 = _context3["catch"](0);
|
|
153
|
+
_t3 = this.onRetryAbort;
|
|
154
|
+
if (!_t3) {
|
|
155
|
+
_context3.next = 3;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
_context3.next = 3;
|
|
159
|
+
return this.onRetryAbort(_t2);
|
|
160
|
+
case 3:
|
|
161
|
+
throw _t2;
|
|
162
|
+
case 4:
|
|
163
|
+
case "end":
|
|
164
|
+
return _context3.stop();
|
|
165
|
+
}
|
|
166
|
+
}, _callee3, this, [[0, 2]]);
|
|
167
|
+
}));
|
|
168
|
+
function exec() {
|
|
169
|
+
return _exec.apply(this, arguments);
|
|
170
|
+
}
|
|
171
|
+
return exec;
|
|
172
|
+
}())
|
|
173
|
+
}]);
|
|
174
|
+
}();
|
|
175
|
+
export var retryAttempt = function retryAttempt(fn, args, opts) {
|
|
176
|
+
return new Retry(fn, args, opts);
|
|
177
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
+
import "core-js/modules/es.string.match.js";
|
|
3
|
+
export function checkBrowserDevice() {
|
|
4
|
+
var sUserAgent = navigator.userAgent.toLowerCase();
|
|
5
|
+
// const bIsIpad = sUserAgent.match(/ipad/i);
|
|
6
|
+
var bIsIphoneOs = sUserAgent.match(/iphone os/i);
|
|
7
|
+
var bIsMidp = sUserAgent.match(/midp/i);
|
|
8
|
+
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i);
|
|
9
|
+
var bIsUc = sUserAgent.match(/ucweb/i);
|
|
10
|
+
var bIsAndroid = sUserAgent.match(/android/i);
|
|
11
|
+
var bIsCE = sUserAgent.match(/windows ce/i);
|
|
12
|
+
var bIsWM = sUserAgent.match(/windows mobile/i);
|
|
13
|
+
if (bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
|
|
14
|
+
return 'MobileWeb';
|
|
15
|
+
}
|
|
16
|
+
return 'DesktopWeb';
|
|
17
|
+
}
|
|
18
|
+
export function isMobileWebBrowser() {
|
|
19
|
+
return 'MobileWeb' === checkBrowserDevice();
|
|
20
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import { FcrApplicationPlatform } from './env';
|
|
3
|
+
export var FcrApplicationPlatformDescType = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FcrApplicationPlatform.WEB_DESKTOP, 'webDesktop'), FcrApplicationPlatform.MACOS, 'macOS'), FcrApplicationPlatform.WINDOWS, 'windows'), FcrApplicationPlatform.WEB_MOBILE, 'webMobile'), FcrApplicationPlatform.HARMONY, 'harmony');
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import "core-js/modules/es.array.find.js";
|
|
2
|
+
import "core-js/modules/es.array.includes.js";
|
|
3
|
+
import "core-js/modules/es.array.index-of.js";
|
|
4
|
+
import "core-js/modules/es.object.to-string.js";
|
|
5
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
6
|
+
import "core-js/modules/es.string.includes.js";
|
|
7
|
+
import "core-js/modules/es.string.match.js";
|
|
8
|
+
import { isMobileWebBrowser } from './browser';
|
|
9
|
+
export var isElectron = function isElectron() {
|
|
10
|
+
var userAgent = navigator.userAgent.toLowerCase();
|
|
11
|
+
if (userAgent.indexOf(' electron/') > -1) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
export var FcrApplicationPlatform = /*#__PURE__*/function (FcrApplicationPlatform) {
|
|
17
|
+
FcrApplicationPlatform[FcrApplicationPlatform["WEB_DESKTOP"] = 1] = "WEB_DESKTOP";
|
|
18
|
+
FcrApplicationPlatform[FcrApplicationPlatform["MACOS"] = 2] = "MACOS";
|
|
19
|
+
FcrApplicationPlatform[FcrApplicationPlatform["WINDOWS"] = 3] = "WINDOWS";
|
|
20
|
+
FcrApplicationPlatform[FcrApplicationPlatform["WEB_MOBILE"] = 6] = "WEB_MOBILE";
|
|
21
|
+
FcrApplicationPlatform[FcrApplicationPlatform["HARMONY"] = 7] = "HARMONY";
|
|
22
|
+
return FcrApplicationPlatform;
|
|
23
|
+
}({});
|
|
24
|
+
export var getPlatform = function getPlatform() {
|
|
25
|
+
var userAgent = navigator.userAgent.toLowerCase();
|
|
26
|
+
if (isElectron()) {
|
|
27
|
+
var platforms = [{
|
|
28
|
+
key: 'windows',
|
|
29
|
+
value: FcrApplicationPlatform.WINDOWS
|
|
30
|
+
}, {
|
|
31
|
+
key: 'mac',
|
|
32
|
+
value: FcrApplicationPlatform.MACOS
|
|
33
|
+
}];
|
|
34
|
+
var platform = platforms.find(function (p) {
|
|
35
|
+
return userAgent.includes(p.key);
|
|
36
|
+
});
|
|
37
|
+
return platform ? platform.value : FcrApplicationPlatform.MACOS;
|
|
38
|
+
} else {
|
|
39
|
+
return isMobileWebBrowser() ? FcrApplicationPlatform.WEB_MOBILE : FcrApplicationPlatform.WEB_DESKTOP;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
export var isWindows = function isWindows() {
|
|
43
|
+
return getPlatform() === FcrApplicationPlatform.WINDOWS;
|
|
44
|
+
};
|
|
45
|
+
export var windowsVersion = function windowsVersion() {
|
|
46
|
+
if (!isWindows()) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
var userAgent = navigator.userAgent.toLowerCase();
|
|
50
|
+
var version = userAgent.match(/windows nt (\d+\.\d+)/);
|
|
51
|
+
return version ? version[1] : null; // return like 10.0
|
|
52
|
+
};
|
|
53
|
+
export var isMac = function isMac() {
|
|
54
|
+
return getPlatform() === FcrApplicationPlatform.MACOS;
|
|
55
|
+
};
|