trtc-electron-sdk 12.7.706-beta.1 → 12.7.706-beta.3

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.
@@ -234,6 +234,7 @@ export declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
234
234
  * @returns {Promise<void>}
235
235
  */
236
236
  removeMediaSource(mediaSource: TRTCMediaSource): Promise<void>;
237
+ private syncRemoveMediaSource;
237
238
  /**
238
239
  * 更新本地混流媒体源
239
240
  * @param mediaSource {TRTCMediaSource} - 媒体源信息
@@ -388,7 +389,8 @@ export declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
388
389
  * @param func {Function} - 事件回调函数
389
390
  */
390
391
  off(event: TRTCMediaMixingEvent, func: (...args: any[]) => void): void;
391
- private initResizeObserver;
392
+ private createResizeObserver;
393
+ private destroyResizeObserver;
392
394
  private onPreviewAreaResize;
393
395
  private onVisibilityChange;
394
396
  private setDisplayRect;
@@ -316,10 +316,8 @@ class TRTCMediaMixingManager {
316
316
  return __awaiter(this, void 0, void 0, function* () {
317
317
  DevicePixelRatioObserver_1.default.off('change', this.onDevicePixelRatioChange);
318
318
  document.removeEventListener('visibilitychange', this.onVisibilityChange);
319
- if (this.resizeObserver && this.view) {
320
- this.resizeObserver.unobserve(this.view);
321
- this.resizeObserver.disconnect();
322
- }
319
+ this.destroyResizeObserver();
320
+ this.destroyLayoutManager();
323
321
  this.view = null;
324
322
  this.windowID = 0;
325
323
  this.destroyDesigner();
@@ -453,7 +451,7 @@ class TRTCMediaMixingManager {
453
451
  this.destroyDesigner();
454
452
  this.view = viewOrRegion;
455
453
  this.setDisplayRect();
456
- this.initResizeObserver();
454
+ this.createResizeObserver();
457
455
  this.createDesigner();
458
456
  }
459
457
  else {
@@ -471,8 +469,10 @@ class TRTCMediaMixingManager {
471
469
  }
472
470
  }
473
471
  else {
472
+ this.destroyResizeObserver();
474
473
  this.destroyLayoutManager();
475
474
  this.destroyDesigner();
475
+ this.view = null;
476
476
  this.nodeMediaMixingPlugin.setDisplayParams(realWindowID, { left: 0, right: 0, top: 0, bottom: 0 });
477
477
  }
478
478
  }
@@ -518,6 +518,7 @@ class TRTCMediaMixingManager {
518
518
  * @returns {Promise<void>}
519
519
  */
520
520
  removeMediaSource(mediaSource) {
521
+ var _a;
521
522
  logger_1.default.log(`${this.logPrefix}removeMediaSource:`, mediaSource);
522
523
  const index = this.findMediaSourceIndex(mediaSource);
523
524
  if (index === -1) {
@@ -526,11 +527,37 @@ class TRTCMediaMixingManager {
526
527
  message: "Not existing media source to remove"
527
528
  });
528
529
  }
529
- return new Promise((resolve, reject) => {
530
- const key = `${promiseKeys.removeMediaSource}-${mediaSource.sourceType}-${mediaSource.sourceId}`;
531
- this.promiseStore.addPromise(key, resolve, reject);
530
+ else {
531
+ const mediaSourceToDelete = this.sourceList[index];
532
+ if ((_a = mediaSourceToDelete === null || mediaSourceToDelete === void 0 ? void 0 : mediaSourceToDelete.control) === null || _a === void 0 ? void 0 : _a.isAddFailed) {
533
+ this.syncRemoveMediaSource(mediaSource, index);
534
+ return Promise.resolve();
535
+ }
536
+ else {
537
+ return new Promise((resolve, reject) => {
538
+ const key = `${promiseKeys.removeMediaSource}-${mediaSource.sourceType}-${mediaSource.sourceId}`;
539
+ this.promiseStore.addPromise(key, resolve, reject);
540
+ this.syncRemoveMediaSource(mediaSource, index);
541
+ });
542
+ }
543
+ }
544
+ }
545
+ syncRemoveMediaSource(mediaSource, index) {
546
+ var _a;
547
+ try {
532
548
  this.nodeMediaMixingPlugin.removeMediaSource(mediaSource);
533
- });
549
+ (_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.removeMedia({
550
+ id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
551
+ rect: mediaSource.rect,
552
+ isSelected: mediaSource.isSelected || false,
553
+ zOrder: mediaSource.zOrder,
554
+ origin: (0, utils_1.safelyParse)(JSON.stringify(mediaSource))
555
+ });
556
+ this.sourceList.splice(index, 1);
557
+ }
558
+ catch (error) {
559
+ logger_1.default.warn(`${this.logPrefix}removeMediaSource exception:`, error);
560
+ }
534
561
  }
535
562
  /**
536
563
  * 更新本地混流媒体源
@@ -744,7 +771,7 @@ class TRTCMediaMixingManager {
744
771
  */
745
772
  setStreamLayout(layout) {
746
773
  var _a, _b, _c;
747
- logger_1.default.log(`${this.logPrefix}setStreamLayout:`, layout);
774
+ logger_1.default.debug(`${this.logPrefix}setStreamLayout:`, JSON.stringify(layout));
748
775
  if (this.paramsStore) {
749
776
  try {
750
777
  this.paramsStore.streamLayout = JSON.parse(JSON.stringify(layout));
@@ -753,8 +780,8 @@ class TRTCMediaMixingManager {
753
780
  this.paramsStore.streamLayout = undefined;
754
781
  }
755
782
  }
756
- this.createOrUpdateLayoutManager(layout);
757
783
  if (this.view) {
784
+ this.createOrUpdateLayoutManager(layout);
758
785
  const viewRect = this.view.getBoundingClientRect();
759
786
  if ((_a = layout.userList) === null || _a === void 0 ? void 0 : _a.length) {
760
787
  const localUser = layout.userList.filter(user => user.userId === constant_1.LOCAL_USER_ID)[0];
@@ -767,7 +794,6 @@ class TRTCMediaMixingManager {
767
794
  bottom: workingArea.bottom / viewRect.height,
768
795
  }, localUser.fillMode);
769
796
  }
770
- logger_1.default.log(`${this.logPrefix}setStreamLayout transfer layout to pixel unit:`, JSON.stringify(layout));
771
797
  }
772
798
  }
773
799
  else {
@@ -860,12 +886,20 @@ class TRTCMediaMixingManager {
860
886
  var _a;
861
887
  (_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.off(event, func);
862
888
  }
863
- initResizeObserver() {
889
+ createResizeObserver() {
864
890
  if (this.view) {
865
891
  this.resizeObserver = new ResizeObserver(this.onPreviewAreaResize);
866
892
  this.resizeObserver.observe(this.view);
867
893
  }
868
894
  }
895
+ destroyResizeObserver() {
896
+ if (this.resizeObserver) {
897
+ if (this.view) {
898
+ this.resizeObserver.unobserve(this.view);
899
+ }
900
+ this.resizeObserver.disconnect();
901
+ }
902
+ }
869
903
  onPreviewAreaResize(entries) {
870
904
  logger_1.default.log(`${this.logPrefix}onPreviewAreaResize:`, entries);
871
905
  for (const entry of entries) {
@@ -893,6 +927,7 @@ class TRTCMediaMixingManager {
893
927
  top: clientRect.top * window.devicePixelRatio,
894
928
  bottom: clientRect.bottom * window.devicePixelRatio,
895
929
  };
930
+ logger_1.default.debug(`${this.logPrefix}setDisplayRect:`, this.windowID, rect);
896
931
  this.nodeMediaMixingPlugin.setDisplayParams(this.windowID, rect);
897
932
  }
898
933
  }
@@ -1082,7 +1117,7 @@ class TRTCMediaMixingManager {
1082
1117
  }
1083
1118
  }
1084
1119
  onMediaSourceAdded(data) {
1085
- var _a, _b;
1120
+ var _a;
1086
1121
  const promiseKey = `${promiseKeys.addMediaSource}-${data.sourceType}-${data.sourceId}`;
1087
1122
  let flag = false;
1088
1123
  if (data.errCode === 0) {
@@ -1095,14 +1130,10 @@ class TRTCMediaMixingManager {
1095
1130
  });
1096
1131
  if (newSourceIndex !== -1) {
1097
1132
  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);
1133
+ if (!newMediaSource.control) {
1134
+ newMediaSource.control = {};
1135
+ }
1136
+ newMediaSource.control.isAddFailed = true;
1106
1137
  }
1107
1138
  flag = this.promiseStore.rejectPromise(promiseKey, {
1108
1139
  code: data.errCode,
@@ -1116,29 +1147,14 @@ class TRTCMediaMixingManager {
1116
1147
  if (index !== -1) {
1117
1148
  mediaSource = Object.assign({}, this.sourceList[index]);
1118
1149
  }
1119
- (_b = this.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(TRTCMediaMixingEvent.onError, data.errCode, data.errMsg, mediaSource);
1150
+ (_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(TRTCMediaMixingEvent.onError, data.errCode, data.errMsg, mediaSource);
1120
1151
  }
1121
1152
  }
1122
1153
  onMediaSourceRemoved(data) {
1123
- var _a, _b;
1154
+ var _a;
1124
1155
  const promiseKey = `${promiseKeys.removeMediaSource}-${data.sourceType}-${data.sourceId}`;
1125
1156
  let flag = false;
1126
1157
  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
- }
1142
1158
  flag = this.promiseStore.resolvePromise(promiseKey, undefined);
1143
1159
  }
1144
1160
  else {
@@ -1154,7 +1170,7 @@ class TRTCMediaMixingManager {
1154
1170
  if (index !== -1) {
1155
1171
  mediaSource = Object.assign({}, this.sourceList[index]);
1156
1172
  }
1157
- (_b = this.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(TRTCMediaMixingEvent.onError, data.errCode, data.errMsg, mediaSource);
1173
+ (_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(TRTCMediaMixingEvent.onError, data.errCode, data.errMsg, mediaSource);
1158
1174
  }
1159
1175
  }
1160
1176
  onMediaSourceSizeChanged(data) {
@@ -28,10 +28,10 @@ class CustomStreamLayoutManager extends BaseStreamLayoutManager_1.default {
28
28
  transferredUserList = this.layout.userList.map((user) => {
29
29
  if (user.rect) {
30
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,
31
+ left: Math.round(user.rect.left * window.devicePixelRatio),
32
+ right: Math.round(user.rect.right * window.devicePixelRatio),
33
+ top: Math.round(user.rect.top * window.devicePixelRatio),
34
+ bottom: Math.round(user.rect.bottom * window.devicePixelRatio),
35
35
  } });
36
36
  }
37
37
  else {
@@ -39,6 +39,7 @@ class CustomStreamLayoutManager extends BaseStreamLayoutManager_1.default {
39
39
  }
40
40
  });
41
41
  }
42
+ logger_1.default.debug(`${this.logPrefix}refreshLayout:`, JSON.stringify(transferredUserList));
42
43
  this.nativeStreamLayoutManager.setStreamLayout(transferredUserList);
43
44
  }
44
45
  else if (this.layout.size && this.layout.streams) {
@@ -29,6 +29,7 @@ class NoneStreamLayoutManager extends BaseStreamLayoutManager_1.default {
29
29
  bottom: workingArea.bottom / this.displayArea.height / window.devicePixelRatio,
30
30
  }, this.layout.userList[0].fillMode);
31
31
  }
32
+ logger_1.default.debug(`${this.logPrefix}refreshLayout:`, JSON.stringify(this.layout.userList));
32
33
  (_b = this.nativeStreamLayoutManager) === null || _b === void 0 ? void 0 : _b.setStreamLayout(this.layout.userList);
33
34
  }
34
35
  else {
@@ -59,12 +60,12 @@ class NoneStreamLayoutManager extends BaseStreamLayoutManager_1.default {
59
60
  this.layout.userList = [{
60
61
  userId: '',
61
62
  rect: {
62
- left: previewLeft,
63
- top: previewTop,
64
- right: previewRight,
65
- bottom: previewBottom,
63
+ left: Math.round(previewLeft),
64
+ top: Math.round(previewTop),
65
+ right: Math.round(previewRight),
66
+ bottom: Math.round(previewBottom),
66
67
  },
67
- fillMode: trtc_define_1.TRTCVideoFillMode.TRTCVideoFillMode_Fit,
68
+ fillMode: trtc_define_1.TRTCVideoFillMode.TRTCVideoFillMode_Fill,
68
69
  zOrder: 0
69
70
  }];
70
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trtc-electron-sdk",
3
- "version": "12.7.706-beta.1",
3
+ "version": "12.7.706-beta.3",
4
4
  "description": "trtc electron sdk",
5
5
  "main": "./liteav/index.js",
6
6
  "types": "./liteav/index.d.ts",