agora-foundation 1.0.0

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.
Files changed (87) hide show
  1. package/lib/decorator/bound/index.d.ts +5 -0
  2. package/lib/decorator/bound/index.js +19 -0
  3. package/lib/decorator/index.d.ts +3 -0
  4. package/lib/decorator/index.js +33 -0
  5. package/lib/decorator/lodash/index.d.ts +16 -0
  6. package/lib/decorator/lodash/index.js +42 -0
  7. package/lib/decorator/log/handler.d.ts +4 -0
  8. package/lib/decorator/log/handler.js +63 -0
  9. package/lib/decorator/log/index.d.ts +4 -0
  10. package/lib/decorator/log/index.js +38 -0
  11. package/lib/decorator/log/log-serializer.d.ts +8 -0
  12. package/lib/decorator/log/log-serializer.js +67 -0
  13. package/lib/decorator/proxy.d.ts +9 -0
  14. package/lib/decorator/proxy.js +154 -0
  15. package/lib/decorator/type.d.ts +16 -0
  16. package/lib/decorator/type.js +12 -0
  17. package/lib/logger/constants.d.ts +11 -0
  18. package/lib/logger/constants.js +11 -0
  19. package/lib/logger/hijack.d.ts +4 -0
  20. package/lib/logger/hijack.js +65 -0
  21. package/lib/logger/index.d.ts +8 -0
  22. package/lib/logger/index.js +70 -0
  23. package/lib/logger/logger-impl.d.ts +19 -0
  24. package/lib/logger/logger-impl.js +111 -0
  25. package/lib/logger/manager-impl.d.ts +8 -0
  26. package/lib/logger/manager-impl.js +67 -0
  27. package/lib/logger/type.d.ts +25 -0
  28. package/lib/logger/type.js +14 -0
  29. package/lib/schedule/index.d.ts +3 -0
  30. package/lib/schedule/index.js +25 -0
  31. package/lib/schedule/scheduler.d.ts +21 -0
  32. package/lib/schedule/scheduler.js +108 -0
  33. package/lib/schedule/task.d.ts +36 -0
  34. package/lib/schedule/task.js +167 -0
  35. package/lib/upload/index.d.ts +2 -0
  36. package/lib/upload/index.js +13 -0
  37. package/lib/upload/scheduler.d.ts +15 -0
  38. package/lib/upload/scheduler.js +114 -0
  39. package/lib/upload/type.d.ts +11 -0
  40. package/lib/upload/type.js +6 -0
  41. package/lib/utilities/async-retry.d.ts +63 -0
  42. package/lib/utilities/async-retry.js +180 -0
  43. package/lib/utilities/env.d.ts +12 -0
  44. package/lib/utilities/env.js +56 -0
  45. package/lib/utilities/events.d.ts +13 -0
  46. package/lib/utilities/events.js +114 -0
  47. package/lib/utilities/file-reader.d.ts +1 -0
  48. package/lib/utilities/file-reader.js +22 -0
  49. package/lib/utilities/interceptor.d.ts +6 -0
  50. package/lib/utilities/interceptor.js +28 -0
  51. package/lib/utilities/misc.d.ts +5 -0
  52. package/lib/utilities/misc.js +52 -0
  53. package/lib/utilities/observable.d.ts +11 -0
  54. package/lib/utilities/observable.js +73 -0
  55. package/lib/utilities/race-condition.d.ts +1 -0
  56. package/lib/utilities/race-condition.js +24 -0
  57. package/lib/utilities/value-check.d.ts +1 -0
  58. package/lib/utilities/value-check.js +10 -0
  59. package/lib/utilities/zip.d.ts +1 -0
  60. package/lib/utilities/zip.js +107 -0
  61. package/lib/worker/constants.d.ts +11 -0
  62. package/lib/worker/constants.js +19 -0
  63. package/lib/worker/handler/binary.d.ts +5 -0
  64. package/lib/worker/handler/binary.js +161 -0
  65. package/lib/worker/handler/db.d.ts +21 -0
  66. package/lib/worker/handler/db.js +42 -0
  67. package/lib/worker/handler/fs-log.d.ts +3 -0
  68. package/lib/worker/handler/fs-log.js +156 -0
  69. package/lib/worker/handler/log.d.ts +12 -0
  70. package/lib/worker/handler/log.js +246 -0
  71. package/lib/worker/handler/reply.d.ts +3 -0
  72. package/lib/worker/handler/reply.js +22 -0
  73. package/lib/worker/index.d.ts +2 -0
  74. package/lib/worker/index.js +15 -0
  75. package/lib/worker/interactor.d.ts +25 -0
  76. package/lib/worker/interactor.js +378 -0
  77. package/lib/worker/mutex.d.ts +5 -0
  78. package/lib/worker/mutex.js +65 -0
  79. package/lib/worker/type.d.ts +1 -0
  80. package/lib/worker/type.js +6 -0
  81. package/lib/worker/worker-entry.d.ts +1 -0
  82. package/lib/worker/worker-entry.js +5 -0
  83. package/lib/worker/worker-factory.d.ts +1 -0
  84. package/lib/worker/worker-factory.js +14 -0
  85. package/lib/worker/worker-installer.d.ts +2 -0
  86. package/lib/worker/worker-installer.js +72 -0
  87. package/package.json +29 -0
@@ -0,0 +1,2 @@
1
+ export type { AgoraUploadHandler, AgoraUploadObserver, AgoraUploadTask } from './type';
2
+ export { AgoraUploadScheduler } from './scheduler';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.object.define-property.js");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "AgoraUploadScheduler", {
8
+ enumerable: true,
9
+ get: function get() {
10
+ return _scheduler.AgoraUploadScheduler;
11
+ }
12
+ });
13
+ var _scheduler = require("./scheduler");
@@ -0,0 +1,15 @@
1
+ import { AgoraUploadTask, AgoraUploadHandler, AgoraUploadObserver } from "./type";
2
+ export declare class AgoraUploadScheduler<T extends AgoraUploadTask> {
3
+ private _uploadHandler;
4
+ private _eventEmitter;
5
+ private _taskQueue;
6
+ private _isProcessing;
7
+ private _retryDelay;
8
+ constructor(_uploadHandler: AgoraUploadHandler<T>);
9
+ setRetryDelay(delay: number): void;
10
+ addUploadTask(task: T): void;
11
+ prependUploadTask(task: T): void;
12
+ addObserver(observer: AgoraUploadObserver): void;
13
+ removeObserver(observer: AgoraUploadObserver): void;
14
+ private _notifyQueueChanged;
15
+ }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.object.define-property.js");
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.AgoraUploadScheduler = void 0;
9
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
+ require("core-js/modules/es.array.push.js");
11
+ require("core-js/modules/es.array.unshift.js");
12
+ require("core-js/modules/es.function.bind.js");
13
+ require("core-js/modules/web.timers.js");
14
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
+ var _events = require("../utilities/events");
19
+ var AgoraUploadScheduler = exports.AgoraUploadScheduler = /*#__PURE__*/function () {
20
+ function AgoraUploadScheduler(_uploadHandler) {
21
+ (0, _classCallCheck2["default"])(this, AgoraUploadScheduler);
22
+ (0, _defineProperty2["default"])(this, "_eventEmitter", new _events.AgoraEventEmitter());
23
+ (0, _defineProperty2["default"])(this, "_taskQueue", []);
24
+ (0, _defineProperty2["default"])(this, "_isProcessing", false);
25
+ (0, _defineProperty2["default"])(this, "_retryDelay", 1000);
26
+ this._uploadHandler = _uploadHandler;
27
+ this._notifyQueueChanged = this._notifyQueueChanged.bind(this);
28
+ }
29
+ return (0, _createClass2["default"])(AgoraUploadScheduler, [{
30
+ key: "setRetryDelay",
31
+ value: function setRetryDelay(delay) {
32
+ this._retryDelay = delay;
33
+ }
34
+ }, {
35
+ key: "addUploadTask",
36
+ value: function addUploadTask(task) {
37
+ this._taskQueue.push(task);
38
+ this._notifyQueueChanged();
39
+ }
40
+ }, {
41
+ key: "prependUploadTask",
42
+ value: function prependUploadTask(task) {
43
+ this._taskQueue.unshift(task);
44
+ this._notifyQueueChanged();
45
+ }
46
+ }, {
47
+ key: "addObserver",
48
+ value: function addObserver(observer) {
49
+ if (observer.onUploadFailure) {
50
+ this._eventEmitter.on("upload-failure", observer.onUploadFailure);
51
+ }
52
+ if (observer.onUploadSuccess) {
53
+ this._eventEmitter.on("upload-success", observer.onUploadSuccess);
54
+ }
55
+ }
56
+ }, {
57
+ key: "removeObserver",
58
+ value: function removeObserver(observer) {
59
+ if (observer.onUploadFailure) {
60
+ this._eventEmitter.off("upload-failure", observer.onUploadFailure);
61
+ }
62
+ if (observer.onUploadSuccess) {
63
+ this._eventEmitter.off("upload-success", observer.onUploadSuccess);
64
+ }
65
+ }
66
+ }, {
67
+ key: "_notifyQueueChanged",
68
+ value: function () {
69
+ var _notifyQueueChanged2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
70
+ var task;
71
+ return _regenerator["default"].wrap(function _callee$(_context) {
72
+ while (1) switch (_context.prev = _context.next) {
73
+ case 0:
74
+ if (!this._isProcessing) {
75
+ _context.next = 2;
76
+ break;
77
+ }
78
+ return _context.abrupt("return");
79
+ case 2:
80
+ if (!(this._taskQueue.length !== 0 && (task = this._taskQueue.shift()))) {
81
+ _context.next = 18;
82
+ break;
83
+ }
84
+ _context.prev = 3;
85
+ this._isProcessing = true;
86
+ _context.next = 7;
87
+ return this._uploadHandler.handleUpload(task);
88
+ case 7:
89
+ this._eventEmitter.emit("upload-success", task);
90
+ _context.next = 14;
91
+ break;
92
+ case 10:
93
+ _context.prev = 10;
94
+ _context.t0 = _context["catch"](3);
95
+ this._eventEmitter.emit("upload-failure", _context.t0, task);
96
+ this._taskQueue.unshift(task);
97
+ case 14:
98
+ _context.prev = 14;
99
+ this._isProcessing = false;
100
+ setTimeout(this._notifyQueueChanged, this._retryDelay);
101
+ return _context.finish(14);
102
+ case 18:
103
+ case "end":
104
+ return _context.stop();
105
+ }
106
+ }, _callee, this, [[3, 10, 14, 18]]);
107
+ }));
108
+ function _notifyQueueChanged() {
109
+ return _notifyQueueChanged2.apply(this, arguments);
110
+ }
111
+ return _notifyQueueChanged;
112
+ }()
113
+ }]);
114
+ }();
@@ -0,0 +1,11 @@
1
+ export type AgoraUploadTask = {
2
+ id: number;
3
+ file: File;
4
+ };
5
+ export interface AgoraUploadObserver {
6
+ onUploadFailure?(error: Error, task: AgoraUploadTask): void;
7
+ onUploadSuccess?(task: AgoraUploadTask): void;
8
+ }
9
+ export interface AgoraUploadHandler<T extends AgoraUploadTask> {
10
+ handleUpload(task: T): Promise<void>;
11
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.object.define-property.js");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
@@ -0,0 +1,63 @@
1
+ type RetryOptions = {
2
+ retriesMax?: number;
3
+ interval?: number;
4
+ exponential?: boolean;
5
+ maxBackoff?: number;
6
+ factor?: number;
7
+ jitter?: number;
8
+ isCb?: boolean;
9
+ };
10
+ type RetryAttemptArgs = {
11
+ error: Error;
12
+ currentRetry: number;
13
+ retriesMax: number;
14
+ interval: number;
15
+ exponential: number;
16
+ factor: number;
17
+ jitter: number;
18
+ maxBackoff: number;
19
+ };
20
+ type AnyFunction = (...args: any[]) => unknown;
21
+ type AbortCallback = (e: Error) => Promise<void> | void;
22
+ type AttemptFailCallback = (args: RetryAttemptArgs & {
23
+ timeFn: () => Promise<void>;
24
+ }) => Promise<boolean> | boolean;
25
+ declare class Retry {
26
+ private fn;
27
+ private args;
28
+ private onRetryAttemptFail?;
29
+ private onRetryAbort?;
30
+ private opts?;
31
+ /**
32
+ * @param fn target function
33
+ * @param args arguments the target function to be called with
34
+ * @param opts options
35
+ */
36
+ constructor(fn: AnyFunction, args: unknown[], opts?: RetryOptions);
37
+ /**
38
+ *
39
+ * Registers a callback to be called when the target function fails
40
+ * 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:
41
+ * you can throw an error
42
+ * if it returns truthy value then normal retry system continues
43
+ * if it returns falsy value then the retry system stop
44
+ *
45
+ * @param fn callback function to be called
46
+ * @returns
47
+ */
48
+ fail(fn: AttemptFailCallback): this;
49
+ /**
50
+ * Registers a callback to be called when the target function and all retries fail
51
+ *
52
+ * @param fn callback function to be called
53
+ * @returns
54
+ */
55
+ abort(fn: AbortCallback): this;
56
+ /**
57
+ * Starts executes the target function
58
+ * retriesMax would be 3 and maxBackoff would be 10000(10 sceonds) by default
59
+ */
60
+ exec(): Promise<void>;
61
+ }
62
+ export declare const retryAttempt: (fn: AnyFunction, args: unknown[], opts?: RetryOptions) => Retry;
63
+ export {};
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.symbol.js");
4
+ require("core-js/modules/es.array.filter.js");
5
+ require("core-js/modules/es.array.for-each.js");
6
+ require("core-js/modules/es.array.push.js");
7
+ require("core-js/modules/es.object.define-properties.js");
8
+ require("core-js/modules/es.object.define-property.js");
9
+ require("core-js/modules/es.object.get-own-property-descriptor.js");
10
+ require("core-js/modules/es.object.get-own-property-descriptors.js");
11
+ require("core-js/modules/es.object.keys.js");
12
+ require("core-js/modules/web.dom-collections.for-each.js");
13
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ exports.retryAttempt = void 0;
18
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
19
+ require("core-js/modules/es.object.to-string.js");
20
+ require("core-js/modules/es.promise.js");
21
+ require("core-js/modules/web.timers.js");
22
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
24
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
25
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
26
+ var _asyncAwaitRetry = _interopRequireDefault(require("async-await-retry"));
27
+ 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; }
28
+ 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) { (0, _defineProperty2["default"])(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; }
29
+ var Retry = /*#__PURE__*/function () {
30
+ /**
31
+ * @param fn target function
32
+ * @param args arguments the target function to be called with
33
+ * @param opts options
34
+ */
35
+ function Retry(fn, args, opts) {
36
+ (0, _classCallCheck2["default"])(this, Retry);
37
+ this.fn = fn;
38
+ this.args = args;
39
+ this.opts = opts;
40
+ }
41
+
42
+ /**
43
+ *
44
+ * Registers a callback to be called when the target function fails
45
+ * 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:
46
+ * you can throw an error
47
+ * if it returns truthy value then normal retry system continues
48
+ * if it returns falsy value then the retry system stop
49
+ *
50
+ * @param fn callback function to be called
51
+ * @returns
52
+ */
53
+ return (0, _createClass2["default"])(Retry, [{
54
+ key: "fail",
55
+ value: function fail(fn) {
56
+ this.onRetryAttemptFail = fn;
57
+ return this;
58
+ }
59
+
60
+ /**
61
+ * Registers a callback to be called when the target function and all retries fail
62
+ *
63
+ * @param fn callback function to be called
64
+ * @returns
65
+ */
66
+ }, {
67
+ key: "abort",
68
+ value: function abort(fn) {
69
+ this.onRetryAbort = fn;
70
+ return this;
71
+ }
72
+
73
+ /**
74
+ * Starts executes the target function
75
+ * retriesMax would be 3 and maxBackoff would be 10000(10 sceonds) by default
76
+ */
77
+ }, {
78
+ key: "exec",
79
+ value: (function () {
80
+ var _exec = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
81
+ var _this = this;
82
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
83
+ while (1) switch (_context3.prev = _context3.next) {
84
+ case 0:
85
+ _context3.prev = 0;
86
+ _context3.next = 3;
87
+ return (0, _asyncAwaitRetry["default"])(this.fn, this.args, _objectSpread(_objectSpread({
88
+ retriesMax: 3,
89
+ maxBackoff: 10000,
90
+ interval: 1000
91
+ }, this.opts), {}, {
92
+ onAttemptFail: function () {
93
+ var _onAttemptFail = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(data) {
94
+ var timeFn;
95
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
96
+ while (1) switch (_context2.prev = _context2.next) {
97
+ case 0:
98
+ timeFn = /*#__PURE__*/function () {
99
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
100
+ var interval;
101
+ return _regenerator["default"].wrap(function _callee$(_context) {
102
+ while (1) switch (_context.prev = _context.next) {
103
+ case 0:
104
+ 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
105
+ if (!interval) {
106
+ _context.next = 4;
107
+ break;
108
+ }
109
+ _context.next = 4;
110
+ return new Promise(function (r) {
111
+ return setTimeout(r, interval + data.jitter);
112
+ });
113
+ case 4:
114
+ case "end":
115
+ return _context.stop();
116
+ }
117
+ }, _callee);
118
+ }));
119
+ return function timeFn() {
120
+ return _ref.apply(this, arguments);
121
+ };
122
+ }();
123
+ _context2.t0 = _this.onRetryAttemptFail;
124
+ if (!_context2.t0) {
125
+ _context2.next = 6;
126
+ break;
127
+ }
128
+ _context2.next = 5;
129
+ return _this.onRetryAttemptFail(_objectSpread(_objectSpread({}, data), {}, {
130
+ // fix issue of currentRetry starting from 0
131
+ currentRetry: data.currentRetry + 1,
132
+ timeFn: timeFn
133
+ }));
134
+ case 5:
135
+ _context2.t0 = _context2.sent;
136
+ case 6:
137
+ return _context2.abrupt("return", _context2.t0);
138
+ case 7:
139
+ case "end":
140
+ return _context2.stop();
141
+ }
142
+ }, _callee2);
143
+ }));
144
+ function onAttemptFail(_x) {
145
+ return _onAttemptFail.apply(this, arguments);
146
+ }
147
+ return onAttemptFail;
148
+ }()
149
+ }));
150
+ case 3:
151
+ _context3.next = 12;
152
+ break;
153
+ case 5:
154
+ _context3.prev = 5;
155
+ _context3.t0 = _context3["catch"](0);
156
+ _context3.t1 = this.onRetryAbort;
157
+ if (!_context3.t1) {
158
+ _context3.next = 11;
159
+ break;
160
+ }
161
+ _context3.next = 11;
162
+ return this.onRetryAbort(_context3.t0);
163
+ case 11:
164
+ throw _context3.t0;
165
+ case 12:
166
+ case "end":
167
+ return _context3.stop();
168
+ }
169
+ }, _callee3, this, [[0, 5]]);
170
+ }));
171
+ function exec() {
172
+ return _exec.apply(this, arguments);
173
+ }
174
+ return exec;
175
+ }())
176
+ }]);
177
+ }();
178
+ var retryAttempt = exports.retryAttempt = function retryAttempt(fn, args, opts) {
179
+ return new Retry(fn, args, opts);
180
+ };
@@ -0,0 +1,12 @@
1
+ export declare const isElectron: () => boolean;
2
+ export declare enum FcrApplicationPlatform {
3
+ DESKTOP_WEB = 0,
4
+ MACOS = 1,
5
+ WINDOWS = 2,
6
+ IOS = 3,
7
+ ANDROID = 4,
8
+ MOBILE_WEB = 5,
9
+ SIP_H322 = 6,
10
+ PSTN = 7
11
+ }
12
+ export declare const getPlatform: () => FcrApplicationPlatform;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.object.define-property.js");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.isElectron = exports.getPlatform = exports.FcrApplicationPlatform = void 0;
8
+ require("core-js/modules/es.array.find.js");
9
+ require("core-js/modules/es.array.includes.js");
10
+ require("core-js/modules/es.array.index-of.js");
11
+ require("core-js/modules/es.object.to-string.js");
12
+ require("core-js/modules/es.string.includes.js");
13
+ var isElectron = exports.isElectron = function isElectron() {
14
+ var userAgent = navigator.userAgent.toLowerCase();
15
+ if (userAgent.indexOf(" electron/") > -1) {
16
+ return true;
17
+ }
18
+ return false;
19
+ };
20
+ var FcrApplicationPlatform = exports.FcrApplicationPlatform = /*#__PURE__*/function (FcrApplicationPlatform) {
21
+ FcrApplicationPlatform[FcrApplicationPlatform["DESKTOP_WEB"] = 0] = "DESKTOP_WEB";
22
+ FcrApplicationPlatform[FcrApplicationPlatform["MACOS"] = 1] = "MACOS";
23
+ FcrApplicationPlatform[FcrApplicationPlatform["WINDOWS"] = 2] = "WINDOWS";
24
+ FcrApplicationPlatform[FcrApplicationPlatform["IOS"] = 3] = "IOS";
25
+ FcrApplicationPlatform[FcrApplicationPlatform["ANDROID"] = 4] = "ANDROID";
26
+ FcrApplicationPlatform[FcrApplicationPlatform["MOBILE_WEB"] = 5] = "MOBILE_WEB";
27
+ FcrApplicationPlatform[FcrApplicationPlatform["SIP_H322"] = 6] = "SIP_H322";
28
+ FcrApplicationPlatform[FcrApplicationPlatform["PSTN"] = 7] = "PSTN";
29
+ return FcrApplicationPlatform;
30
+ }({});
31
+ var getPlatform = exports.getPlatform = function getPlatform() {
32
+ var userAgent = navigator.userAgent.toLowerCase();
33
+ var platforms = [{
34
+ key: 'windows',
35
+ value: FcrApplicationPlatform.WINDOWS
36
+ }, {
37
+ key: 'mac',
38
+ value: FcrApplicationPlatform.MACOS
39
+ }, {
40
+ key: 'android',
41
+ value: FcrApplicationPlatform.MOBILE_WEB
42
+ }, {
43
+ key: 'iphone',
44
+ value: FcrApplicationPlatform.MOBILE_WEB
45
+ }, {
46
+ key: 'ipad',
47
+ value: FcrApplicationPlatform.MOBILE_WEB
48
+ }];
49
+ var platform = platforms.find(function (p) {
50
+ return userAgent.includes(p.key);
51
+ });
52
+ if (isElectron()) {
53
+ return platform ? platform.value : FcrApplicationPlatform.MACOS;
54
+ }
55
+ return platform ? platform.value : FcrApplicationPlatform.DESKTOP_WEB;
56
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 事件发射器
3
+ */
4
+ /**@en
5
+ * Event emitter
6
+ */
7
+ export declare class AgoraEventEmitter {
8
+ once(evt: string, cb: CallableFunction): this;
9
+ on(evt: string, cb: CallableFunction): this;
10
+ off(evt: string, cb: CallableFunction): this;
11
+ removeAllEventListeners(): void;
12
+ emit(evt: string, ...args: any[]): this;
13
+ }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.symbol.js");
4
+ require("core-js/modules/es.symbol.description.js");
5
+ require("core-js/modules/es.symbol.iterator.js");
6
+ require("core-js/modules/es.error.cause.js");
7
+ require("core-js/modules/es.error.to-string.js");
8
+ require("core-js/modules/es.array.from.js");
9
+ require("core-js/modules/es.array.is-array.js");
10
+ require("core-js/modules/es.array.slice.js");
11
+ require("core-js/modules/es.date.to-string.js");
12
+ require("core-js/modules/es.function.name.js");
13
+ require("core-js/modules/es.object.define-property.js");
14
+ require("core-js/modules/es.regexp.exec.js");
15
+ require("core-js/modules/es.regexp.test.js");
16
+ require("core-js/modules/es.regexp.to-string.js");
17
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
18
+ Object.defineProperty(exports, "__esModule", {
19
+ value: true
20
+ });
21
+ exports.AgoraEventEmitter = void 0;
22
+ require("core-js/modules/es.array.concat.js");
23
+ require("core-js/modules/es.array.filter.js");
24
+ require("core-js/modules/es.array.iterator.js");
25
+ require("core-js/modules/es.array.push.js");
26
+ require("core-js/modules/es.map.js");
27
+ require("core-js/modules/es.object.to-string.js");
28
+ require("core-js/modules/es.string.iterator.js");
29
+ require("core-js/modules/web.dom-collections.iterator.js");
30
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
31
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
32
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
33
+ var _logger = require("../logger");
34
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
35
+ 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); }
36
+ 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; } /**
37
+ * 事件发射器
38
+ */
39
+ /**@en
40
+ * Event emitter
41
+ */
42
+ var AgoraEventEmitter = exports.AgoraEventEmitter = /*#__PURE__*/function () {
43
+ function AgoraEventEmitter() {
44
+ (0, _classCallCheck2["default"])(this, AgoraEventEmitter);
45
+ //@internal
46
+ (0, _defineProperty2["default"])(this, "_eventMap", new Map());
47
+ }
48
+ return (0, _createClass2["default"])(AgoraEventEmitter, [{
49
+ key: "once",
50
+ value: function once(evt, cb) {
51
+ var _this = this;
52
+ var wrapper = function wrapper() {
53
+ _this.off(evt, wrapper);
54
+ cb.apply(void 0, arguments);
55
+ };
56
+ this.on(evt, wrapper);
57
+ return this;
58
+ }
59
+ }, {
60
+ key: "on",
61
+ value: function on(evt, cb) {
62
+ var _this$_eventMap$get;
63
+ var cbs = (_this$_eventMap$get = this._eventMap.get(evt)) !== null && _this$_eventMap$get !== void 0 ? _this$_eventMap$get : [];
64
+ cbs.push(cb);
65
+ this._eventMap.set(evt, cbs);
66
+ return this;
67
+ }
68
+ }, {
69
+ key: "off",
70
+ value: function off(evt, cb) {
71
+ var cbs = this._eventMap.get(evt);
72
+ if (cbs) {
73
+ this._eventMap.set(evt, cbs.filter(function (it) {
74
+ return it !== cb;
75
+ }));
76
+ }
77
+ return this;
78
+ }
79
+ }, {
80
+ key: "removeAllEventListeners",
81
+ value: function removeAllEventListeners() {
82
+ this._eventMap.clear();
83
+ }
84
+ }, {
85
+ key: "emit",
86
+ value: function emit(evt) {
87
+ var _this$_eventMap$get2;
88
+ var cbs = (_this$_eventMap$get2 = this._eventMap.get(evt)) !== null && _this$_eventMap$get2 !== void 0 ? _this$_eventMap$get2 : [];
89
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
90
+ args[_key - 1] = arguments[_key];
91
+ }
92
+ var _iterator = _createForOfIteratorHelper(cbs),
93
+ _step;
94
+ try {
95
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
96
+ var cb = _step.value;
97
+ try {
98
+ cb && cb.apply(void 0, args);
99
+ } catch (e) {
100
+ //cb exception should not affect other callbacks
101
+ var error = e;
102
+ var details = error.stack || error.message;
103
+ (0, _logger.getLogger)().error("[event] handling event ".concat(evt, " fail: ").concat(details));
104
+ }
105
+ }
106
+ } catch (err) {
107
+ _iterator.e(err);
108
+ } finally {
109
+ _iterator.f();
110
+ }
111
+ return this;
112
+ }
113
+ }]);
114
+ }();
@@ -0,0 +1 @@
1
+ export declare const readAsArrayBuffer: (blob: Blob) => Promise<ArrayBuffer | null | undefined>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.object.define-property.js");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.readAsArrayBuffer = void 0;
8
+ require("core-js/modules/es.object.to-string.js");
9
+ require("core-js/modules/es.promise.js");
10
+ var readAsArrayBuffer = exports.readAsArrayBuffer = function readAsArrayBuffer(blob) {
11
+ return new Promise(function (resolve, reject) {
12
+ var reader = new FileReader();
13
+ reader.onload = function (event) {
14
+ var _event$target;
15
+ resolve((_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result);
16
+ };
17
+ reader.onerror = function (event) {
18
+ reject(event);
19
+ };
20
+ reader.readAsArrayBuffer(blob);
21
+ });
22
+ };
@@ -0,0 +1,6 @@
1
+ export type Interceptor<T = unknown> = (evt: T) => Result;
2
+ export declare enum Result {
3
+ BREAK = 0,
4
+ CONTINUE = 1
5
+ }
6
+ export declare const chain: <T>(...interceptors: Interceptor<T>[]) => Interceptor<T>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.object.define-property.js");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.chain = exports.Result = void 0;
8
+ var Result = exports.Result = /*#__PURE__*/function (Result) {
9
+ Result[Result["BREAK"] = 0] = "BREAK";
10
+ Result[Result["CONTINUE"] = 1] = "CONTINUE";
11
+ return Result;
12
+ }({}); // simple interceptor chain that allows you to make flow control with functional programming style
13
+ var chain = exports.chain = function chain() {
14
+ for (var _len = arguments.length, interceptors = new Array(_len), _key = 0; _key < _len; _key++) {
15
+ interceptors[_key] = arguments[_key];
16
+ }
17
+ return function (evt) {
18
+ var r = Result.CONTINUE;
19
+ for (var i in interceptors) {
20
+ var interceptor = interceptors[i];
21
+ r = interceptor(evt);
22
+ if (r === Result.BREAK) {
23
+ break;
24
+ }
25
+ }
26
+ return r;
27
+ };
28
+ };