trtc-electron-sdk 12.2.115-alpha.20 → 12.2.115-alpha.23
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 +2 -1
- package/liteav/MediaMixingDesigner/index.js +26 -3
- package/liteav/base/DevicePixelRatioObserver.d.ts +12 -0
- package/liteav/base/DevicePixelRatioObserver.js +32 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingManager.d.ts +5 -2
- package/liteav/extensions/MediaMixingManager/MediaMixingManager.js +108 -66
- package/liteav/extensions/MediaMixingManager/StreamLayout/BaseStreamLayoutManager.d.ts +1 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/BaseStreamLayoutManager.js +8 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/CustomStreamLayoutManager.js +17 -1
- package/liteav/trtc.d.ts +2 -1
- package/liteav/trtc.js +10 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ export declare type TRTCMediaInfo = {
|
|
|
3
3
|
id: string;
|
|
4
4
|
rect: Rect;
|
|
5
5
|
isSelected: boolean;
|
|
6
|
-
zOrder
|
|
6
|
+
zOrder: number;
|
|
7
7
|
origin: any;
|
|
8
8
|
};
|
|
9
9
|
declare class TRTCMediaMixingDesigner {
|
|
@@ -48,6 +48,7 @@ declare class TRTCMediaMixingDesigner {
|
|
|
48
48
|
addMedia(media: TRTCMediaInfo): void;
|
|
49
49
|
removeMedia(media: TRTCMediaInfo): void;
|
|
50
50
|
updateMedia(media: TRTCMediaInfo): void;
|
|
51
|
+
removeAllMedia(): void;
|
|
51
52
|
on(event: string, func: (...args: any[]) => void): void;
|
|
52
53
|
off(event: string, func: (...args: any[]) => void): void;
|
|
53
54
|
destroy(): void;
|
|
@@ -73,9 +73,23 @@ class TRTCMediaMixingDesigner {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
addMedia(media) {
|
|
76
|
-
|
|
76
|
+
// sort by zOrder desc
|
|
77
|
+
const length = this.mediaList.length;
|
|
78
|
+
let insertIndex = -1;
|
|
79
|
+
for (let i = 0; i < length; i++) {
|
|
80
|
+
if (media.zOrder >= this.mediaList[i].zOrder) {
|
|
81
|
+
insertIndex = i;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (insertIndex >= 0) {
|
|
86
|
+
this.mediaList.splice(insertIndex, 0, media);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
this.mediaList.push(media);
|
|
90
|
+
}
|
|
77
91
|
if (media.isSelected) {
|
|
78
|
-
this.selectedMediaIndex = 0;
|
|
92
|
+
this.selectedMediaIndex = insertIndex >= 0 ? insertIndex : (this.mediaList.length - 1);
|
|
79
93
|
this.updateOverlay();
|
|
80
94
|
}
|
|
81
95
|
}
|
|
@@ -90,15 +104,24 @@ class TRTCMediaMixingDesigner {
|
|
|
90
104
|
}
|
|
91
105
|
}
|
|
92
106
|
updateMedia(media) {
|
|
93
|
-
|
|
107
|
+
let targetIndex = this.mediaList.findIndex(item => item.id === media.id);
|
|
94
108
|
if (targetIndex !== -1) {
|
|
109
|
+
const isZOrderChanged = media.zOrder !== this.mediaList[targetIndex].zOrder;
|
|
95
110
|
this.mediaList[targetIndex] = Object.assign({}, this.mediaList[targetIndex], media);
|
|
111
|
+
if (isZOrderChanged) {
|
|
112
|
+
this.mediaList.sort((a, b) => b.zOrder - a.zOrder);
|
|
113
|
+
targetIndex = this.mediaList.findIndex(item => item.id === media.id);
|
|
114
|
+
}
|
|
96
115
|
if (media.isSelected) {
|
|
97
116
|
this.selectedMediaIndex = targetIndex;
|
|
98
117
|
this.updateOverlay();
|
|
99
118
|
}
|
|
100
119
|
}
|
|
101
120
|
}
|
|
121
|
+
removeAllMedia() {
|
|
122
|
+
this.mediaList = [];
|
|
123
|
+
this.selectedMediaIndex = -1;
|
|
124
|
+
}
|
|
102
125
|
on(event, func) {
|
|
103
126
|
var _a;
|
|
104
127
|
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.on(event, func);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare class DevicePixelRatioObserver {
|
|
2
|
+
private mediaQueryString;
|
|
3
|
+
private mediaQuery;
|
|
4
|
+
private eventEmitter;
|
|
5
|
+
constructor();
|
|
6
|
+
destroy(): void;
|
|
7
|
+
on(event: string, func: (...args: any[]) => void): void;
|
|
8
|
+
off(event: string, func: (...args: any[]) => void): void;
|
|
9
|
+
private onPixelRatioChanged;
|
|
10
|
+
}
|
|
11
|
+
declare const devicePixelRationObserver: DevicePixelRatioObserver;
|
|
12
|
+
export default devicePixelRationObserver;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const events_1 = require("events");
|
|
4
|
+
class DevicePixelRatioObserver {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.mediaQueryString = `(resolution: ${window.devicePixelRatio}dppx)`;
|
|
7
|
+
this.mediaQuery = window.matchMedia(this.mediaQueryString);
|
|
8
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
9
|
+
this.onPixelRatioChanged = this.onPixelRatioChanged.bind(this);
|
|
10
|
+
this.mediaQuery.addEventListener('change', this.onPixelRatioChanged);
|
|
11
|
+
}
|
|
12
|
+
destroy() {
|
|
13
|
+
var _a;
|
|
14
|
+
(_a = this.mediaQuery) === null || _a === void 0 ? void 0 : _a.removeEventListener('change', this.onPixelRatioChanged);
|
|
15
|
+
this.mediaQuery = null;
|
|
16
|
+
this.eventEmitter = null;
|
|
17
|
+
}
|
|
18
|
+
on(event, func) {
|
|
19
|
+
var _a;
|
|
20
|
+
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.on(event, func);
|
|
21
|
+
}
|
|
22
|
+
off(event, func) {
|
|
23
|
+
var _a;
|
|
24
|
+
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.off(event, func);
|
|
25
|
+
}
|
|
26
|
+
onPixelRatioChanged() {
|
|
27
|
+
var _a;
|
|
28
|
+
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit('change');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const devicePixelRationObserver = new DevicePixelRatioObserver();
|
|
32
|
+
exports.default = devicePixelRationObserver;
|
|
@@ -373,6 +373,7 @@ export declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
|
|
|
373
373
|
* @returns {Promise<void>}
|
|
374
374
|
*/
|
|
375
375
|
stopMediaMixingServer(): Promise<void>;
|
|
376
|
+
callExperimentalAPI(jsonStr: string): void;
|
|
376
377
|
/**
|
|
377
378
|
* 注册事件监听
|
|
378
379
|
*
|
|
@@ -393,7 +394,7 @@ export declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
|
|
|
393
394
|
private setDisplayRect;
|
|
394
395
|
private createDesigner;
|
|
395
396
|
private destroyDesigner;
|
|
396
|
-
private
|
|
397
|
+
private createOrUpdateLayoutManager;
|
|
397
398
|
private destroyLayoutManager;
|
|
398
399
|
private updateMixingVideoSize;
|
|
399
400
|
private listenDesignerEvent;
|
|
@@ -409,13 +410,15 @@ export declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
|
|
|
409
410
|
private findSelectedMediaSource;
|
|
410
411
|
private unselectMediaSource;
|
|
411
412
|
private handleCppCallbackEvent;
|
|
412
|
-
private
|
|
413
|
+
private onMediaSourceAdded;
|
|
414
|
+
private onMediaSourceRemoved;
|
|
413
415
|
private onMediaSourceSizeChanged;
|
|
414
416
|
private onPhoneMirrorSourceChanged;
|
|
415
417
|
private onMediaServerState;
|
|
416
418
|
private onMediaMixingServerLost;
|
|
417
419
|
private onCallExperimentalAPIFinish;
|
|
418
420
|
private recoverMediaMixingServer;
|
|
421
|
+
private onDevicePixelRatioChange;
|
|
419
422
|
startCameraDeviceTest(windowID: number | Uint8Array, rect?: Rect): Promise<number>;
|
|
420
423
|
stopCameraDeviceTest(): Promise<number>;
|
|
421
424
|
setCameraTestRenderMirror(mirror: boolean): void;
|
|
@@ -15,11 +15,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.TRTCMediaMixingManager = exports.TRTCMediaMixingEvent = void 0;
|
|
16
16
|
const events_1 = require("events");
|
|
17
17
|
const trtc_define_1 = require("../../trtc_define");
|
|
18
|
+
const types_1 = require("./types");
|
|
18
19
|
const utils_1 = require("../../utils");
|
|
19
20
|
const constant_1 = require("../../constant");
|
|
20
21
|
const index_1 = __importDefault(require("../../MediaMixingDesigner/index"));
|
|
21
22
|
const StreamLayout_1 = require("./StreamLayout");
|
|
22
23
|
const PromiseStore_1 = __importDefault(require("../../base/PromiseStore"));
|
|
24
|
+
const DevicePixelRatioObserver_1 = __importDefault(require("../../base/DevicePixelRatioObserver"));
|
|
23
25
|
const logger_1 = __importDefault(require("../../logger"));
|
|
24
26
|
const NodeTRTCEngine = require('../../../build/Release/trtc_electron_sdk.node');
|
|
25
27
|
/**
|
|
@@ -307,9 +309,12 @@ class TRTCMediaMixingManager {
|
|
|
307
309
|
this.onPreviewAreaResize = this.onPreviewAreaResize.bind(this);
|
|
308
310
|
this.onVisibilityChange = this.onVisibilityChange.bind(this);
|
|
309
311
|
document.addEventListener('visibilitychange', this.onVisibilityChange);
|
|
312
|
+
this.onDevicePixelRatioChange = this.onDevicePixelRatioChange.bind(this);
|
|
313
|
+
DevicePixelRatioObserver_1.default.on('change', this.onDevicePixelRatioChange);
|
|
310
314
|
}
|
|
311
315
|
destroy() {
|
|
312
316
|
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
+
DevicePixelRatioObserver_1.default.off('change', this.onDevicePixelRatioChange);
|
|
313
318
|
document.removeEventListener('visibilitychange', this.onVisibilityChange);
|
|
314
319
|
if (this.resizeObserver && this.view) {
|
|
315
320
|
this.resizeObserver.unobserve(this.view);
|
|
@@ -480,7 +485,10 @@ class TRTCMediaMixingManager {
|
|
|
480
485
|
logger_1.default.log(`${this.logPrefix}addMediaSource:`, mediaSource);
|
|
481
486
|
const index = this.findMediaSourceIndex(mediaSource);
|
|
482
487
|
if (index !== -1) {
|
|
483
|
-
|
|
488
|
+
return Promise.reject({
|
|
489
|
+
code: types_1.TRTCMediaMixingErrorCode.InvalidParams,
|
|
490
|
+
message: "Media source already existed"
|
|
491
|
+
});
|
|
484
492
|
}
|
|
485
493
|
const newMediaSource = (0, utils_1.safelyParse)(JSON.stringify(mediaSource));
|
|
486
494
|
if (newMediaSource.isSelected) {
|
|
@@ -498,6 +506,7 @@ class TRTCMediaMixingManager {
|
|
|
498
506
|
id: `${newMediaSource.sourceType}__${newMediaSource.sourceId}`,
|
|
499
507
|
rect: newMediaSource.rect,
|
|
500
508
|
isSelected: newMediaSource.isSelected || false,
|
|
509
|
+
zOrder: newMediaSource.zOrder,
|
|
501
510
|
origin: newMediaSource
|
|
502
511
|
});
|
|
503
512
|
this.sourceList.push(newMediaSource);
|
|
@@ -512,20 +521,15 @@ class TRTCMediaMixingManager {
|
|
|
512
521
|
logger_1.default.log(`${this.logPrefix}removeMediaSource:`, mediaSource);
|
|
513
522
|
const index = this.findMediaSourceIndex(mediaSource);
|
|
514
523
|
if (index === -1) {
|
|
515
|
-
|
|
524
|
+
return Promise.reject({
|
|
525
|
+
code: types_1.TRTCMediaMixingErrorCode.NotFoundSource,
|
|
526
|
+
message: "Not existing media source to remove"
|
|
527
|
+
});
|
|
516
528
|
}
|
|
517
529
|
return new Promise((resolve, reject) => {
|
|
518
|
-
var _a;
|
|
519
530
|
const key = `${promiseKeys.removeMediaSource}-${mediaSource.sourceType}-${mediaSource.sourceId}`;
|
|
520
531
|
this.promiseStore.addPromise(key, resolve, reject);
|
|
521
532
|
this.nodeMediaMixingPlugin.removeMediaSource(mediaSource);
|
|
522
|
-
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.removeMedia({
|
|
523
|
-
id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
|
|
524
|
-
rect: mediaSource.rect,
|
|
525
|
-
isSelected: mediaSource.isSelected || false,
|
|
526
|
-
origin: (0, utils_1.safelyParse)(JSON.stringify(mediaSource))
|
|
527
|
-
});
|
|
528
|
-
this.sourceList.splice(index, 1);
|
|
529
533
|
});
|
|
530
534
|
}
|
|
531
535
|
/**
|
|
@@ -539,7 +543,10 @@ class TRTCMediaMixingManager {
|
|
|
539
543
|
logger_1.default.log(`${this.logPrefix}updateMediaSource:`, mediaSource);
|
|
540
544
|
const index = this.findMediaSourceIndex(mediaSource);
|
|
541
545
|
if (index === -1) {
|
|
542
|
-
|
|
546
|
+
return Promise.reject({
|
|
547
|
+
code: types_1.TRTCMediaMixingErrorCode.NotFoundSource,
|
|
548
|
+
message: "Not existing media source to update"
|
|
549
|
+
});
|
|
543
550
|
}
|
|
544
551
|
const newMediaSource = Object.assign(Object.assign({}, this.sourceList[index]), (0, utils_1.safelyParse)(JSON.stringify(mediaSource)));
|
|
545
552
|
if (mediaSource.isSelected) {
|
|
@@ -553,6 +560,7 @@ class TRTCMediaMixingManager {
|
|
|
553
560
|
id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
|
|
554
561
|
rect: mediaSource.rect,
|
|
555
562
|
isSelected: mediaSource.isSelected || false,
|
|
563
|
+
zOrder: mediaSource.zOrder,
|
|
556
564
|
origin: (0, utils_1.safelyParse)(JSON.stringify(mediaSource))
|
|
557
565
|
});
|
|
558
566
|
this.sourceList[index] = newMediaSource;
|
|
@@ -639,30 +647,26 @@ class TRTCMediaMixingManager {
|
|
|
639
647
|
minVideoBitrate: 0,
|
|
640
648
|
enableAdjustRes: 0,
|
|
641
649
|
} }));
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
streamType: trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig,
|
|
652
|
-
}
|
|
653
|
-
}));
|
|
650
|
+
const encodeParamEx = {
|
|
651
|
+
videoWidth: this.mixingVideoWidth > this.mixingVideoHeight ? this.mixingVideoWidth : this.mixingVideoHeight,
|
|
652
|
+
videoHeight: this.mixingVideoWidth > this.mixingVideoHeight ? this.mixingVideoHeight : this.mixingVideoWidth,
|
|
653
|
+
videoFps: params.videoEncoderParams.videoFps,
|
|
654
|
+
videoBitrate: params.videoEncoderParams.videoBitrate,
|
|
655
|
+
gop: 1,
|
|
656
|
+
resolutionMode: params.videoEncoderParams.resMode,
|
|
657
|
+
streamType: trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig,
|
|
658
|
+
};
|
|
654
659
|
if (params.videoEncoderParams.colorRange !== undefined
|
|
655
660
|
|| params.videoEncoderParams.colorSpace !== undefined
|
|
656
661
|
|| params.videoEncoderParams.complexity !== undefined) {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
"colorRange": params.videoEncoderParams.colorRange || trtc_define_1.TRTCVideoColorRange.TRTCVideoColorRange_Auto,
|
|
661
|
-
"colorSpace": params.videoEncoderParams.colorSpace || trtc_define_1.TRTCVideoColorSpace.TRTCVideoColorSpace_Auto,
|
|
662
|
-
"complexity": params.videoEncoderParams.complexity || trtc_define_1.TRTCVideoEncodeComplexity.TRTCVideoEncodeComplexity_Fastest,
|
|
663
|
-
}
|
|
664
|
-
}));
|
|
662
|
+
encodeParamEx.colorRange = params.videoEncoderParams.colorRange || trtc_define_1.TRTCVideoColorRange.TRTCVideoColorRange_Auto;
|
|
663
|
+
encodeParamEx.colorSpace = params.videoEncoderParams.colorSpace || trtc_define_1.TRTCVideoColorSpace.TRTCVideoColorSpace_Auto;
|
|
664
|
+
encodeParamEx.complexity = params.videoEncoderParams.complexity || trtc_define_1.TRTCVideoEncodeComplexity.TRTCVideoEncodeComplexity_Fastest;
|
|
665
665
|
}
|
|
666
|
+
this.nodeMediaMixingPlugin.callExperimentalAPI(JSON.stringify({
|
|
667
|
+
api: 'setVideoEncodeParamEx',
|
|
668
|
+
params: encodeParamEx
|
|
669
|
+
}));
|
|
666
670
|
return result;
|
|
667
671
|
});
|
|
668
672
|
}
|
|
@@ -749,8 +753,7 @@ class TRTCMediaMixingManager {
|
|
|
749
753
|
this.paramsStore.streamLayout = undefined;
|
|
750
754
|
}
|
|
751
755
|
}
|
|
752
|
-
this.
|
|
753
|
-
let transferredUserList = layout.userList;
|
|
756
|
+
this.createOrUpdateLayoutManager(layout);
|
|
754
757
|
if (this.view) {
|
|
755
758
|
const viewRect = this.view.getBoundingClientRect();
|
|
756
759
|
if ((_a = layout.userList) === null || _a === void 0 ? void 0 : _a.length) {
|
|
@@ -764,26 +767,13 @@ class TRTCMediaMixingManager {
|
|
|
764
767
|
bottom: workingArea.bottom / viewRect.height,
|
|
765
768
|
}, localUser.fillMode);
|
|
766
769
|
}
|
|
767
|
-
transferredUserList = layout.userList.map((user) => {
|
|
768
|
-
if (user.rect) {
|
|
769
|
-
return Object.assign(Object.assign({}, user), { rect: {
|
|
770
|
-
left: user.rect.left * window.devicePixelRatio,
|
|
771
|
-
right: user.rect.right * window.devicePixelRatio,
|
|
772
|
-
top: user.rect.top * window.devicePixelRatio,
|
|
773
|
-
bottom: user.rect.bottom * window.devicePixelRatio,
|
|
774
|
-
} });
|
|
775
|
-
}
|
|
776
|
-
else {
|
|
777
|
-
return user;
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
770
|
logger_1.default.log(`${this.logPrefix}setStreamLayout transfer layout to pixel unit:`, JSON.stringify(layout));
|
|
781
771
|
}
|
|
782
772
|
}
|
|
783
773
|
else {
|
|
784
774
|
logger_1.default.warn(`${this.logPrefix}setStreamLayout: view is null, no container HTML element. User control the layout manually in device pixel unit.`);
|
|
785
775
|
}
|
|
786
|
-
(_c = this.streamLayoutManager) === null || _c === void 0 ? void 0 : _c.setLayout(
|
|
776
|
+
(_c = this.streamLayoutManager) === null || _c === void 0 ? void 0 : _c.setLayout(layout);
|
|
787
777
|
}
|
|
788
778
|
/**
|
|
789
779
|
* @private
|
|
@@ -846,6 +836,10 @@ class TRTCMediaMixingManager {
|
|
|
846
836
|
});
|
|
847
837
|
});
|
|
848
838
|
}
|
|
839
|
+
callExperimentalAPI(jsonStr) {
|
|
840
|
+
logger_1.default.debug(`${this.logPrefix}callExperimentalAPI:${jsonStr}`);
|
|
841
|
+
this.nodeMediaMixingPlugin.callExperimentalAPI(jsonStr);
|
|
842
|
+
}
|
|
849
843
|
/**
|
|
850
844
|
* 注册事件监听
|
|
851
845
|
*
|
|
@@ -919,6 +913,7 @@ class TRTCMediaMixingManager {
|
|
|
919
913
|
id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
|
|
920
914
|
rect: mediaSource.rect,
|
|
921
915
|
isSelected: mediaSource.isSelected || false,
|
|
916
|
+
zOrder: mediaSource.zOrder,
|
|
922
917
|
origin: mediaSource
|
|
923
918
|
});
|
|
924
919
|
}));
|
|
@@ -933,7 +928,7 @@ class TRTCMediaMixingManager {
|
|
|
933
928
|
this.mediaMixingDesigner = null;
|
|
934
929
|
}
|
|
935
930
|
}
|
|
936
|
-
|
|
931
|
+
createOrUpdateLayoutManager(layout) {
|
|
937
932
|
const context = {
|
|
938
933
|
container: this.view,
|
|
939
934
|
mixingVideoSize: {
|
|
@@ -1052,6 +1047,7 @@ class TRTCMediaMixingManager {
|
|
|
1052
1047
|
id: `${this.sourceList[index].sourceType}__${this.sourceList[index].sourceId}`,
|
|
1053
1048
|
rect: this.sourceList[index].rect,
|
|
1054
1049
|
isSelected: this.sourceList[index].isSelected || false,
|
|
1050
|
+
zOrder: this.sourceList[index].zOrder,
|
|
1055
1051
|
origin: (0, utils_1.safelyParse)(JSON.stringify(this.sourceList[index]))
|
|
1056
1052
|
});
|
|
1057
1053
|
});
|
|
@@ -1063,8 +1059,10 @@ class TRTCMediaMixingManager {
|
|
|
1063
1059
|
// To do: 待完善
|
|
1064
1060
|
switch (key) {
|
|
1065
1061
|
case "onMediaSourceAdded":
|
|
1062
|
+
this.onMediaSourceAdded(data);
|
|
1063
|
+
break;
|
|
1066
1064
|
case "onMediaSourceRemoved":
|
|
1067
|
-
this.
|
|
1065
|
+
this.onMediaSourceRemoved(data);
|
|
1068
1066
|
break;
|
|
1069
1067
|
case TRTCMediaMixingEvent.onMediaSourceSizeChanged:
|
|
1070
1068
|
this.onMediaSourceSizeChanged(data);
|
|
@@ -1083,18 +1081,64 @@ class TRTCMediaMixingManager {
|
|
|
1083
1081
|
break;
|
|
1084
1082
|
}
|
|
1085
1083
|
}
|
|
1086
|
-
|
|
1087
|
-
var _a;
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1084
|
+
onMediaSourceAdded(data) {
|
|
1085
|
+
var _a, _b;
|
|
1086
|
+
const promiseKey = `${promiseKeys.addMediaSource}-${data.sourceType}-${data.sourceId}`;
|
|
1087
|
+
let flag = false;
|
|
1088
|
+
if (data.errCode === 0) {
|
|
1089
|
+
flag = this.promiseStore.resolvePromise(promiseKey, undefined);
|
|
1091
1090
|
}
|
|
1092
1091
|
else {
|
|
1093
|
-
|
|
1094
|
-
|
|
1092
|
+
const newSourceIndex = this.findMediaSourceIndex({
|
|
1093
|
+
sourceId: data.sourceId,
|
|
1094
|
+
sourceType: data.sourceType,
|
|
1095
|
+
});
|
|
1096
|
+
if (newSourceIndex !== -1) {
|
|
1097
|
+
const newMediaSource = this.sourceList[newSourceIndex];
|
|
1098
|
+
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.removeMedia({
|
|
1099
|
+
id: `${newMediaSource.sourceType}__${newMediaSource.sourceId}`,
|
|
1100
|
+
rect: newMediaSource.rect,
|
|
1101
|
+
isSelected: newMediaSource.isSelected || false,
|
|
1102
|
+
zOrder: newMediaSource.zOrder,
|
|
1103
|
+
origin: newMediaSource
|
|
1104
|
+
});
|
|
1105
|
+
this.sourceList.splice(newSourceIndex, 1);
|
|
1106
|
+
}
|
|
1107
|
+
flag = this.promiseStore.rejectPromise(promiseKey, {
|
|
1108
|
+
code: data.errCode,
|
|
1109
|
+
message: data.errMsg,
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
if (data.errCode !== 0 && !flag) {
|
|
1113
|
+
// event triggered internally, not by method invoked by user
|
|
1114
|
+
const index = this.findMediaSourceIndex(data);
|
|
1115
|
+
let mediaSource = undefined;
|
|
1116
|
+
if (index !== -1) {
|
|
1117
|
+
mediaSource = Object.assign({}, this.sourceList[index]);
|
|
1118
|
+
}
|
|
1119
|
+
(_b = this.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(TRTCMediaMixingEvent.onError, data.errCode, data.errMsg, mediaSource);
|
|
1095
1120
|
}
|
|
1121
|
+
}
|
|
1122
|
+
onMediaSourceRemoved(data) {
|
|
1123
|
+
var _a, _b;
|
|
1124
|
+
const promiseKey = `${promiseKeys.removeMediaSource}-${data.sourceType}-${data.sourceId}`;
|
|
1096
1125
|
let flag = false;
|
|
1097
1126
|
if (data.errCode === 0) {
|
|
1127
|
+
const sourceIndex = this.findMediaSourceIndex({
|
|
1128
|
+
sourceId: data.sourceId,
|
|
1129
|
+
sourceType: data.sourceType
|
|
1130
|
+
});
|
|
1131
|
+
if (sourceIndex !== -1) {
|
|
1132
|
+
const mediaSource = this.sourceList[sourceIndex];
|
|
1133
|
+
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.removeMedia({
|
|
1134
|
+
id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
|
|
1135
|
+
rect: mediaSource.rect,
|
|
1136
|
+
isSelected: mediaSource.isSelected || false,
|
|
1137
|
+
zOrder: mediaSource.zOrder,
|
|
1138
|
+
origin: (0, utils_1.safelyParse)(JSON.stringify(mediaSource))
|
|
1139
|
+
});
|
|
1140
|
+
this.sourceList.splice(sourceIndex, 1);
|
|
1141
|
+
}
|
|
1098
1142
|
flag = this.promiseStore.resolvePromise(promiseKey, undefined);
|
|
1099
1143
|
}
|
|
1100
1144
|
else {
|
|
@@ -1110,7 +1154,7 @@ class TRTCMediaMixingManager {
|
|
|
1110
1154
|
if (index !== -1) {
|
|
1111
1155
|
mediaSource = Object.assign({}, this.sourceList[index]);
|
|
1112
1156
|
}
|
|
1113
|
-
(
|
|
1157
|
+
(_b = this.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(TRTCMediaMixingEvent.onError, data.errCode, data.errMsg, mediaSource);
|
|
1114
1158
|
}
|
|
1115
1159
|
}
|
|
1116
1160
|
onMediaSourceSizeChanged(data) {
|
|
@@ -1183,14 +1227,15 @@ class TRTCMediaMixingManager {
|
|
|
1183
1227
|
});
|
|
1184
1228
|
}
|
|
1185
1229
|
onMediaMixingServerLost() {
|
|
1186
|
-
var _a;
|
|
1230
|
+
var _a, _b;
|
|
1187
1231
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1188
1232
|
if (this.autoControlServer) {
|
|
1189
1233
|
yield this.recoverMediaMixingServer();
|
|
1190
1234
|
}
|
|
1191
1235
|
else {
|
|
1192
1236
|
this.sourceList = [];
|
|
1193
|
-
(_a = this.
|
|
1237
|
+
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.removeAllMedia();
|
|
1238
|
+
(_b = this.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(TRTCMediaMixingEvent.onMediaMixingServerLost);
|
|
1194
1239
|
}
|
|
1195
1240
|
});
|
|
1196
1241
|
}
|
|
@@ -1209,14 +1254,7 @@ class TRTCMediaMixingManager {
|
|
|
1209
1254
|
this.setStreamLayout(this.paramsStore.streamLayout);
|
|
1210
1255
|
}
|
|
1211
1256
|
this.sourceList.forEach((item) => {
|
|
1212
|
-
var _a;
|
|
1213
1257
|
this.nodeMediaMixingPlugin.addMediaSource(item);
|
|
1214
|
-
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.addMedia({
|
|
1215
|
-
id: `${item.sourceType}__${item.sourceId}`,
|
|
1216
|
-
rect: item.rect,
|
|
1217
|
-
isSelected: item.isSelected || false,
|
|
1218
|
-
origin: item
|
|
1219
|
-
});
|
|
1220
1258
|
});
|
|
1221
1259
|
if (((_b = this.trtcParamsStore) === null || _b === void 0 ? void 0 : _b.enterRoomParams) && ((_c = this.trtcParamsStore) === null || _c === void 0 ? void 0 : _c.enterRoomScene)) {
|
|
1222
1260
|
this.nodeTRTCCloud.enterRoom(this.trtcParamsStore.enterRoomParams, this.trtcParamsStore.enterRoomScene);
|
|
@@ -1228,6 +1266,10 @@ class TRTCMediaMixingManager {
|
|
|
1228
1266
|
}
|
|
1229
1267
|
});
|
|
1230
1268
|
}
|
|
1269
|
+
onDevicePixelRatioChange() {
|
|
1270
|
+
logger_1.default.debug(`${this.logPrefix}onDevicePixelRatioChange:`, window.devicePixelRatio);
|
|
1271
|
+
this.setDisplayRect();
|
|
1272
|
+
}
|
|
1231
1273
|
// ****** 这一部分接口暴露不合理,暂时不对暴露在 API 文档上 **************/
|
|
1232
1274
|
startCameraDeviceTest(windowID, rect) {
|
|
1233
1275
|
var _a;
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const types_1 = require("../types");
|
|
7
|
+
const DevicePixelRatioObserver_1 = __importDefault(require("../../../base/DevicePixelRatioObserver"));
|
|
7
8
|
const utils_1 = require("../../../utils");
|
|
8
9
|
const logger_1 = __importDefault(require("../../../logger"));
|
|
9
10
|
class BaseStreamLayoutManager {
|
|
@@ -33,6 +34,8 @@ class BaseStreamLayoutManager {
|
|
|
33
34
|
else {
|
|
34
35
|
logger_1.default.warn(`${this.logPrefix}constructor failed, no context.container.`);
|
|
35
36
|
}
|
|
37
|
+
this.onDevicePixelRatioChange = (0, utils_1.debounce)(this.onDevicePixelRatioChange.bind(this), 100);
|
|
38
|
+
DevicePixelRatioObserver_1.default.on('change', this.onDevicePixelRatioChange);
|
|
36
39
|
}
|
|
37
40
|
setLayout(layout) {
|
|
38
41
|
this.layout = layout;
|
|
@@ -58,6 +61,7 @@ class BaseStreamLayoutManager {
|
|
|
58
61
|
this.resizeObserver.disconnect();
|
|
59
62
|
this.resizeObserver = null;
|
|
60
63
|
}
|
|
64
|
+
DevicePixelRatioObserver_1.default.off('change', this.onDevicePixelRatioChange);
|
|
61
65
|
}
|
|
62
66
|
refreshLayout() {
|
|
63
67
|
logger_1.default.warn(`${this.logPrefix}refreshLayout should be implemented by sub-class.`);
|
|
@@ -102,5 +106,9 @@ class BaseStreamLayoutManager {
|
|
|
102
106
|
logger_1.default.warn(`${this.logPrefix}updateDisplayArea failed, no container.`);
|
|
103
107
|
}
|
|
104
108
|
}
|
|
109
|
+
onDevicePixelRatioChange() {
|
|
110
|
+
logger_1.default.debug(`${this.logPrefix}onDevicePixelRatioChange:`, window.devicePixelRatio);
|
|
111
|
+
this.refreshLayout();
|
|
112
|
+
}
|
|
105
113
|
}
|
|
106
114
|
exports.default = BaseStreamLayoutManager;
|
|
@@ -23,7 +23,23 @@ class CustomStreamLayoutManager extends BaseStreamLayoutManager_1.default {
|
|
|
23
23
|
refreshLayout() {
|
|
24
24
|
var _a;
|
|
25
25
|
if (this.layout.userList) {
|
|
26
|
-
this.
|
|
26
|
+
let transferredUserList = this.layout.userList;
|
|
27
|
+
if (this.container) {
|
|
28
|
+
transferredUserList = this.layout.userList.map((user) => {
|
|
29
|
+
if (user.rect) {
|
|
30
|
+
return Object.assign(Object.assign({}, user), { rect: {
|
|
31
|
+
left: user.rect.left * window.devicePixelRatio,
|
|
32
|
+
right: user.rect.right * window.devicePixelRatio,
|
|
33
|
+
top: user.rect.top * window.devicePixelRatio,
|
|
34
|
+
bottom: user.rect.bottom * window.devicePixelRatio,
|
|
35
|
+
} });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return user;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
this.nativeStreamLayoutManager.setStreamLayout(transferredUserList);
|
|
27
43
|
}
|
|
28
44
|
else if (this.layout.size && this.layout.streams) {
|
|
29
45
|
const userList = this.convertRelativeToAbsolute(this.layout);
|
package/liteav/trtc.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ declare class TRTCCloud extends EventEmitter {
|
|
|
20
20
|
private logger;
|
|
21
21
|
private id;
|
|
22
22
|
private static isIPCMode;
|
|
23
|
+
private static ipcModeReferenceCount;
|
|
23
24
|
private static sharedTRTCCloudInstance;
|
|
24
25
|
private static subInstances;
|
|
25
26
|
private stateStore;
|
|
@@ -1983,7 +1984,7 @@ declare class TRTCCloud extends EventEmitter {
|
|
|
1983
1984
|
* true // enable highlight
|
|
1984
1985
|
* );
|
|
1985
1986
|
*/
|
|
1986
|
-
selectScreenCaptureTarget(source: TRTCScreenCaptureSourceInfo | number, captureRect: Rect | string, property: TRTCScreenCaptureProperty | string, deprecatedCaptureRect?: Rect, captureMouse?: boolean, highlightWindow?: boolean):
|
|
1987
|
+
selectScreenCaptureTarget(source: TRTCScreenCaptureSourceInfo | number, captureRect: Rect | string, property: TRTCScreenCaptureProperty | string, deprecatedCaptureRect?: Rect, captureMouse?: boolean, highlightWindow?: boolean): void;
|
|
1987
1988
|
/**
|
|
1988
1989
|
* 启动屏幕分享,支持选择使用主路或辅路进行屏幕分享。
|
|
1989
1990
|
*
|
package/liteav/trtc.js
CHANGED
|
@@ -174,9 +174,11 @@ class TRTCCloud extends events_1.EventEmitter {
|
|
|
174
174
|
const newConfig = Object.assign({ jsVersion: pkg.version, componentNO }, config);
|
|
175
175
|
if (!TRTCCloud.isIPCMode) {
|
|
176
176
|
this.rtcCloud = new NodeTRTCEngine.NodeTRTCCloud(newConfig);
|
|
177
|
+
TRTCCloud.ipcModeReferenceCount = 0;
|
|
177
178
|
}
|
|
178
179
|
else {
|
|
179
180
|
this.rtcCloud = new NodeTRTCEngine.NodeRemoteTRTCCloud(newConfig);
|
|
181
|
+
TRTCCloud.ipcModeReferenceCount = 1;
|
|
180
182
|
}
|
|
181
183
|
this.stateStore = new Map();
|
|
182
184
|
this.videoRendererMap = new Map();
|
|
@@ -308,6 +310,7 @@ class TRTCCloud extends events_1.EventEmitter {
|
|
|
308
310
|
return null;
|
|
309
311
|
}
|
|
310
312
|
if (TRTCCloud.isIPCMode) {
|
|
313
|
+
TRTCCloud.ipcModeReferenceCount = TRTCCloud.ipcModeReferenceCount + 1;
|
|
311
314
|
return TRTCCloud.sharedTRTCCloudInstance;
|
|
312
315
|
}
|
|
313
316
|
return new TRTCCloud(config);
|
|
@@ -348,6 +351,12 @@ class TRTCCloud extends events_1.EventEmitter {
|
|
|
348
351
|
*/
|
|
349
352
|
destroy() {
|
|
350
353
|
var _a, _b;
|
|
354
|
+
if (TRTCCloud.isIPCMode) {
|
|
355
|
+
TRTCCloud.ipcModeReferenceCount = TRTCCloud.ipcModeReferenceCount - 1;
|
|
356
|
+
if (TRTCCloud.ipcModeReferenceCount > 0) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
351
360
|
if (this === TRTCCloud.sharedTRTCCloudInstance) {
|
|
352
361
|
if (TRTCCloud.subInstances) {
|
|
353
362
|
TRTCCloud.subInstances.forEach(sub => {
|
|
@@ -5261,7 +5270,7 @@ class TRTCCloud extends events_1.EventEmitter {
|
|
|
5261
5270
|
}
|
|
5262
5271
|
}
|
|
5263
5272
|
catch (error) {
|
|
5264
|
-
this.logger.warn(`callExperimentalAPI invalid JSON parameter`, error);
|
|
5273
|
+
this.logger.warn(`callExperimentalAPI invalid JSON parameter`, error, jsonStr);
|
|
5265
5274
|
}
|
|
5266
5275
|
}
|
|
5267
5276
|
/**
|