trtc-electron-sdk 12.2.115-beta.18 → 12.2.115-beta.21

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.
@@ -3,7 +3,7 @@ export declare type TRTCMediaInfo = {
3
3
  id: string;
4
4
  rect: Rect;
5
5
  isSelected: boolean;
6
- zOrder?: number;
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
- this.mediaList.unshift(media);
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
- const targetIndex = this.mediaList.findIndex(item => item.id === media.id);
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;
@@ -393,7 +393,7 @@ export declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
393
393
  private setDisplayRect;
394
394
  private createDesigner;
395
395
  private destroyDesigner;
396
- private createorUpdateLayoutManager;
396
+ private createOrUpdateLayoutManager;
397
397
  private destroyLayoutManager;
398
398
  private updateMixingVideoSize;
399
399
  private listenDesignerEvent;
@@ -409,13 +409,15 @@ export declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
409
409
  private findSelectedMediaSource;
410
410
  private unselectMediaSource;
411
411
  private handleCppCallbackEvent;
412
- private onMediaSourceAddedOrRemoved;
412
+ private onMediaSourceAdded;
413
+ private onMediaSourceRemoved;
413
414
  private onMediaSourceSizeChanged;
414
415
  private onPhoneMirrorSourceChanged;
415
416
  private onMediaServerState;
416
417
  private onMediaMixingServerLost;
417
418
  private onCallExperimentalAPIFinish;
418
419
  private recoverMediaMixingServer;
420
+ private onDevicePixelRatioChange;
419
421
  startCameraDeviceTest(windowID: number | Uint8Array, rect?: Rect): Promise<number>;
420
422
  stopCameraDeviceTest(): Promise<number>;
421
423
  setCameraTestRenderMirror(mirror: boolean): void;
@@ -20,6 +20,7 @@ const constant_1 = require("../../constant");
20
20
  const index_1 = __importDefault(require("../../MediaMixingDesigner/index"));
21
21
  const StreamLayout_1 = require("./StreamLayout");
22
22
  const PromiseStore_1 = __importDefault(require("../../base/PromiseStore"));
23
+ const DevicePixelRatioObserver_1 = __importDefault(require("../../base/DevicePixelRatioObserver"));
23
24
  const logger_1 = __importDefault(require("../../logger"));
24
25
  const NodeTRTCEngine = require('../../../build/Release/trtc_electron_sdk.node');
25
26
  /**
@@ -307,9 +308,12 @@ class TRTCMediaMixingManager {
307
308
  this.onPreviewAreaResize = this.onPreviewAreaResize.bind(this);
308
309
  this.onVisibilityChange = this.onVisibilityChange.bind(this);
309
310
  document.addEventListener('visibilitychange', this.onVisibilityChange);
311
+ this.onDevicePixelRatioChange = this.onDevicePixelRatioChange.bind(this);
312
+ DevicePixelRatioObserver_1.default.on('change', this.onDevicePixelRatioChange);
310
313
  }
311
314
  destroy() {
312
315
  return __awaiter(this, void 0, void 0, function* () {
316
+ DevicePixelRatioObserver_1.default.off('change', this.onDevicePixelRatioChange);
313
317
  document.removeEventListener('visibilitychange', this.onVisibilityChange);
314
318
  if (this.resizeObserver && this.view) {
315
319
  this.resizeObserver.unobserve(this.view);
@@ -498,6 +502,7 @@ class TRTCMediaMixingManager {
498
502
  id: `${newMediaSource.sourceType}__${newMediaSource.sourceId}`,
499
503
  rect: newMediaSource.rect,
500
504
  isSelected: newMediaSource.isSelected || false,
505
+ zOrder: newMediaSource.zOrder,
501
506
  origin: newMediaSource
502
507
  });
503
508
  this.sourceList.push(newMediaSource);
@@ -515,17 +520,9 @@ class TRTCMediaMixingManager {
515
520
  throw new Error("Not existing media source to remove");
516
521
  }
517
522
  return new Promise((resolve, reject) => {
518
- var _a;
519
523
  const key = `${promiseKeys.removeMediaSource}-${mediaSource.sourceType}-${mediaSource.sourceId}`;
520
524
  this.promiseStore.addPromise(key, resolve, reject);
521
525
  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
526
  });
530
527
  }
531
528
  /**
@@ -553,6 +550,7 @@ class TRTCMediaMixingManager {
553
550
  id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
554
551
  rect: mediaSource.rect,
555
552
  isSelected: mediaSource.isSelected || false,
553
+ zOrder: mediaSource.zOrder,
556
554
  origin: (0, utils_1.safelyParse)(JSON.stringify(mediaSource))
557
555
  });
558
556
  this.sourceList[index] = newMediaSource;
@@ -631,19 +629,34 @@ class TRTCMediaMixingManager {
631
629
  width: this.mixingVideoWidth,
632
630
  height: this.mixingVideoHeight
633
631
  });
634
- const result = yield this.nodeMediaMixingPlugin.updatePublishParams(params);
632
+ const result = yield this.nodeMediaMixingPlugin.updatePublishParams(Object.assign(Object.assign({}, params), { videoEncoderParams: {
633
+ videoResolution: 0,
634
+ resMode: 0,
635
+ videoFps: params.videoEncoderParams.videoFps,
636
+ videoBitrate: 0,
637
+ minVideoBitrate: 0,
638
+ enableAdjustRes: 0,
639
+ } }));
640
+ const encodeParamEx = {
641
+ videoWidth: this.mixingVideoWidth > this.mixingVideoHeight ? this.mixingVideoWidth : this.mixingVideoHeight,
642
+ videoHeight: this.mixingVideoWidth > this.mixingVideoHeight ? this.mixingVideoHeight : this.mixingVideoWidth,
643
+ videoFps: params.videoEncoderParams.videoFps,
644
+ videoBitrate: params.videoEncoderParams.videoBitrate,
645
+ gop: 1,
646
+ resolutionMode: params.videoEncoderParams.resMode,
647
+ streamType: trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig,
648
+ };
635
649
  if (params.videoEncoderParams.colorRange !== undefined
636
650
  || params.videoEncoderParams.colorSpace !== undefined
637
651
  || params.videoEncoderParams.complexity !== undefined) {
638
- this.nodeMediaMixingPlugin.callExperimentalAPI(JSON.stringify({
639
- "api": "setVideoEncodeParamEx",
640
- "params": {
641
- "colorRange": params.videoEncoderParams.colorRange || trtc_define_1.TRTCVideoColorRange.TRTCVideoColorRange_Auto,
642
- "colorSpace": params.videoEncoderParams.colorSpace || trtc_define_1.TRTCVideoColorSpace.TRTCVideoColorSpace_Auto,
643
- "complexity": params.videoEncoderParams.complexity || trtc_define_1.TRTCVideoEncodeComplexity.TRTCVideoEncodeComplexity_Fastest,
644
- }
645
- }));
652
+ encodeParamEx.colorRange = params.videoEncoderParams.colorRange || trtc_define_1.TRTCVideoColorRange.TRTCVideoColorRange_Auto;
653
+ encodeParamEx.colorSpace = params.videoEncoderParams.colorSpace || trtc_define_1.TRTCVideoColorSpace.TRTCVideoColorSpace_Auto;
654
+ encodeParamEx.complexity = params.videoEncoderParams.complexity || trtc_define_1.TRTCVideoEncodeComplexity.TRTCVideoEncodeComplexity_Fastest;
646
655
  }
656
+ this.nodeMediaMixingPlugin.callExperimentalAPI(JSON.stringify({
657
+ api: 'setVideoEncodeParamEx',
658
+ params: encodeParamEx
659
+ }));
647
660
  return result;
648
661
  });
649
662
  }
@@ -730,8 +743,7 @@ class TRTCMediaMixingManager {
730
743
  this.paramsStore.streamLayout = undefined;
731
744
  }
732
745
  }
733
- this.createorUpdateLayoutManager(layout);
734
- let transferredUserList = layout.userList;
746
+ this.createOrUpdateLayoutManager(layout);
735
747
  if (this.view) {
736
748
  const viewRect = this.view.getBoundingClientRect();
737
749
  if ((_a = layout.userList) === null || _a === void 0 ? void 0 : _a.length) {
@@ -745,26 +757,13 @@ class TRTCMediaMixingManager {
745
757
  bottom: workingArea.bottom / viewRect.height,
746
758
  }, localUser.fillMode);
747
759
  }
748
- transferredUserList = layout.userList.map((user) => {
749
- if (user.rect) {
750
- return Object.assign(Object.assign({}, user), { rect: {
751
- left: user.rect.left * window.devicePixelRatio,
752
- right: user.rect.right * window.devicePixelRatio,
753
- top: user.rect.top * window.devicePixelRatio,
754
- bottom: user.rect.bottom * window.devicePixelRatio,
755
- } });
756
- }
757
- else {
758
- return user;
759
- }
760
- });
761
760
  logger_1.default.log(`${this.logPrefix}setStreamLayout transfer layout to pixel unit:`, JSON.stringify(layout));
762
761
  }
763
762
  }
764
763
  else {
765
764
  logger_1.default.warn(`${this.logPrefix}setStreamLayout: view is null, no container HTML element. User control the layout manually in device pixel unit.`);
766
765
  }
767
- (_c = this.streamLayoutManager) === null || _c === void 0 ? void 0 : _c.setLayout(Object.assign(Object.assign({}, layout), { userList: transferredUserList }));
766
+ (_c = this.streamLayoutManager) === null || _c === void 0 ? void 0 : _c.setLayout(layout);
768
767
  }
769
768
  /**
770
769
  * @private
@@ -900,6 +899,7 @@ class TRTCMediaMixingManager {
900
899
  id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
901
900
  rect: mediaSource.rect,
902
901
  isSelected: mediaSource.isSelected || false,
902
+ zOrder: mediaSource.zOrder,
903
903
  origin: mediaSource
904
904
  });
905
905
  }));
@@ -914,7 +914,7 @@ class TRTCMediaMixingManager {
914
914
  this.mediaMixingDesigner = null;
915
915
  }
916
916
  }
917
- createorUpdateLayoutManager(layout) {
917
+ createOrUpdateLayoutManager(layout) {
918
918
  const context = {
919
919
  container: this.view,
920
920
  mixingVideoSize: {
@@ -1033,6 +1033,7 @@ class TRTCMediaMixingManager {
1033
1033
  id: `${this.sourceList[index].sourceType}__${this.sourceList[index].sourceId}`,
1034
1034
  rect: this.sourceList[index].rect,
1035
1035
  isSelected: this.sourceList[index].isSelected || false,
1036
+ zOrder: this.sourceList[index].zOrder,
1036
1037
  origin: (0, utils_1.safelyParse)(JSON.stringify(this.sourceList[index]))
1037
1038
  });
1038
1039
  });
@@ -1044,8 +1045,10 @@ class TRTCMediaMixingManager {
1044
1045
  // To do: 待完善
1045
1046
  switch (key) {
1046
1047
  case "onMediaSourceAdded":
1048
+ this.onMediaSourceAdded(data);
1049
+ break;
1047
1050
  case "onMediaSourceRemoved":
1048
- this.onMediaSourceAddedOrRemoved(key, data);
1051
+ this.onMediaSourceRemoved(data);
1049
1052
  break;
1050
1053
  case TRTCMediaMixingEvent.onMediaSourceSizeChanged:
1051
1054
  this.onMediaSourceSizeChanged(data);
@@ -1064,18 +1067,64 @@ class TRTCMediaMixingManager {
1064
1067
  break;
1065
1068
  }
1066
1069
  }
1067
- onMediaSourceAddedOrRemoved(key, data) {
1068
- var _a;
1069
- let promiseKey;
1070
- if (key === "onMediaSourceAdded") {
1071
- promiseKey = `${promiseKeys.addMediaSource}-${data.sourceType}-${data.sourceId}`;
1070
+ onMediaSourceAdded(data) {
1071
+ var _a, _b;
1072
+ const promiseKey = `${promiseKeys.addMediaSource}-${data.sourceType}-${data.sourceId}`;
1073
+ let flag = false;
1074
+ if (data.errCode === 0) {
1075
+ flag = this.promiseStore.resolvePromise(promiseKey, undefined);
1072
1076
  }
1073
1077
  else {
1074
- // 'onMediaSourceRemoved'
1075
- promiseKey = `${promiseKeys.removeMediaSource}-${data.sourceType}-${data.sourceId}`;
1078
+ const newSourceIndex = this.findMediaSourceIndex({
1079
+ sourceId: data.sourceId,
1080
+ sourceType: data.sourceType,
1081
+ });
1082
+ if (newSourceIndex !== -1) {
1083
+ const newMediaSource = this.sourceList[newSourceIndex];
1084
+ (_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.removeMedia({
1085
+ id: `${newMediaSource.sourceType}__${newMediaSource.sourceId}`,
1086
+ rect: newMediaSource.rect,
1087
+ isSelected: newMediaSource.isSelected || false,
1088
+ zOrder: newMediaSource.zOrder,
1089
+ origin: newMediaSource
1090
+ });
1091
+ this.sourceList.splice(newSourceIndex, 1);
1092
+ }
1093
+ flag = this.promiseStore.rejectPromise(promiseKey, {
1094
+ code: data.errCode,
1095
+ message: data.errMsg,
1096
+ });
1097
+ }
1098
+ if (data.errCode !== 0 && !flag) {
1099
+ // event triggered internally, not by method invoked by user
1100
+ const index = this.findMediaSourceIndex(data);
1101
+ let mediaSource = undefined;
1102
+ if (index !== -1) {
1103
+ mediaSource = Object.assign({}, this.sourceList[index]);
1104
+ }
1105
+ (_b = this.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(TRTCMediaMixingEvent.onError, data.errCode, data.errMsg, mediaSource);
1076
1106
  }
1107
+ }
1108
+ onMediaSourceRemoved(data) {
1109
+ var _a, _b;
1110
+ const promiseKey = `${promiseKeys.removeMediaSource}-${data.sourceType}-${data.sourceId}`;
1077
1111
  let flag = false;
1078
1112
  if (data.errCode === 0) {
1113
+ const sourceIndex = this.findMediaSourceIndex({
1114
+ sourceId: data.sourceId,
1115
+ sourceType: data.sourceType
1116
+ });
1117
+ if (sourceIndex !== -1) {
1118
+ const mediaSource = this.sourceList[sourceIndex];
1119
+ (_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.removeMedia({
1120
+ id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
1121
+ rect: mediaSource.rect,
1122
+ isSelected: mediaSource.isSelected || false,
1123
+ zOrder: mediaSource.zOrder,
1124
+ origin: (0, utils_1.safelyParse)(JSON.stringify(mediaSource))
1125
+ });
1126
+ this.sourceList.splice(sourceIndex, 1);
1127
+ }
1079
1128
  flag = this.promiseStore.resolvePromise(promiseKey, undefined);
1080
1129
  }
1081
1130
  else {
@@ -1091,7 +1140,7 @@ class TRTCMediaMixingManager {
1091
1140
  if (index !== -1) {
1092
1141
  mediaSource = Object.assign({}, this.sourceList[index]);
1093
1142
  }
1094
- (_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(TRTCMediaMixingEvent.onError, data.errCode, data.errMsg, mediaSource);
1143
+ (_b = this.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(TRTCMediaMixingEvent.onError, data.errCode, data.errMsg, mediaSource);
1095
1144
  }
1096
1145
  }
1097
1146
  onMediaSourceSizeChanged(data) {
@@ -1164,14 +1213,15 @@ class TRTCMediaMixingManager {
1164
1213
  });
1165
1214
  }
1166
1215
  onMediaMixingServerLost() {
1167
- var _a;
1216
+ var _a, _b;
1168
1217
  return __awaiter(this, void 0, void 0, function* () {
1169
1218
  if (this.autoControlServer) {
1170
1219
  yield this.recoverMediaMixingServer();
1171
1220
  }
1172
1221
  else {
1173
1222
  this.sourceList = [];
1174
- (_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(TRTCMediaMixingEvent.onMediaMixingServerLost);
1223
+ (_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.removeAllMedia();
1224
+ (_b = this.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(TRTCMediaMixingEvent.onMediaMixingServerLost);
1175
1225
  }
1176
1226
  });
1177
1227
  }
@@ -1190,14 +1240,7 @@ class TRTCMediaMixingManager {
1190
1240
  this.setStreamLayout(this.paramsStore.streamLayout);
1191
1241
  }
1192
1242
  this.sourceList.forEach((item) => {
1193
- var _a;
1194
1243
  this.nodeMediaMixingPlugin.addMediaSource(item);
1195
- (_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.addMedia({
1196
- id: `${item.sourceType}__${item.sourceId}`,
1197
- rect: item.rect,
1198
- isSelected: item.isSelected || false,
1199
- origin: item
1200
- });
1201
1244
  });
1202
1245
  if (((_b = this.trtcParamsStore) === null || _b === void 0 ? void 0 : _b.enterRoomParams) && ((_c = this.trtcParamsStore) === null || _c === void 0 ? void 0 : _c.enterRoomScene)) {
1203
1246
  this.nodeTRTCCloud.enterRoom(this.trtcParamsStore.enterRoomParams, this.trtcParamsStore.enterRoomScene);
@@ -1209,6 +1252,10 @@ class TRTCMediaMixingManager {
1209
1252
  }
1210
1253
  });
1211
1254
  }
1255
+ onDevicePixelRatioChange() {
1256
+ logger_1.default.debug(`${this.logPrefix}onDevicePixelRatioChange:`, window.devicePixelRatio);
1257
+ this.setDisplayRect();
1258
+ }
1212
1259
  // ****** 这一部分接口暴露不合理,暂时不对暴露在 API 文档上 **************/
1213
1260
  startCameraDeviceTest(windowID, rect) {
1214
1261
  var _a;
@@ -27,5 +27,6 @@ declare class BaseStreamLayoutManager implements ITRTCStreamLayoutManager {
27
27
  private onResize;
28
28
  private setResizeObserver;
29
29
  private updateDisplayArea;
30
+ private onDevicePixelRatioChange;
30
31
  }
31
32
  export default BaseStreamLayoutManager;
@@ -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.nativeStreamLayoutManager.setStreamLayout(this.layout.userList);
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;
@@ -98,11 +99,11 @@ declare class TRTCCloud extends EventEmitter {
98
99
  * rtcCloud.startLocalAudio(); // 主实例开启麦克风采集
99
100
  *
100
101
  * const childRtcCloud = rtcCloud.createSubCloud();
101
- * childRtcCloud.startSystemAudioLoopback(); // 子实例开启系统音采集
102
+ * childRtcCloud?.startSystemAudioLoopback(); // 子实例开启系统音采集
102
103
  *
103
- * @returns {TRTCCloud}
104
+ * @returns {TRTCCloud|null}
104
105
  */
105
- createSubCloud(config?: TRTCInitConfig): TRTCCloud;
106
+ createSubCloud(config?: TRTCInitConfig): TRTCCloud | null;
106
107
  /**
107
108
  * 获取 TRTC 配置对象
108
109
  *
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();
@@ -298,16 +300,18 @@ class TRTCCloud extends events_1.EventEmitter {
298
300
  * rtcCloud.startLocalAudio(); // 主实例开启麦克风采集
299
301
  *
300
302
  * const childRtcCloud = rtcCloud.createSubCloud();
301
- * childRtcCloud.startSystemAudioLoopback(); // 子实例开启系统音采集
303
+ * childRtcCloud?.startSystemAudioLoopback(); // 子实例开启系统音采集
302
304
  *
303
- * @returns {TRTCCloud}
305
+ * @returns {TRTCCloud|null}
304
306
  */
305
307
  createSubCloud(config) {
306
308
  if (this !== TRTCCloud.sharedTRTCCloudInstance) {
307
- throw new Error("createSubCloud() can only be called on the main instance created by getTRTCShareInstance().");
309
+ this.logger.warn("createSubCloud() can only be called on the main instance created by getTRTCShareInstance().");
310
+ return null;
308
311
  }
309
312
  if (TRTCCloud.isIPCMode) {
310
- throw new Error("createSubCloud() is not supported when `isIPCMode` is true.");
313
+ TRTCCloud.ipcModeReferenceCount = TRTCCloud.ipcModeReferenceCount + 1;
314
+ return TRTCCloud.sharedTRTCCloudInstance;
311
315
  }
312
316
  return new TRTCCloud(config);
313
317
  }
@@ -347,6 +351,12 @@ class TRTCCloud extends events_1.EventEmitter {
347
351
  */
348
352
  destroy() {
349
353
  var _a, _b;
354
+ if (TRTCCloud.isIPCMode) {
355
+ TRTCCloud.ipcModeReferenceCount = TRTCCloud.ipcModeReferenceCount - 1;
356
+ if (TRTCCloud.ipcModeReferenceCount > 0) {
357
+ return;
358
+ }
359
+ }
350
360
  if (this === TRTCCloud.sharedTRTCCloudInstance) {
351
361
  if (TRTCCloud.subInstances) {
352
362
  TRTCCloud.subInstances.forEach(sub => {
@@ -5260,7 +5270,7 @@ class TRTCCloud extends events_1.EventEmitter {
5260
5270
  }
5261
5271
  }
5262
5272
  catch (error) {
5263
- this.logger.warn(`callExperimentalAPI invalid JSON parameter`, error);
5273
+ this.logger.warn(`callExperimentalAPI invalid JSON parameter`, error, jsonStr);
5264
5274
  }
5265
5275
  }
5266
5276
  /**
@@ -25,7 +25,8 @@ export declare enum TRTCVideoResolution {
25
25
  TRTCVideoResolution_640_360 = 108,
26
26
  TRTCVideoResolution_960_540 = 110,
27
27
  TRTCVideoResolution_1280_720 = 112,
28
- TRTCVideoResolution_1920_1080 = 114
28
+ TRTCVideoResolution_1920_1080 = 114,
29
+ TRTCVideoResolution_2560_1440 = 116
29
30
  }
30
31
  export declare enum TRTCVideoResolutionMode {
31
32
  TRTCVideoResolutionModeLandscape = 0,
@@ -22,52 +22,48 @@ const util_1 = require("./Renderer/util");
22
22
  * @enum {Number}
23
23
  */
24
24
  const TRTCVideoResolution_HACK_JSDOC = {
25
- /// 宽高比1:1
26
- /** [C] 建议码率80kbps */
25
+ /** 宽高比 1:1;分辨率 120x120;建议码率(VideoCall)80kbps; 建议码率(LIVE)120kbps。 */
27
26
  TRTCVideoResolution_120_120: 1,
28
- /** [C] 建议码率100kbps */
27
+ /** 宽高比 1:1 分辨率 160x160;建议码率(VideoCall)100kbps; 建议码率(LIVE)150kbps。 */
29
28
  TRTCVideoResolution_160_160: 3,
30
- /** [C] 建议码率200kbps */
29
+ /** 宽高比 1:1;分辨率 270x270;建议码率(VideoCall)200kbps; 建议码率(LIVE)300kbps。 */
31
30
  TRTCVideoResolution_270_270: 5,
32
- /** [C] 建议码率350kbps */
31
+ /** 宽高比 1:1;分辨率 480x480;建议码率(VideoCall)350kbps; 建议码率(LIVE)500kbps。 */
33
32
  TRTCVideoResolution_480_480: 7,
34
- /// 宽高比4:3
35
- /** [C] 建议码率100kbps */
33
+ /** 宽高比4:3;分辨率 160x120;建议码率(VideoCall)100kbps; 建议码率(LIVE)150kbps。 */
36
34
  TRTCVideoResolution_160_120: 50,
37
- /** [C] 建议码率150kbps */
35
+ /** 宽高比 4:3;分辨率 240x180;建议码率(VideoCall)150kbps; 建议码率(LIVE)250kbps。 */
38
36
  TRTCVideoResolution_240_180: 52,
39
- /** [C] 建议码率200kbps */
37
+ /** 宽高比 4:3;分辨率 280x210;建议码率(VideoCall)200kbps; 建议码率(LIVE)300kbps。 */
40
38
  TRTCVideoResolution_280_210: 54,
41
- /** [C] 建议码率250kbps */
39
+ /** 宽高比 4:3;分辨率 320x240;建议码率(VideoCall)250kbps; 建议码率(LIVE)375kbps。 */
42
40
  TRTCVideoResolution_320_240: 56,
43
- /** [C] 建议码率300kbps */
41
+ /** 宽高比 4:3;分辨率 400x300;建议码率(VideoCall)300kbps; 建议码率(LIVE)450kbps。 */
44
42
  TRTCVideoResolution_400_300: 58,
45
- /** [C] 建议码率400kbps */
43
+ /** 宽高比 4:3;分辨率 480x360;建议码率(VideoCall)400kbps; 建议码率(LIVE)600kbps。 */
46
44
  TRTCVideoResolution_480_360: 60,
47
- /** [C] 建议码率600kbps */
45
+ /** 宽高比 4:3;分辨率 640x480;建议码率(VideoCall)600kbps; 建议码率(LIVE)900kbps。 */
48
46
  TRTCVideoResolution_640_480: 62,
49
- /** [C] 建议码率1000kbps */
47
+ /** 宽高比 4:3;分辨率 960x720;建议码率(VideoCall)1000kbps; 建议码率(LIVE)1500kbps。 */
50
48
  TRTCVideoResolution_960_720: 64,
51
- /// 宽高比16:9
52
- /** [C] 建议码率150kbps */
49
+ /** 宽高比 16:9;分辨率 160x90;建议码率(VideoCall)150kbps; 建议码率(LIVE)250kbps。*/
53
50
  TRTCVideoResolution_160_90: 100,
54
- /** [C] 建议码率200kbps */
51
+ /** 宽高比 16:9;分辨率 256x144;建议码率(VideoCall)200kbps; 建议码率(LIVE)300kbps。 */
55
52
  TRTCVideoResolution_256_144: 102,
56
- /** [C] 建议码率250kbps */
53
+ /** 宽高比 16:9;分辨率 320x180;建议码率(VideoCall)250kbps; 建议码率(LIVE)400kbps。 */
57
54
  TRTCVideoResolution_320_180: 104,
58
- /** [C] 建议码率350kbps */
55
+ /**宽高比 16:9;分辨率 480x270;建议码率(VideoCall)350kbps; 建议码率(LIVE)550kbps。 */
59
56
  TRTCVideoResolution_480_270: 106,
60
- /** [C] 建议码率550kbps */
57
+ /** 宽高比 16:9;分辨率 640x360;建议码率(VideoCall)500kbps; 建议码率(LIVE)900kbps。 */
61
58
  TRTCVideoResolution_640_360: 108,
62
- /** [C] 建议码率850kbps */
59
+ /** 宽高比 16:9;分辨率 960x540;建议码率(VideoCall)850kbps; 建议码率(LIVE)1300kbps。 */
63
60
  TRTCVideoResolution_960_540: 110,
64
- /**
65
- * [C] 摄像头采集 - 建议码率1200kbps<br>
66
- * [S] 屏幕分享 - 建议码率 低清:1000kbps 高清:1600kbps
67
- */
61
+ /** 宽高比 16:9;分辨率 1280x720;建议码率(VideoCall)1200kbps; 建议码率(LIVE)1800kbps。 */
68
62
  TRTCVideoResolution_1280_720: 112,
69
- /** [S] 屏幕分享 - 建议码率2000kbps */
63
+ /** 宽高比 16:9;分辨率 1920x1080;建议码率(VideoCall)2000kbps; 建议码率(LIVE)3000kbps。 */
70
64
  TRTCVideoResolution_1920_1080: 114,
65
+ /** 宽高比 16:9;分辨率 2560x1440;建议码率(VideoCall)4000kbps; 建议码率(LIVE)6000kbps。 */
66
+ TRTCVideoResolution_2560_1440: 116,
71
67
  };
72
68
  var TRTCVideoResolution;
73
69
  (function (TRTCVideoResolution) {
@@ -91,6 +87,7 @@ var TRTCVideoResolution;
91
87
  TRTCVideoResolution[TRTCVideoResolution["TRTCVideoResolution_960_540"] = 110] = "TRTCVideoResolution_960_540";
92
88
  TRTCVideoResolution[TRTCVideoResolution["TRTCVideoResolution_1280_720"] = 112] = "TRTCVideoResolution_1280_720";
93
89
  TRTCVideoResolution[TRTCVideoResolution["TRTCVideoResolution_1920_1080"] = 114] = "TRTCVideoResolution_1920_1080";
90
+ TRTCVideoResolution[TRTCVideoResolution["TRTCVideoResolution_2560_1440"] = 116] = "TRTCVideoResolution_2560_1440";
94
91
  })(TRTCVideoResolution = exports.TRTCVideoResolution || (exports.TRTCVideoResolution = {}));
95
92
  /**
96
93
  * 视频分辨率模式
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trtc-electron-sdk",
3
- "version": "12.2.115-beta.18",
3
+ "version": "12.2.115-beta.21",
4
4
  "description": "trtc electron sdk",
5
5
  "main": "./liteav/index.js",
6
6
  "types": "./liteav/index.d.ts",