agora-foundation 3.2.0 → 3.3.1
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.
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { AgoraUploadTask, AgoraUploadHandler, AgoraUploadObserver } from
|
|
1
|
+
import { AgoraUploadTask, AgoraUploadHandler, AgoraUploadObserver } from './type';
|
|
2
2
|
export declare class AgoraUploadScheduler<T extends AgoraUploadTask> {
|
|
3
3
|
private _uploadHandler;
|
|
4
4
|
private _eventEmitter;
|
|
5
5
|
private _taskQueue;
|
|
6
6
|
private _isProcessing;
|
|
7
7
|
private _retryDelay;
|
|
8
|
+
private _stopped;
|
|
8
9
|
constructor(_uploadHandler: AgoraUploadHandler<T>);
|
|
10
|
+
release(): void;
|
|
9
11
|
setRetryDelay(delay: number): void;
|
|
10
12
|
addUploadTask(task: T): void;
|
|
11
13
|
prependUploadTask(task: T): void;
|
package/lib/upload/scheduler.js
CHANGED
|
@@ -23,10 +23,17 @@ var AgoraUploadScheduler = exports.AgoraUploadScheduler = /*#__PURE__*/function
|
|
|
23
23
|
(0, _defineProperty2["default"])(this, "_taskQueue", []);
|
|
24
24
|
(0, _defineProperty2["default"])(this, "_isProcessing", false);
|
|
25
25
|
(0, _defineProperty2["default"])(this, "_retryDelay", 1000);
|
|
26
|
+
(0, _defineProperty2["default"])(this, "_stopped", false);
|
|
26
27
|
this._uploadHandler = _uploadHandler;
|
|
27
28
|
this._notifyQueueChanged = this._notifyQueueChanged.bind(this);
|
|
28
29
|
}
|
|
29
30
|
return (0, _createClass2["default"])(AgoraUploadScheduler, [{
|
|
31
|
+
key: "release",
|
|
32
|
+
value: function release() {
|
|
33
|
+
this._stopped = true;
|
|
34
|
+
this._taskQueue = [];
|
|
35
|
+
}
|
|
36
|
+
}, {
|
|
30
37
|
key: "setRetryDelay",
|
|
31
38
|
value: function setRetryDelay(delay) {
|
|
32
39
|
this._retryDelay = delay;
|
|
@@ -47,20 +54,20 @@ var AgoraUploadScheduler = exports.AgoraUploadScheduler = /*#__PURE__*/function
|
|
|
47
54
|
key: "addObserver",
|
|
48
55
|
value: function addObserver(observer) {
|
|
49
56
|
if (observer.onUploadFailure) {
|
|
50
|
-
this._eventEmitter.on(
|
|
57
|
+
this._eventEmitter.on('upload-failure', observer.onUploadFailure);
|
|
51
58
|
}
|
|
52
59
|
if (observer.onUploadSuccess) {
|
|
53
|
-
this._eventEmitter.on(
|
|
60
|
+
this._eventEmitter.on('upload-success', observer.onUploadSuccess);
|
|
54
61
|
}
|
|
55
62
|
}
|
|
56
63
|
}, {
|
|
57
64
|
key: "removeObserver",
|
|
58
65
|
value: function removeObserver(observer) {
|
|
59
66
|
if (observer.onUploadFailure) {
|
|
60
|
-
this._eventEmitter.off(
|
|
67
|
+
this._eventEmitter.off('upload-failure', observer.onUploadFailure);
|
|
61
68
|
}
|
|
62
69
|
if (observer.onUploadSuccess) {
|
|
63
|
-
this._eventEmitter.off(
|
|
70
|
+
this._eventEmitter.off('upload-success', observer.onUploadSuccess);
|
|
64
71
|
}
|
|
65
72
|
}
|
|
66
73
|
}, {
|
|
@@ -71,39 +78,45 @@ var AgoraUploadScheduler = exports.AgoraUploadScheduler = /*#__PURE__*/function
|
|
|
71
78
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
72
79
|
while (1) switch (_context.prev = _context.next) {
|
|
73
80
|
case 0:
|
|
74
|
-
if (!this.
|
|
81
|
+
if (!this._stopped) {
|
|
75
82
|
_context.next = 2;
|
|
76
83
|
break;
|
|
77
84
|
}
|
|
78
85
|
return _context.abrupt("return");
|
|
79
86
|
case 2:
|
|
87
|
+
if (!this._isProcessing) {
|
|
88
|
+
_context.next = 4;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
return _context.abrupt("return");
|
|
92
|
+
case 4:
|
|
80
93
|
if (!(this._taskQueue.length !== 0 && (task = this._taskQueue.shift()))) {
|
|
81
|
-
_context.next =
|
|
94
|
+
_context.next = 20;
|
|
82
95
|
break;
|
|
83
96
|
}
|
|
84
|
-
_context.prev =
|
|
97
|
+
_context.prev = 5;
|
|
85
98
|
this._isProcessing = true;
|
|
86
|
-
_context.next =
|
|
99
|
+
_context.next = 9;
|
|
87
100
|
return this._uploadHandler.handleUpload(task);
|
|
88
|
-
case
|
|
89
|
-
this._eventEmitter.emit(
|
|
90
|
-
_context.next =
|
|
101
|
+
case 9:
|
|
102
|
+
this._eventEmitter.emit('upload-success', task);
|
|
103
|
+
_context.next = 16;
|
|
91
104
|
break;
|
|
92
|
-
case
|
|
93
|
-
_context.prev =
|
|
94
|
-
_context.t0 = _context["catch"](
|
|
95
|
-
this._eventEmitter.emit(
|
|
105
|
+
case 12:
|
|
106
|
+
_context.prev = 12;
|
|
107
|
+
_context.t0 = _context["catch"](5);
|
|
108
|
+
this._eventEmitter.emit('upload-failure', _context.t0, task);
|
|
96
109
|
this._taskQueue.unshift(task);
|
|
97
|
-
case
|
|
98
|
-
_context.prev =
|
|
110
|
+
case 16:
|
|
111
|
+
_context.prev = 16;
|
|
99
112
|
this._isProcessing = false;
|
|
100
113
|
setTimeout(this._notifyQueueChanged, this._retryDelay);
|
|
101
|
-
return _context.finish(
|
|
102
|
-
case
|
|
114
|
+
return _context.finish(16);
|
|
115
|
+
case 20:
|
|
103
116
|
case "end":
|
|
104
117
|
return _context.stop();
|
|
105
118
|
}
|
|
106
|
-
}, _callee, this, [[
|
|
119
|
+
}, _callee, this, [[5, 12, 16, 20]]);
|
|
107
120
|
}));
|
|
108
121
|
function _notifyQueueChanged() {
|
|
109
122
|
return _notifyQueueChanged2.apply(this, arguments);
|
package/lib/utilities/zip.js
CHANGED
|
@@ -48,8 +48,8 @@ var zipDir = exports.zipDir = function zipDir(dirPath) {
|
|
|
48
48
|
_context.next = 4;
|
|
49
49
|
break;
|
|
50
50
|
}
|
|
51
|
-
console.error("failed to read
|
|
52
|
-
_context.next =
|
|
51
|
+
console.error("failed to read dir.", err);
|
|
52
|
+
_context.next = 39;
|
|
53
53
|
break;
|
|
54
54
|
case 4:
|
|
55
55
|
if (!(files.length === 0)) {
|
|
@@ -57,43 +57,64 @@ var zipDir = exports.zipDir = function zipDir(dirPath) {
|
|
|
57
57
|
break;
|
|
58
58
|
}
|
|
59
59
|
resolve(null);
|
|
60
|
-
_context.next =
|
|
60
|
+
_context.next = 39;
|
|
61
61
|
break;
|
|
62
62
|
case 8:
|
|
63
63
|
zip = new _jszip["default"]();
|
|
64
64
|
_iterator = _createForOfIteratorHelper(files);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
_context.prev = 10;
|
|
66
|
+
_iterator.s();
|
|
67
|
+
case 12:
|
|
68
|
+
if ((_step = _iterator.n()).done) {
|
|
69
|
+
_context.next = 22;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
_file = _step.value;
|
|
73
|
+
filePath = "".concat(dirPath, "/").concat(_file); // check if filePath pointed to a regular file
|
|
74
|
+
_context.next = 17;
|
|
75
|
+
return isFile(filePath);
|
|
76
|
+
case 17:
|
|
77
|
+
if (!_context.sent) {
|
|
78
|
+
_context.next = 20;
|
|
79
|
+
break;
|
|
76
80
|
}
|
|
77
|
-
|
|
81
|
+
logsStr = fs.readFileSync(filePath, 'utf8');
|
|
82
|
+
zip.file(_file, logsStr);
|
|
83
|
+
case 20:
|
|
84
|
+
_context.next = 12;
|
|
85
|
+
break;
|
|
86
|
+
case 22:
|
|
87
|
+
_context.next = 27;
|
|
88
|
+
break;
|
|
89
|
+
case 24:
|
|
90
|
+
_context.prev = 24;
|
|
91
|
+
_context.t0 = _context["catch"](10);
|
|
92
|
+
_iterator.e(_context.t0);
|
|
93
|
+
case 27:
|
|
94
|
+
_context.prev = 27;
|
|
95
|
+
_iterator.f();
|
|
96
|
+
return _context.finish(27);
|
|
97
|
+
case 30:
|
|
98
|
+
_context.next = 32;
|
|
78
99
|
return zip.generateAsync({
|
|
79
100
|
type: 'blob'
|
|
80
101
|
});
|
|
81
|
-
case
|
|
102
|
+
case 32:
|
|
82
103
|
blob = _context.sent;
|
|
83
|
-
_context.next =
|
|
104
|
+
_context.next = 35;
|
|
84
105
|
return blob.arrayBuffer();
|
|
85
|
-
case
|
|
106
|
+
case 35:
|
|
86
107
|
buffer = _context.sent;
|
|
87
108
|
datefmt = (0, _dayjs["default"])().format('YYYY-MM-DDTHH:mm:ssZ[Z]');
|
|
88
109
|
file = new File([buffer], "logs-".concat(datefmt, ".zip"), {
|
|
89
110
|
type: 'application/zip'
|
|
90
111
|
});
|
|
91
112
|
resolve(file);
|
|
92
|
-
case
|
|
113
|
+
case 39:
|
|
93
114
|
case "end":
|
|
94
115
|
return _context.stop();
|
|
95
116
|
}
|
|
96
|
-
}, _callee);
|
|
117
|
+
}, _callee, null, [[10, 24, 27, 30]]);
|
|
97
118
|
}));
|
|
98
119
|
return function (_x, _x2) {
|
|
99
120
|
return _ref.apply(this, arguments);
|
|
@@ -104,4 +125,27 @@ var zipDir = exports.zipDir = function zipDir(dirPath) {
|
|
|
104
125
|
resolve(null);
|
|
105
126
|
}
|
|
106
127
|
});
|
|
107
|
-
};
|
|
128
|
+
};
|
|
129
|
+
var isFile = /*#__PURE__*/function () {
|
|
130
|
+
var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(filePath) {
|
|
131
|
+
var fs;
|
|
132
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
133
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
134
|
+
case 0:
|
|
135
|
+
fs = window.require('fs');
|
|
136
|
+
return _context2.abrupt("return", new Promise(function (resolve, reject) {
|
|
137
|
+
fs.stat(filePath, function (err, stats) {
|
|
138
|
+
if (err) reject(err);
|
|
139
|
+
resolve(stats.isFile());
|
|
140
|
+
});
|
|
141
|
+
}));
|
|
142
|
+
case 2:
|
|
143
|
+
case "end":
|
|
144
|
+
return _context2.stop();
|
|
145
|
+
}
|
|
146
|
+
}, _callee2);
|
|
147
|
+
}));
|
|
148
|
+
return function isFile(_x3) {
|
|
149
|
+
return _ref2.apply(this, arguments);
|
|
150
|
+
};
|
|
151
|
+
}();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WorkerContext } from
|
|
1
|
+
import { WorkerContext } from '../type';
|
|
2
2
|
export declare const persistBinary: (self: WorkerContext, callId: number, id: number, data: Blob) => Promise<void>;
|
|
3
3
|
export declare const unpersistBinary: (self: WorkerContext, callId: number, id: number) => Promise<void>;
|
|
4
4
|
export declare const getBuffer: (self: WorkerContext, callId: number, id: number) => Promise<void>;
|
|
@@ -85,19 +85,20 @@ var getBuffer = exports.getBuffer = /*#__PURE__*/function () {
|
|
|
85
85
|
case 0:
|
|
86
86
|
_context3.prev = 0;
|
|
87
87
|
_context3.next = 3;
|
|
88
|
-
return _db.db.tempLogs.where(
|
|
88
|
+
return _db.db.tempLogs.where('id').equals(id).first();
|
|
89
89
|
case 3:
|
|
90
90
|
tempLogs = _context3.sent;
|
|
91
|
+
buffer = null;
|
|
91
92
|
if (!(tempLogs !== null && tempLogs !== void 0 && tempLogs.data)) {
|
|
92
|
-
_context3.next =
|
|
93
|
+
_context3.next = 10;
|
|
93
94
|
break;
|
|
94
95
|
}
|
|
95
|
-
_context3.next =
|
|
96
|
+
_context3.next = 8;
|
|
96
97
|
return (0, _fileReader.readAsArrayBuffer)(tempLogs.data);
|
|
97
|
-
case
|
|
98
|
+
case 8:
|
|
98
99
|
data = _context3.sent;
|
|
99
100
|
buffer = data;
|
|
100
|
-
case
|
|
101
|
+
case 10:
|
|
101
102
|
if (buffer) {
|
|
102
103
|
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.GET_BUFFER, {
|
|
103
104
|
isSuccess: true,
|
|
@@ -109,20 +110,20 @@ var getBuffer = exports.getBuffer = /*#__PURE__*/function () {
|
|
|
109
110
|
buffer: null
|
|
110
111
|
});
|
|
111
112
|
}
|
|
112
|
-
_context3.next =
|
|
113
|
+
_context3.next = 17;
|
|
113
114
|
break;
|
|
114
|
-
case
|
|
115
|
-
_context3.prev =
|
|
115
|
+
case 13:
|
|
116
|
+
_context3.prev = 13;
|
|
116
117
|
_context3.t0 = _context3["catch"](0);
|
|
117
118
|
console.error("[logger] failed to get buffer.", _context3.t0);
|
|
118
119
|
(0, _reply.reply)(self, callId, _constants.WorkerDirectives.GET_BUFFER, {
|
|
119
120
|
isSuccess: false
|
|
120
121
|
});
|
|
121
|
-
case
|
|
122
|
+
case 17:
|
|
122
123
|
case "end":
|
|
123
124
|
return _context3.stop();
|
|
124
125
|
}
|
|
125
|
-
}, _callee3, null, [[0,
|
|
126
|
+
}, _callee3, null, [[0, 13]]);
|
|
126
127
|
}));
|
|
127
128
|
return function getBuffer(_x8, _x9, _x10) {
|
|
128
129
|
return _ref3.apply(this, arguments);
|
|
@@ -13,7 +13,7 @@ export declare class WorkerInteractor implements LogWorkerInteractor {
|
|
|
13
13
|
deleteLogs(labels: string[], lastId: number): Promise<void>;
|
|
14
14
|
persistBinary(id: number, buffer: Buffer): Promise<void>;
|
|
15
15
|
unpersistBinary(id: number): Promise<void>;
|
|
16
|
-
getBinary(id: number): Promise<Buffer | null>;
|
|
16
|
+
getBinary(id: number): Promise<Buffer<ArrayBufferLike> | null>;
|
|
17
17
|
collectLogsOnFs(logDirPath: string): Promise<File>;
|
|
18
18
|
private _handleMessageCallback;
|
|
19
19
|
private _handleErrorCallback;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agora-foundation",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "agora-tc-transpile",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@types/lodash": "^4.14.168",
|
|
22
22
|
"@types/node": "^20.11.30",
|
|
23
23
|
"tslib": "^2.6.2",
|
|
24
|
-
"agora-toolchain": "^3.
|
|
24
|
+
"agora-toolchain": "^3.3.1"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"async-await-retry": "^2.0.1",
|
|
@@ -30,4 +30,4 @@
|
|
|
30
30
|
"jszip": "^3.10.1",
|
|
31
31
|
"lodash": "^4.17.21"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|