trtc-electron-sdk 12.2.115-beta.1 → 12.2.115-beta.11
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/liteav/MediaMixingDesigner/index.d.ts +10 -7
- package/liteav/MediaMixingDesigner/index.js +109 -76
- package/liteav/base/PromiseStore.d.ts +10 -0
- package/liteav/base/PromiseStore.js +60 -0
- package/liteav/constant.d.ts +1 -0
- package/liteav/constant.js +4 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingManager.d.ts +423 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingManager.js +1167 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingService.d.ts +60 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingService.js +80 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/BaseStreamLayoutManager.d.ts +27 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/BaseStreamLayoutManager.js +99 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/CustomStreamLayoutManager.d.ts +11 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/CustomStreamLayoutManager.js +119 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/NoneStreamLayoutManager.d.ts +11 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/NoneStreamLayoutManager.js +64 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/index.d.ts +7 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/index.js +34 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/types.d.ts +21 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/types.js +2 -0
- package/liteav/extensions/MediaMixingManager/index.d.ts +4 -227
- package/liteav/extensions/MediaMixingManager/index.js +30 -589
- package/liteav/extensions/MediaMixingManager/types.d.ts +107 -0
- package/liteav/extensions/MediaMixingManager/types.js +26 -0
- package/liteav/trtc.d.ts +63 -10
- package/liteav/trtc.js +145 -57
- package/liteav/trtc_define.d.ts +25 -2
- package/liteav/trtc_define.js +27 -3
- package/liteav/utils.d.ts +27 -0
- package/liteav/utils.js +85 -1
- package/package.json +2 -2
- package/scripts/download.js +153 -169
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Rect, TRTCVideoFillMode } from "../trtc_define";
|
|
2
2
|
export declare type TRTCMediaInfo = {
|
|
3
3
|
id: string;
|
|
4
4
|
rect: Rect;
|
|
@@ -9,8 +9,6 @@ export declare type TRTCMediaInfo = {
|
|
|
9
9
|
declare class TRTCMediaMixingDesigner {
|
|
10
10
|
private logPrefix;
|
|
11
11
|
private container;
|
|
12
|
-
private videoResolution;
|
|
13
|
-
private resMode;
|
|
14
12
|
private mixingVideoWidth;
|
|
15
13
|
private mixingVideoHeight;
|
|
16
14
|
private canExceedContainer;
|
|
@@ -33,16 +31,20 @@ declare class TRTCMediaMixingDesigner {
|
|
|
33
31
|
private mousedownTop;
|
|
34
32
|
private eventButton;
|
|
35
33
|
private resizeObserver;
|
|
34
|
+
private relativeWorkingArea;
|
|
35
|
+
private absoluteWorkingArea;
|
|
36
|
+
private fillMode;
|
|
36
37
|
constructor(options: {
|
|
37
38
|
view: HTMLElement;
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
40
41
|
canExceedContainer: boolean;
|
|
41
42
|
});
|
|
42
43
|
updateOptions(options: {
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
width: number;
|
|
45
|
+
height: number;
|
|
45
46
|
}): void;
|
|
47
|
+
setWorkingArea(relative: Rect | null | undefined, fillMode?: TRTCVideoFillMode): void;
|
|
46
48
|
addMedia(media: TRTCMediaInfo): void;
|
|
47
49
|
removeMedia(media: TRTCMediaInfo): void;
|
|
48
50
|
updateMedia(media: TRTCMediaInfo): void;
|
|
@@ -54,6 +56,7 @@ declare class TRTCMediaMixingDesigner {
|
|
|
54
56
|
private initContainerMouseEventHander;
|
|
55
57
|
private initContainerResizeObserver;
|
|
56
58
|
private onPreviewAreaResize;
|
|
59
|
+
private updateWorkingArea;
|
|
57
60
|
private updatePreviewProperty;
|
|
58
61
|
private updateOverlay;
|
|
59
62
|
private onMove;
|
|
@@ -5,26 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const events_1 = require("events");
|
|
7
7
|
const trtc_define_1 = require("../trtc_define");
|
|
8
|
-
const utils_1 = require("../utils");
|
|
9
8
|
const logger_1 = __importDefault(require("../logger"));
|
|
10
9
|
const Movable_1 = __importDefault(require("./Movable"));
|
|
11
10
|
const Resizable_1 = __importDefault(require("./Resizable"));
|
|
12
11
|
const MIN_MOVE_DISTANCE = 5; // minimum moving distance
|
|
13
|
-
const initResolutionMap = () => {
|
|
14
|
-
const map = new Map();
|
|
15
|
-
for (const key in trtc_define_1.TRTCVideoResolution) {
|
|
16
|
-
if (isNaN(Number(key))) {
|
|
17
|
-
const value = trtc_define_1.TRTCVideoResolution[key];
|
|
18
|
-
const tmp = key.split('_');
|
|
19
|
-
map.set(value, {
|
|
20
|
-
width: parseInt(tmp[1]),
|
|
21
|
-
height: parseInt(tmp[2]),
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return map;
|
|
26
|
-
};
|
|
27
|
-
const resolutionMap = initResolutionMap();
|
|
28
12
|
class TRTCMediaMixingDesigner {
|
|
29
13
|
constructor(options) {
|
|
30
14
|
this.logPrefix = '[TRTCMediaMixingDesigner]';
|
|
@@ -48,19 +32,12 @@ class TRTCMediaMixingDesigner {
|
|
|
48
32
|
this.resizeObserver = null;
|
|
49
33
|
this.container = options.view;
|
|
50
34
|
this.container.style.position = 'absolute';
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.mixingVideoHeight = height;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
this.mixingVideoWidth = height;
|
|
61
|
-
this.mixingVideoHeight = width;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
35
|
+
this.relativeWorkingArea = { left: 0, top: 0, right: 1, bottom: 1 };
|
|
36
|
+
this.absoluteWorkingArea = {};
|
|
37
|
+
this.fillMode = trtc_define_1.TRTCVideoFillMode.TRTCVideoFillMode_Fit;
|
|
38
|
+
this.updateWorkingArea();
|
|
39
|
+
this.mixingVideoWidth = options.width;
|
|
40
|
+
this.mixingVideoHeight = options.height;
|
|
64
41
|
this.updatePreviewProperty();
|
|
65
42
|
this.canExceedContainer = options.canExceedContainer || false;
|
|
66
43
|
this.eventEmitter = new events_1.EventEmitter();
|
|
@@ -75,25 +52,26 @@ class TRTCMediaMixingDesigner {
|
|
|
75
52
|
this.initContainerResizeObserver();
|
|
76
53
|
}
|
|
77
54
|
updateOptions(options) {
|
|
78
|
-
if (
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
if (resolutionMap.has(options.videoResolution)) {
|
|
82
|
-
const { width, height } = resolutionMap.get(options.videoResolution);
|
|
83
|
-
if (this.resMode === trtc_define_1.TRTCVideoResolutionMode.TRTCVideoResolutionModeLandscape) {
|
|
84
|
-
this.mixingVideoWidth = width;
|
|
85
|
-
this.mixingVideoHeight = height;
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
this.mixingVideoWidth = height;
|
|
89
|
-
this.mixingVideoHeight = width;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
55
|
+
if (this.mixingVideoWidth !== options.width || this.mixingVideoHeight !== options.height) {
|
|
56
|
+
this.mixingVideoWidth = options.width;
|
|
57
|
+
this.mixingVideoHeight = options.height;
|
|
93
58
|
this.updatePreviewProperty();
|
|
94
59
|
this.updateOverlay();
|
|
95
60
|
}
|
|
96
61
|
}
|
|
62
|
+
setWorkingArea(relative, fillMode = trtc_define_1.TRTCVideoFillMode.TRTCVideoFillMode_Fit) {
|
|
63
|
+
logger_1.default.log(`${this.logPrefix}setWorkingArea:`, JSON.stringify(relative), `fillMode:${fillMode}`);
|
|
64
|
+
if (relative) {
|
|
65
|
+
this.relativeWorkingArea = Object.assign({}, relative);
|
|
66
|
+
this.fillMode = fillMode;
|
|
67
|
+
this.updateWorkingArea();
|
|
68
|
+
this.updatePreviewProperty();
|
|
69
|
+
this.updateOverlay();
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
logger_1.default.error(`${this.logPrefix}setWorkingArea invalid parameter:`, relative);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
97
75
|
addMedia(media) {
|
|
98
76
|
this.mediaList.unshift(media);
|
|
99
77
|
if (media.isSelected) {
|
|
@@ -194,50 +172,98 @@ class TRTCMediaMixingDesigner {
|
|
|
194
172
|
logger_1.default.log(`${this.logPrefix}onPreviewAreaResize:`, entries);
|
|
195
173
|
for (const entry of entries) {
|
|
196
174
|
if (entry.target === this.container) {
|
|
175
|
+
this.updateWorkingArea();
|
|
197
176
|
this.updatePreviewProperty();
|
|
198
177
|
this.updateOverlay();
|
|
199
178
|
break;
|
|
200
179
|
}
|
|
201
180
|
}
|
|
202
181
|
}
|
|
182
|
+
updateWorkingArea() {
|
|
183
|
+
if (this.relativeWorkingArea && this.container) {
|
|
184
|
+
const containerRect = this.container.getBoundingClientRect();
|
|
185
|
+
this.absoluteWorkingArea = {
|
|
186
|
+
left: this.relativeWorkingArea.left * containerRect.width,
|
|
187
|
+
top: this.relativeWorkingArea.top * containerRect.height,
|
|
188
|
+
right: this.relativeWorkingArea.right * containerRect.width,
|
|
189
|
+
bottom: this.relativeWorkingArea.bottom * containerRect.height,
|
|
190
|
+
width: (this.relativeWorkingArea.right - this.relativeWorkingArea.left) * containerRect.width,
|
|
191
|
+
height: (this.relativeWorkingArea.bottom - this.relativeWorkingArea.top) * containerRect.height,
|
|
192
|
+
};
|
|
193
|
+
logger_1.default.log(`${this.logPrefix}updateWorkingArea absolute working area:`, JSON.stringify(this.absoluteWorkingArea));
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
logger_1.default.error(`${this.logPrefix}updateWorkingArea no data:`, this.relativeWorkingArea, this.container);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
203
199
|
updatePreviewProperty() {
|
|
204
|
-
if (this.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
200
|
+
if (this.absoluteWorkingArea) {
|
|
201
|
+
if (this.mixingVideoWidth <= 0 || this.mixingVideoHeight <= 0) {
|
|
202
|
+
logger_1.default.error(`${this.logPrefix}updatePreviewProperty failed, mixingVideoWidth or mixingVideoHeight is zero`);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const workingAreaWidth = this.absoluteWorkingArea.width;
|
|
206
|
+
const workingAreaHeight = this.absoluteWorkingArea.height;
|
|
207
|
+
const widthScale = workingAreaWidth / this.mixingVideoWidth;
|
|
208
|
+
const heightScale = workingAreaHeight / this.mixingVideoHeight;
|
|
209
|
+
if (this.fillMode === trtc_define_1.TRTCVideoFillMode.TRTCVideoFillMode_Fill) {
|
|
210
|
+
this.previewScale = widthScale > heightScale ? widthScale : heightScale;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
this.fillMode = trtc_define_1.TRTCVideoFillMode.TRTCVideoFillMode_Fit;
|
|
214
|
+
this.previewScale = widthScale > heightScale ? heightScale : widthScale;
|
|
215
|
+
}
|
|
210
216
|
this.previewWidth = this.mixingVideoWidth * this.previewScale;
|
|
211
217
|
this.previewHeight = this.mixingVideoHeight * this.previewScale;
|
|
212
|
-
this.previewLeft = (
|
|
213
|
-
this.previewTop = (
|
|
218
|
+
this.previewLeft = (workingAreaWidth - this.previewWidth) / 2;
|
|
219
|
+
this.previewTop = (workingAreaHeight - this.previewHeight) / 2;
|
|
220
|
+
logger_1.default.debug(`${this.logPrefix}updatePreviewProperty: fillMode: ${this.fillMode} previewScale: ${this.previewScale}, previewWidth: ${this.previewWidth}, previewHeight: ${this.previewHeight}, previewLeft: ${this.previewLeft}, previewTop: ${this.previewTop}`);
|
|
214
221
|
}
|
|
215
222
|
else {
|
|
216
|
-
logger_1.default.error(`${this.logPrefix}
|
|
223
|
+
logger_1.default.error(`${this.logPrefix}updatePreviewProperty failed, no HTML element to display`);
|
|
217
224
|
}
|
|
218
225
|
}
|
|
219
226
|
updateOverlay() {
|
|
220
227
|
if (this.moveAndResizeOverlay) {
|
|
221
|
-
let left =
|
|
222
|
-
let top =
|
|
223
|
-
let width =
|
|
224
|
-
let height =
|
|
228
|
+
let left = this.absoluteWorkingArea.left + this.previewLeft;
|
|
229
|
+
let top = this.absoluteWorkingArea.top + this.previewTop;
|
|
230
|
+
let width = 0;
|
|
231
|
+
let height = 0;
|
|
225
232
|
if (this.selectedMediaIndex >= 0) {
|
|
233
|
+
logger_1.default.debug(`${this.logPrefix}updateOverlay: selected media:`, this.mediaList[this.selectedMediaIndex].rect);
|
|
226
234
|
const selectedPreviewRect = {
|
|
227
235
|
left: this.mediaList[this.selectedMediaIndex].rect.left * this.previewScale,
|
|
228
236
|
top: this.mediaList[this.selectedMediaIndex].rect.top * this.previewScale,
|
|
229
237
|
right: this.mediaList[this.selectedMediaIndex].rect.right * this.previewScale,
|
|
230
238
|
bottom: this.mediaList[this.selectedMediaIndex].rect.bottom * this.previewScale
|
|
231
239
|
};
|
|
232
|
-
left =
|
|
233
|
-
top =
|
|
234
|
-
width =
|
|
235
|
-
height =
|
|
240
|
+
left = this.absoluteWorkingArea.left + this.previewLeft + selectedPreviewRect.left;
|
|
241
|
+
top = this.absoluteWorkingArea.top + this.previewTop + selectedPreviewRect.top;
|
|
242
|
+
width = selectedPreviewRect.right - selectedPreviewRect.left;
|
|
243
|
+
height = selectedPreviewRect.bottom - selectedPreviewRect.top;
|
|
244
|
+
}
|
|
245
|
+
let renderScale = 1;
|
|
246
|
+
if (this.container) {
|
|
247
|
+
const containerLayoutWidth = this.container.offsetWidth;
|
|
248
|
+
const containerRenderWidth = Math.round(this.container.getBoundingClientRect().width);
|
|
249
|
+
if (containerLayoutWidth !== containerRenderWidth) {
|
|
250
|
+
logger_1.default.warn(`${this.logPrefix}updateOverlay container layout width: ${containerLayoutWidth} container render width: ${containerRenderWidth}`);
|
|
251
|
+
renderScale = containerRenderWidth / containerLayoutWidth;
|
|
252
|
+
}
|
|
236
253
|
}
|
|
237
|
-
this.moveAndResizeOverlay.style.left = left
|
|
238
|
-
this.moveAndResizeOverlay.style.top = top
|
|
239
|
-
this.moveAndResizeOverlay.style.width = width
|
|
240
|
-
this.moveAndResizeOverlay.style.height = height
|
|
254
|
+
this.moveAndResizeOverlay.style.left = `${left}px`;
|
|
255
|
+
this.moveAndResizeOverlay.style.top = `${top}px`;
|
|
256
|
+
this.moveAndResizeOverlay.style.width = `${width}px`;
|
|
257
|
+
this.moveAndResizeOverlay.style.height = `${height}px`;
|
|
258
|
+
if (renderScale !== 1) {
|
|
259
|
+
this.moveAndResizeOverlay.style.transform = `scale(${1 / renderScale})`;
|
|
260
|
+
this.moveAndResizeOverlay.style.transformOrigin = `-${left}px -${top}px`; // Why?
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
this.moveAndResizeOverlay.style.transform = 'none';
|
|
264
|
+
this.moveAndResizeOverlay.style.transformOrigin = 'none';
|
|
265
|
+
}
|
|
266
|
+
logger_1.default.debug(`${this.logPrefix}updateOverlay: ${left} ${top} ${width} ${height} ${renderScale}`);
|
|
241
267
|
}
|
|
242
268
|
}
|
|
243
269
|
onMove(left, top) {
|
|
@@ -247,10 +273,10 @@ class TRTCMediaMixingDesigner {
|
|
|
247
273
|
if (target && this.moveAndResizeOverlay) {
|
|
248
274
|
// calc new preview rect
|
|
249
275
|
const newPreviewRect = {
|
|
250
|
-
left: left - this.previewLeft,
|
|
251
|
-
top: top - this.previewTop,
|
|
252
|
-
right: left - this.previewLeft + this.moveAndResizeOverlay.offsetWidth,
|
|
253
|
-
bottom: top - this.previewTop + this.moveAndResizeOverlay.offsetHeight,
|
|
276
|
+
left: left - this.absoluteWorkingArea.left - this.previewLeft,
|
|
277
|
+
top: top - this.absoluteWorkingArea.top - this.previewTop,
|
|
278
|
+
right: left - this.absoluteWorkingArea.left - this.previewLeft + this.moveAndResizeOverlay.offsetWidth,
|
|
279
|
+
bottom: top - this.absoluteWorkingArea.top - this.previewTop + this.moveAndResizeOverlay.offsetHeight,
|
|
254
280
|
};
|
|
255
281
|
this.doAdsorption(newPreviewRect);
|
|
256
282
|
// calc new mixing rect
|
|
@@ -260,6 +286,8 @@ class TRTCMediaMixingDesigner {
|
|
|
260
286
|
right: Math.round(newPreviewRect.right / this.previewScale),
|
|
261
287
|
bottom: Math.round(newPreviewRect.bottom / this.previewScale),
|
|
262
288
|
};
|
|
289
|
+
logger_1.default.debug(`${this.logPrefix}onMove new preview rect: ${JSON.stringify(newPreviewRect)}`);
|
|
290
|
+
logger_1.default.debug(`${this.logPrefix}onMove new rect in mixing: ${JSON.stringify(newRectInMixing)}`);
|
|
263
291
|
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit('onSourceMoved', Object.assign({}, target), newRectInMixing);
|
|
264
292
|
}
|
|
265
293
|
else {
|
|
@@ -292,10 +320,10 @@ class TRTCMediaMixingDesigner {
|
|
|
292
320
|
if (target) {
|
|
293
321
|
// calc new preview rect
|
|
294
322
|
const newPreviewRect = {
|
|
295
|
-
left: left - this.previewLeft,
|
|
296
|
-
top: top - this.previewTop,
|
|
297
|
-
right: left - this.previewLeft + width,
|
|
298
|
-
bottom: top - this.previewTop + height,
|
|
323
|
+
left: left - this.absoluteWorkingArea.left - this.previewLeft,
|
|
324
|
+
top: top - this.absoluteWorkingArea.top - this.previewTop,
|
|
325
|
+
right: left - this.absoluteWorkingArea.left - this.previewLeft + width,
|
|
326
|
+
bottom: top - this.absoluteWorkingArea.top - this.previewTop + height,
|
|
299
327
|
};
|
|
300
328
|
// calc new mixing rect
|
|
301
329
|
const newRectInMixing = {
|
|
@@ -335,8 +363,8 @@ class TRTCMediaMixingDesigner {
|
|
|
335
363
|
// calc click point coordinates in mix video image
|
|
336
364
|
logger_1.default.log(`${this.logPrefix}onContainerMousedown mix video image clicked`);
|
|
337
365
|
const containerBounds = this.container.getBoundingClientRect();
|
|
338
|
-
const xInPreviewImage = event.clientX - containerBounds.
|
|
339
|
-
const yInPreviewImage = event.clientY - containerBounds.
|
|
366
|
+
const xInPreviewImage = event.clientX - containerBounds.left - this.absoluteWorkingArea.left - this.previewLeft;
|
|
367
|
+
const yInPreviewImage = event.clientY - containerBounds.top - this.absoluteWorkingArea.top - this.previewTop;
|
|
340
368
|
const xInImage = xInPreviewImage / this.previewScale;
|
|
341
369
|
const yInImage = yInPreviewImage / this.previewScale;
|
|
342
370
|
logger_1.default.log(`${this.logPrefix}onContainerMousedown click point coordinates in mix video:`, xInPreviewImage, yInPreviewImage, xInImage, yInImage);
|
|
@@ -459,7 +487,12 @@ class TRTCMediaMixingDesigner {
|
|
|
459
487
|
var _a;
|
|
460
488
|
logger_1.default.log(`${this.logPrefix}onRightButtonClicked:`, event.target, event.currentTarget, event.buttons);
|
|
461
489
|
event.preventDefault();
|
|
462
|
-
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit('onRightButtonClicked', Object.assign({}, this.mediaList[this.selectedMediaIndex])
|
|
490
|
+
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit('onRightButtonClicked', Object.assign({}, this.mediaList[this.selectedMediaIndex]), {
|
|
491
|
+
windowX: event.clientX,
|
|
492
|
+
windowY: event.clientY,
|
|
493
|
+
screenX: event.screenX,
|
|
494
|
+
screenY: event.screenY
|
|
495
|
+
});
|
|
463
496
|
}
|
|
464
497
|
}
|
|
465
498
|
exports.default = TRTCMediaMixingDesigner;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare class PromiseStore {
|
|
2
|
+
private logPrefix;
|
|
3
|
+
private promiseStore;
|
|
4
|
+
constructor();
|
|
5
|
+
addPromise(key: string, resolve: (data: void | PromiseLike<void>) => void, reject: (reason?: any) => void): void;
|
|
6
|
+
resolvePromise(key: string, value: void | PromiseLike<void>): void;
|
|
7
|
+
rejectPromise(key: string, reason?: any): void;
|
|
8
|
+
destroy(): void;
|
|
9
|
+
}
|
|
10
|
+
export default PromiseStore;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
7
|
+
class PromiseStore {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.logPrefix = '[PromiseStore]';
|
|
10
|
+
this.promiseStore = new Map();
|
|
11
|
+
}
|
|
12
|
+
addPromise(key, resolve, reject) {
|
|
13
|
+
if (!this.promiseStore.has(key)) {
|
|
14
|
+
this.promiseStore.set(key, []);
|
|
15
|
+
}
|
|
16
|
+
const storedPromises = this.promiseStore.get(key);
|
|
17
|
+
storedPromises === null || storedPromises === void 0 ? void 0 : storedPromises.push({
|
|
18
|
+
resolve,
|
|
19
|
+
reject
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
resolvePromise(key, value) {
|
|
23
|
+
var _a;
|
|
24
|
+
const storedPromises = (_a = this.promiseStore) === null || _a === void 0 ? void 0 : _a.get(key);
|
|
25
|
+
if (storedPromises) {
|
|
26
|
+
storedPromises.forEach(({ resolve }) => {
|
|
27
|
+
resolve(value);
|
|
28
|
+
});
|
|
29
|
+
this.promiseStore.delete(key);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
logger_1.default.warn(`${this.logPrefix}resolvePromise '${key}' not existed`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
rejectPromise(key, reason) {
|
|
36
|
+
var _a;
|
|
37
|
+
const storedPromises = (_a = this.promiseStore) === null || _a === void 0 ? void 0 : _a.get(key);
|
|
38
|
+
if (storedPromises) {
|
|
39
|
+
storedPromises.forEach(({ reject }) => {
|
|
40
|
+
reject(reason);
|
|
41
|
+
});
|
|
42
|
+
this.promiseStore.delete(key);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
logger_1.default.warn(`${this.logPrefix}rejectPromise '${key}' not existed`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
destroy() {
|
|
49
|
+
this.promiseStore.forEach((value) => {
|
|
50
|
+
value.forEach(({ reject }) => {
|
|
51
|
+
reject({
|
|
52
|
+
code: Number.NEGATIVE_INFINITY,
|
|
53
|
+
message: 'Instance destroyed, reject all pending promises',
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
this.promiseStore.clear();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.default = PromiseStore;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const LOCAL_USER_ID = "";
|