trtc-electron-sdk 12.6.706-beta.0 → 12.7.706-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,6 +393,8 @@ export declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
393
393
  private setDisplayRect;
394
394
  private createDesigner;
395
395
  private destroyDesigner;
396
+ private createOrUpdateLayoutManager;
397
+ private destroyLayoutManager;
396
398
  private updateMixingVideoSize;
397
399
  private listenDesignerEvent;
398
400
  private unlistenDesignerEvent;
@@ -407,13 +409,15 @@ export declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
407
409
  private findSelectedMediaSource;
408
410
  private unselectMediaSource;
409
411
  private handleCppCallbackEvent;
410
- private onMediaSourceAddedOrRemoved;
412
+ private onMediaSourceAdded;
413
+ private onMediaSourceRemoved;
411
414
  private onMediaSourceSizeChanged;
412
415
  private onPhoneMirrorSourceChanged;
413
416
  private onMediaServerState;
414
417
  private onMediaMixingServerLost;
415
418
  private onCallExperimentalAPIFinish;
416
419
  private recoverMediaMixingServer;
420
+ private onDevicePixelRatioChange;
417
421
  startCameraDeviceTest(windowID: number | Uint8Array, rect?: Rect): Promise<number>;
418
422
  stopCameraDeviceTest(): Promise<number>;
419
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);
@@ -444,18 +448,29 @@ class TRTCMediaMixingManager {
444
448
  this.windowID = realWindowID;
445
449
  if (realWindowID !== 0 && viewOrRegion !== null) {
446
450
  if (viewOrRegion instanceof HTMLElement) {
447
- this.destroyDesigner();
448
- this.view = viewOrRegion;
449
- this.setDisplayRect();
450
- this.initResizeObserver();
451
- this.createDesigner();
451
+ if (this.view !== viewOrRegion) {
452
+ this.destroyDesigner();
453
+ this.view = viewOrRegion;
454
+ this.setDisplayRect();
455
+ this.initResizeObserver();
456
+ this.createDesigner();
457
+ }
458
+ else {
459
+ this.setDisplayRect();
460
+ if (!this.mediaMixingDesigner) {
461
+ this.createDesigner();
462
+ }
463
+ }
452
464
  }
453
465
  else {
454
466
  // Rect
467
+ this.destroyLayoutManager();
468
+ this.destroyDesigner();
455
469
  this.nodeMediaMixingPlugin.setDisplayParams(realWindowID, viewOrRegion);
456
470
  }
457
471
  }
458
472
  else {
473
+ this.destroyLayoutManager();
459
474
  this.destroyDesigner();
460
475
  this.nodeMediaMixingPlugin.setDisplayParams(realWindowID, { left: 0, right: 0, top: 0, bottom: 0 });
461
476
  }
@@ -487,6 +502,7 @@ class TRTCMediaMixingManager {
487
502
  id: `${newMediaSource.sourceType}__${newMediaSource.sourceId}`,
488
503
  rect: newMediaSource.rect,
489
504
  isSelected: newMediaSource.isSelected || false,
505
+ zOrder: newMediaSource.zOrder,
490
506
  origin: newMediaSource
491
507
  });
492
508
  this.sourceList.push(newMediaSource);
@@ -504,17 +520,9 @@ class TRTCMediaMixingManager {
504
520
  throw new Error("Not existing media source to remove");
505
521
  }
506
522
  return new Promise((resolve, reject) => {
507
- var _a;
508
523
  const key = `${promiseKeys.removeMediaSource}-${mediaSource.sourceType}-${mediaSource.sourceId}`;
509
524
  this.promiseStore.addPromise(key, resolve, reject);
510
525
  this.nodeMediaMixingPlugin.removeMediaSource(mediaSource);
511
- (_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.removeMedia({
512
- id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
513
- rect: mediaSource.rect,
514
- isSelected: mediaSource.isSelected || false,
515
- origin: (0, utils_1.safelyParse)(JSON.stringify(mediaSource))
516
- });
517
- this.sourceList.splice(index, 1);
518
526
  });
519
527
  }
520
528
  /**
@@ -542,6 +550,7 @@ class TRTCMediaMixingManager {
542
550
  id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
543
551
  rect: mediaSource.rect,
544
552
  isSelected: mediaSource.isSelected || false,
553
+ zOrder: mediaSource.zOrder,
545
554
  origin: (0, utils_1.safelyParse)(JSON.stringify(mediaSource))
546
555
  });
547
556
  this.sourceList[index] = newMediaSource;
@@ -620,19 +629,34 @@ class TRTCMediaMixingManager {
620
629
  width: this.mixingVideoWidth,
621
630
  height: this.mixingVideoHeight
622
631
  });
623
- 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
+ };
624
649
  if (params.videoEncoderParams.colorRange !== undefined
625
650
  || params.videoEncoderParams.colorSpace !== undefined
626
651
  || params.videoEncoderParams.complexity !== undefined) {
627
- this.nodeMediaMixingPlugin.callExperimentalAPI(JSON.stringify({
628
- "api": "setVideoEncodeParamEx",
629
- "params": {
630
- "colorRange": params.videoEncoderParams.colorRange || trtc_define_1.TRTCVideoColorRange.TRTCVideoColorRange_Auto,
631
- "colorSpace": params.videoEncoderParams.colorSpace || trtc_define_1.TRTCVideoColorSpace.TRTCVideoColorSpace_Auto,
632
- "complexity": params.videoEncoderParams.complexity || trtc_define_1.TRTCVideoEncodeComplexity.TRTCVideoEncodeComplexity_Fastest,
633
- }
634
- }));
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;
635
655
  }
656
+ this.nodeMediaMixingPlugin.callExperimentalAPI(JSON.stringify({
657
+ api: 'setVideoEncodeParamEx',
658
+ params: encodeParamEx
659
+ }));
636
660
  return result;
637
661
  });
638
662
  }
@@ -709,7 +733,7 @@ class TRTCMediaMixingManager {
709
733
  * }
710
734
  */
711
735
  setStreamLayout(layout) {
712
- var _a, _b;
736
+ var _a, _b, _c;
713
737
  logger_1.default.log(`${this.logPrefix}setStreamLayout:`, layout);
714
738
  if (this.paramsStore) {
715
739
  try {
@@ -719,22 +743,7 @@ class TRTCMediaMixingManager {
719
743
  this.paramsStore.streamLayout = undefined;
720
744
  }
721
745
  }
722
- const context = {
723
- container: this.view,
724
- mixingVideoSize: {
725
- width: this.mixingVideoWidth,
726
- height: this.mixingVideoHeight
727
- },
728
- mediaMixingDesigner: this.mediaMixingDesigner
729
- };
730
- if (!this.streamLayoutManager) {
731
- this.streamLayoutManager = StreamLayout_1.StreamLayoutFactory.create(layout.layoutMode, this.nodeMediaMixingPlugin, context);
732
- }
733
- else if (this.streamLayoutManager.getLayoutMode() !== layout.layoutMode) {
734
- this.streamLayoutManager.destroy();
735
- this.streamLayoutManager = StreamLayout_1.StreamLayoutFactory.create(layout.layoutMode, this.nodeMediaMixingPlugin, context);
736
- }
737
- let transferredUserList = layout.userList;
746
+ this.createOrUpdateLayoutManager(layout);
738
747
  if (this.view) {
739
748
  const viewRect = this.view.getBoundingClientRect();
740
749
  if ((_a = layout.userList) === null || _a === void 0 ? void 0 : _a.length) {
@@ -748,26 +757,13 @@ class TRTCMediaMixingManager {
748
757
  bottom: workingArea.bottom / viewRect.height,
749
758
  }, localUser.fillMode);
750
759
  }
751
- transferredUserList = layout.userList.map((user) => {
752
- if (user.rect) {
753
- return Object.assign(Object.assign({}, user), { rect: {
754
- left: user.rect.left * window.devicePixelRatio,
755
- right: user.rect.right * window.devicePixelRatio,
756
- top: user.rect.top * window.devicePixelRatio,
757
- bottom: user.rect.bottom * window.devicePixelRatio,
758
- } });
759
- }
760
- else {
761
- return user;
762
- }
763
- });
764
760
  logger_1.default.log(`${this.logPrefix}setStreamLayout transfer layout to pixel unit:`, JSON.stringify(layout));
765
761
  }
766
762
  }
767
763
  else {
768
764
  logger_1.default.warn(`${this.logPrefix}setStreamLayout: view is null, no container HTML element. User control the layout manually in device pixel unit.`);
769
765
  }
770
- this.streamLayoutManager.setLayout(Object.assign(Object.assign({}, layout), { userList: transferredUserList }));
766
+ (_c = this.streamLayoutManager) === null || _c === void 0 ? void 0 : _c.setLayout(layout);
771
767
  }
772
768
  /**
773
769
  * @private
@@ -896,6 +892,18 @@ class TRTCMediaMixingManager {
896
892
  canExceedContainer: true,
897
893
  });
898
894
  this.listenDesignerEvent();
895
+ if (this.sourceList.length >= 1) {
896
+ this.sourceList.forEach((mediaSource => {
897
+ var _a;
898
+ (_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.addMedia({
899
+ id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
900
+ rect: mediaSource.rect,
901
+ isSelected: mediaSource.isSelected || false,
902
+ zOrder: mediaSource.zOrder,
903
+ origin: mediaSource
904
+ });
905
+ }));
906
+ }
899
907
  }
900
908
  }
901
909
  destroyDesigner() {
@@ -906,6 +914,29 @@ class TRTCMediaMixingManager {
906
914
  this.mediaMixingDesigner = null;
907
915
  }
908
916
  }
917
+ createOrUpdateLayoutManager(layout) {
918
+ const context = {
919
+ container: this.view,
920
+ mixingVideoSize: {
921
+ width: this.mixingVideoWidth,
922
+ height: this.mixingVideoHeight
923
+ },
924
+ mediaMixingDesigner: this.mediaMixingDesigner
925
+ };
926
+ if (!this.streamLayoutManager) {
927
+ this.streamLayoutManager = StreamLayout_1.StreamLayoutFactory.create(layout.layoutMode, this.nodeMediaMixingPlugin, context);
928
+ }
929
+ else if (this.streamLayoutManager.getLayoutMode() !== layout.layoutMode) {
930
+ this.streamLayoutManager.destroy();
931
+ this.streamLayoutManager = StreamLayout_1.StreamLayoutFactory.create(layout.layoutMode, this.nodeMediaMixingPlugin, context);
932
+ }
933
+ }
934
+ destroyLayoutManager() {
935
+ if (this.streamLayoutManager) {
936
+ this.streamLayoutManager.destroy();
937
+ this.streamLayoutManager = null;
938
+ }
939
+ }
909
940
  updateMixingVideoSize(params) {
910
941
  if (resolutionMap.has(params.videoResolution)) {
911
942
  const { width, height } = resolutionMap.get(params.videoResolution);
@@ -1002,6 +1033,7 @@ class TRTCMediaMixingManager {
1002
1033
  id: `${this.sourceList[index].sourceType}__${this.sourceList[index].sourceId}`,
1003
1034
  rect: this.sourceList[index].rect,
1004
1035
  isSelected: this.sourceList[index].isSelected || false,
1036
+ zOrder: this.sourceList[index].zOrder,
1005
1037
  origin: (0, utils_1.safelyParse)(JSON.stringify(this.sourceList[index]))
1006
1038
  });
1007
1039
  });
@@ -1013,8 +1045,10 @@ class TRTCMediaMixingManager {
1013
1045
  // To do: 待完善
1014
1046
  switch (key) {
1015
1047
  case "onMediaSourceAdded":
1048
+ this.onMediaSourceAdded(data);
1049
+ break;
1016
1050
  case "onMediaSourceRemoved":
1017
- this.onMediaSourceAddedOrRemoved(key, data);
1051
+ this.onMediaSourceRemoved(data);
1018
1052
  break;
1019
1053
  case TRTCMediaMixingEvent.onMediaSourceSizeChanged:
1020
1054
  this.onMediaSourceSizeChanged(data);
@@ -1033,18 +1067,64 @@ class TRTCMediaMixingManager {
1033
1067
  break;
1034
1068
  }
1035
1069
  }
1036
- onMediaSourceAddedOrRemoved(key, data) {
1037
- var _a;
1038
- let promiseKey;
1039
- if (key === "onMediaSourceAdded") {
1040
- 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);
1041
1076
  }
1042
1077
  else {
1043
- // 'onMediaSourceRemoved'
1044
- 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);
1045
1106
  }
1107
+ }
1108
+ onMediaSourceRemoved(data) {
1109
+ var _a, _b;
1110
+ const promiseKey = `${promiseKeys.removeMediaSource}-${data.sourceType}-${data.sourceId}`;
1046
1111
  let flag = false;
1047
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
+ }
1048
1128
  flag = this.promiseStore.resolvePromise(promiseKey, undefined);
1049
1129
  }
1050
1130
  else {
@@ -1060,7 +1140,7 @@ class TRTCMediaMixingManager {
1060
1140
  if (index !== -1) {
1061
1141
  mediaSource = Object.assign({}, this.sourceList[index]);
1062
1142
  }
1063
- (_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);
1064
1144
  }
1065
1145
  }
1066
1146
  onMediaSourceSizeChanged(data) {
@@ -1133,14 +1213,15 @@ class TRTCMediaMixingManager {
1133
1213
  });
1134
1214
  }
1135
1215
  onMediaMixingServerLost() {
1136
- var _a;
1216
+ var _a, _b;
1137
1217
  return __awaiter(this, void 0, void 0, function* () {
1138
1218
  if (this.autoControlServer) {
1139
1219
  yield this.recoverMediaMixingServer();
1140
1220
  }
1141
1221
  else {
1142
1222
  this.sourceList = [];
1143
- (_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);
1144
1225
  }
1145
1226
  });
1146
1227
  }
@@ -1159,14 +1240,7 @@ class TRTCMediaMixingManager {
1159
1240
  this.setStreamLayout(this.paramsStore.streamLayout);
1160
1241
  }
1161
1242
  this.sourceList.forEach((item) => {
1162
- var _a;
1163
1243
  this.nodeMediaMixingPlugin.addMediaSource(item);
1164
- (_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.addMedia({
1165
- id: `${item.sourceType}__${item.sourceId}`,
1166
- rect: item.rect,
1167
- isSelected: item.isSelected || false,
1168
- origin: item
1169
- });
1170
1244
  });
1171
1245
  if (((_b = this.trtcParamsStore) === null || _b === void 0 ? void 0 : _b.enterRoomParams) && ((_c = this.trtcParamsStore) === null || _c === void 0 ? void 0 : _c.enterRoomScene)) {
1172
1246
  this.nodeTRTCCloud.enterRoom(this.trtcParamsStore.enterRoomParams, this.trtcParamsStore.enterRoomScene);
@@ -1178,6 +1252,10 @@ class TRTCMediaMixingManager {
1178
1252
  }
1179
1253
  });
1180
1254
  }
1255
+ onDevicePixelRatioChange() {
1256
+ logger_1.default.debug(`${this.logPrefix}onDevicePixelRatioChange:`, window.devicePixelRatio);
1257
+ this.setDisplayRect();
1258
+ }
1181
1259
  // ****** 这一部分接口暴露不合理,暂时不对暴露在 API 文档上 **************/
1182
1260
  startCameraDeviceTest(windowID, rect) {
1183
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);
@@ -17,13 +17,22 @@ class NoneStreamLayoutManager extends BaseStreamLayoutManager_1.default {
17
17
  this.refreshLayout();
18
18
  }
19
19
  refreshLayout() {
20
- var _a;
20
+ var _a, _b;
21
21
  if (this.context && this.layout.userList) {
22
22
  this.centerLiveOwner();
23
- (_a = this.nativeStreamLayoutManager) === null || _a === void 0 ? void 0 : _a.setStreamLayout(this.layout.userList);
23
+ if (this.layout.userList.length === 1 && this.layout.userList[0].rect && this.displayArea.width !== 0 && this.displayArea.height !== 0 && window.devicePixelRatio !== 0) {
24
+ const workingArea = this.layout.userList[0].rect;
25
+ (_a = this.context.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.setWorkingArea({
26
+ left: workingArea.left / this.displayArea.width / window.devicePixelRatio,
27
+ top: workingArea.top / this.displayArea.height / window.devicePixelRatio,
28
+ right: workingArea.right / this.displayArea.width / window.devicePixelRatio,
29
+ bottom: workingArea.bottom / this.displayArea.height / window.devicePixelRatio,
30
+ }, this.layout.userList[0].fillMode);
31
+ }
32
+ (_b = this.nativeStreamLayoutManager) === null || _b === void 0 ? void 0 : _b.setStreamLayout(this.layout.userList);
24
33
  }
25
34
  else {
26
- logger_1.default.error(`${this.logPrefix}setLayout context is null or no user`);
35
+ logger_1.default.error(`${this.logPrefix}refreshLayout context is null or no user`);
27
36
  }
28
37
  }
29
38
  centerLiveOwner() {
package/liteav/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './trtc_define';
2
2
  export * from './trtc_code';
3
- export * from './vod_player';
4
3
  export * from './extensions/DeviceManager';
5
4
  export * from './extensions/AudioEffectManager';
6
5
  export * from './extensions/MediaMixingManager';
package/liteav/index.js CHANGED
@@ -15,7 +15,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  __exportStar(require("./trtc_define"), exports);
17
17
  __exportStar(require("./trtc_code"), exports);
18
- __exportStar(require("./vod_player"), exports);
19
18
  __exportStar(require("./extensions/DeviceManager"), exports);
20
19
  __exportStar(require("./extensions/AudioEffectManager"), exports);
21
20
  __exportStar(require("./extensions/MediaMixingManager"), exports);
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;
@@ -36,7 +37,6 @@ declare class TRTCCloud extends EventEmitter {
36
37
  private enableRenderFrame;
37
38
  private screenCaptureStreamType;
38
39
  private isScreenCapturing;
39
- private vodPlayers;
40
40
  private localMediaTranscoder;
41
41
  private isCaptureLocalVideoEnabled;
42
42
  private videoProcessBufferType;
@@ -98,11 +98,11 @@ declare class TRTCCloud extends EventEmitter {
98
98
  * rtcCloud.startLocalAudio(); // 主实例开启麦克风采集
99
99
  *
100
100
  * const childRtcCloud = rtcCloud.createSubCloud();
101
- * childRtcCloud.startSystemAudioLoopback(); // 子实例开启系统音采集
101
+ * childRtcCloud?.startSystemAudioLoopback(); // 子实例开启系统音采集
102
102
  *
103
- * @returns {TRTCCloud}
103
+ * @returns {TRTCCloud|null}
104
104
  */
105
- createSubCloud(config?: TRTCInitConfig): TRTCCloud;
105
+ createSubCloud(config?: TRTCInitConfig): TRTCCloud | null;
106
106
  /**
107
107
  * 获取 TRTC 配置对象
108
108
  *
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();
@@ -212,7 +214,6 @@ class TRTCCloud extends events_1.EventEmitter {
212
214
  //VideoCallback 本地和远程
213
215
  this.localVideoCallback = null;
214
216
  this.remoteVideoCallback = new Map();
215
- this.vodPlayers = {};
216
217
  secMethods(this);
217
218
  // 视频渲染共享buffer
218
219
  this.remoteVideoBufferMap = new Map();
@@ -306,16 +307,18 @@ class TRTCCloud extends events_1.EventEmitter {
306
307
  * rtcCloud.startLocalAudio(); // 主实例开启麦克风采集
307
308
  *
308
309
  * const childRtcCloud = rtcCloud.createSubCloud();
309
- * childRtcCloud.startSystemAudioLoopback(); // 子实例开启系统音采集
310
+ * childRtcCloud?.startSystemAudioLoopback(); // 子实例开启系统音采集
310
311
  *
311
- * @returns {TRTCCloud}
312
+ * @returns {TRTCCloud|null}
312
313
  */
313
314
  createSubCloud(config) {
314
315
  if (this !== TRTCCloud.sharedTRTCCloudInstance) {
315
- throw new Error("createSubCloud() can only be called on the main instance created by getTRTCShareInstance().");
316
+ this.logger.warn("createSubCloud() can only be called on the main instance created by getTRTCShareInstance().");
317
+ return null;
316
318
  }
317
319
  if (TRTCCloud.isIPCMode) {
318
- throw new Error("createSubCloud() is not supported when `isIPCMode` is true.");
320
+ TRTCCloud.ipcModeReferenceCount = TRTCCloud.ipcModeReferenceCount + 1;
321
+ return TRTCCloud.sharedTRTCCloudInstance;
319
322
  }
320
323
  return new TRTCCloud(config);
321
324
  }
@@ -355,6 +358,12 @@ class TRTCCloud extends events_1.EventEmitter {
355
358
  */
356
359
  destroy() {
357
360
  var _a, _b;
361
+ if (TRTCCloud.isIPCMode) {
362
+ TRTCCloud.ipcModeReferenceCount = TRTCCloud.ipcModeReferenceCount - 1;
363
+ if (TRTCCloud.ipcModeReferenceCount > 0) {
364
+ return;
365
+ }
366
+ }
358
367
  if (this === TRTCCloud.sharedTRTCCloudInstance) {
359
368
  if (TRTCCloud.subInstances) {
360
369
  TRTCCloud.subInstances.forEach(sub => {
@@ -4875,28 +4884,6 @@ class TRTCCloud extends events_1.EventEmitter {
4875
4884
  //----------------------------------//
4876
4885
  // plugin API -- end
4877
4886
  //----------------------------------//
4878
- //----------------------------------//
4879
- // Vod API -- start
4880
- //----------------------------------//
4881
- // createVodPlayer(mediaFilePath: string, repeat: boolean) {
4882
- // const nativeVodPlayer = this.rtcCloud.createVodPlayer(mediaFilePath, repeat);
4883
- // if (nativeVodPlayer) {
4884
- // const vodPlayer = new VodPlayer(nativeVodPlayer, mediaFilePath, repeat);
4885
- // vodPlayer.setVodPlayerRenderCallback();
4886
- // vodPlayer.setVodEventCallback();
4887
- // this.vodPlayers[vodPlayer.key] = vodPlayer;
4888
- // return vodPlayer;
4889
- // }
4890
- // return null;
4891
- // }
4892
- // destroyVodPlayer(vodPlayer: VodPlayer) {
4893
- // vodPlayer.destroyRender();
4894
- // this.rtcCloud.destroyVodPlayer(vodPlayer.key);
4895
- // delete this.vodPlayers[vodPlayer.key];
4896
- // }
4897
- //----------------------------------//
4898
- // Vod API -- end
4899
- //----------------------------------//
4900
4887
  _getKey(uid, type) {
4901
4888
  return String(uid) + '_' + String(type);
4902
4889
  }
@@ -5326,7 +5313,7 @@ class TRTCCloud extends events_1.EventEmitter {
5326
5313
  }
5327
5314
  }
5328
5315
  catch (error) {
5329
- this.logger.warn(`callExperimentalAPI invalid JSON parameter`, error);
5316
+ this.logger.warn(`callExperimentalAPI invalid JSON parameter`, error, jsonStr);
5330
5317
  }
5331
5318
  }
5332
5319
  /**
@@ -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.6.706-beta.0",
3
+ "version": "12.7.706-beta.0",
4
4
  "description": "trtc electron sdk",
5
5
  "main": "./liteav/index.js",
6
6
  "types": "./liteav/index.d.ts",
@@ -1,46 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { TRTCVideoRotation } from './trtc_define';
4
- export declare enum PlayerEvents {
5
- onVodPlayerStarted = "onVodPlayerStarted",
6
- onVodPlayerProgress = "onVodPlayerProgress",
7
- onVodPlayerPaused = "onVodPlayerPaused",
8
- onVodPlayerResumed = "onVodPlayerResumed",
9
- onVodPlayerStoped = "onVodPlayerStoped",
10
- onVodPlayerError = "onVodPlayerError"
11
- }
12
- export declare class VodPlayer extends EventEmitter {
13
- private renderer;
14
- private nativeVodPlayer;
15
- private mediaFilePath;
16
- private repeat;
17
- private view;
18
- private isStarted;
19
- private pixelLength;
20
- private pixelFormat;
21
- private vodPlayerVideoBuffer;
22
- constructor(mediaFilePath: string, repeat: boolean);
23
- setVodPlayerView(view: HTMLElement): void;
24
- start(): void;
25
- pause(): void;
26
- resume(): void;
27
- stop(): void;
28
- seek(msPos: number): void;
29
- getDuration(): number;
30
- getWidth(): number;
31
- getHeight(): number;
32
- mute(mute: boolean): void;
33
- setVolume(volume: number): void;
34
- attachTRTC(): void;
35
- detachTRTC(): void;
36
- publishVideo(): void;
37
- publishAudio(): void;
38
- unpublishVideo(): void;
39
- unpublishAudio(): void;
40
- setVodPlayerDataCallback(): void;
41
- setVodPlayerEventCallback(): void;
42
- _renderVodVideoFrame(data: any, width: number, height: number, timestamp: number, rotation: TRTCVideoRotation): void;
43
- handleVideoSizeChange(userId: string, streamType: number, width: number, height: number): void;
44
- _initRender(view: HTMLElement): void;
45
- destroyRender(): void;
46
- }
@@ -1,194 +0,0 @@
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
- exports.VodPlayer = exports.PlayerEvents = void 0;
7
- const events_1 = require("events");
8
- const Renderer_1 = require("./Renderer");
9
- const trtc_define_1 = require("./trtc_define");
10
- const logger_1 = __importDefault(require("./logger"));
11
- const util_1 = require("./Renderer/util");
12
- const NodeTRTCEngine = require('../build/Release/trtc_electron_sdk.node');
13
- const DEFAULT_VIDEO_WIDTH = 640;
14
- const DEFAULT_VIDEO_HEIGHT = 360;
15
- var PlayerEvents;
16
- (function (PlayerEvents) {
17
- PlayerEvents["onVodPlayerStarted"] = "onVodPlayerStarted";
18
- PlayerEvents["onVodPlayerProgress"] = "onVodPlayerProgress";
19
- PlayerEvents["onVodPlayerPaused"] = "onVodPlayerPaused";
20
- PlayerEvents["onVodPlayerResumed"] = "onVodPlayerResumed";
21
- PlayerEvents["onVodPlayerStoped"] = "onVodPlayerStoped";
22
- PlayerEvents["onVodPlayerError"] = "onVodPlayerError";
23
- })(PlayerEvents = exports.PlayerEvents || (exports.PlayerEvents = {}));
24
- class VodPlayer extends events_1.EventEmitter {
25
- constructor(mediaFilePath, repeat) {
26
- super();
27
- this.nativeVodPlayer = new NodeTRTCEngine.NodeVodPlayer(mediaFilePath, repeat);
28
- this.mediaFilePath = mediaFilePath;
29
- this.repeat = repeat;
30
- this.view = null;
31
- this.isStarted = false;
32
- this.vodPlayerVideoBuffer = new trtc_define_1.VideoBufferInfo();
33
- this.pixelLength = 1.5;
34
- this.pixelFormat = trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420;
35
- this.setVodPlayerEventCallback();
36
- }
37
- setVodPlayerView(view) {
38
- this.view = view;
39
- this._initRender(this.view);
40
- }
41
- start() {
42
- this.nativeVodPlayer.streamType = trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig;
43
- this.vodPlayerVideoBuffer.buffer = (0, util_1.allocBuffer)(DEFAULT_VIDEO_WIDTH * DEFAULT_VIDEO_HEIGHT * this.pixelLength);
44
- this.nativeVodPlayer.id = (0, util_1.generateUniqueId)();
45
- this.nativeVodPlayer.pixelFormat = this.pixelFormat;
46
- this.nativeVodPlayer.width = DEFAULT_VIDEO_WIDTH;
47
- this.nativeVodPlayer.height = DEFAULT_VIDEO_HEIGHT;
48
- this.nativeVodPlayer.setVideoBuffer('', this.vodPlayerVideoBuffer.buffer, this.nativeVodPlayer.streamType, this.nativeVodPlayer.width, this.nativeVodPlayer.height, this.nativeVodPlayer.pixelFormat, this.nativeVodPlayer.id);
49
- this.setVodPlayerDataCallback();
50
- if (!this.isStarted) {
51
- this.nativeVodPlayer.start();
52
- }
53
- this.isStarted = true;
54
- }
55
- pause() {
56
- this.nativeVodPlayer.pause();
57
- }
58
- resume() {
59
- this.nativeVodPlayer.resume();
60
- }
61
- stop() {
62
- this.isStarted = false;
63
- this.nativeVodPlayer.stop();
64
- if (this.vodPlayerVideoBuffer.buffer) {
65
- this.nativeVodPlayer.setVideoBuffer('', this.vodPlayerVideoBuffer.buffer, this.nativeVodPlayer.streamType, 0, 0, this.nativeVodPlayer.pixelFormat, 0);
66
- this.vodPlayerVideoBuffer.buffer = null;
67
- this.vodPlayerVideoBuffer.id = 0;
68
- }
69
- }
70
- seek(msPos) {
71
- this.nativeVodPlayer.seek(msPos);
72
- }
73
- getDuration() {
74
- return this.nativeVodPlayer.getDuration();
75
- }
76
- getWidth() {
77
- return this.nativeVodPlayer.getWidth();
78
- }
79
- getHeight() {
80
- return this.nativeVodPlayer.getHeight();
81
- }
82
- mute(mute) {
83
- this.nativeVodPlayer.mute(mute);
84
- }
85
- setVolume(volume) {
86
- this.nativeVodPlayer.setVolume(volume);
87
- }
88
- attachTRTC() {
89
- this.nativeVodPlayer.attachTRTC();
90
- }
91
- detachTRTC() {
92
- this.nativeVodPlayer.detachTRTC();
93
- }
94
- publishVideo() {
95
- this.nativeVodPlayer.publishVideo();
96
- }
97
- publishAudio() {
98
- this.nativeVodPlayer.publishAudio();
99
- }
100
- unpublishVideo() {
101
- this.nativeVodPlayer.unpublishVideo();
102
- }
103
- unpublishAudio() {
104
- this.nativeVodPlayer.unpublishAudio();
105
- }
106
- setVodPlayerDataCallback() {
107
- this.nativeVodPlayer.setDataCallback((args) => {
108
- const [id, type, width, height, timestamp, rotation, valid, bufferId] = args;
109
- if (valid === true) {
110
- this._renderVodVideoFrame(this.vodPlayerVideoBuffer.buffer, width, height, timestamp, rotation);
111
- }
112
- else {
113
- this.handleVideoSizeChange(id, type, width, height);
114
- }
115
- });
116
- }
117
- setVodPlayerEventCallback() {
118
- this.nativeVodPlayer.setEventCallback((args) => {
119
- const key = args[0];
120
- const data = args[1];
121
- switch (key) {
122
- case 'onVodPlayerStarted':
123
- this.emit(key, data.msLength);
124
- break;
125
- case 'onVodPlayerProgress':
126
- this.emit(key, data.msPos);
127
- break;
128
- case 'onVodPlayerPaused':
129
- this.emit(key);
130
- break;
131
- case 'onVodPlayerResumed':
132
- this.emit(key);
133
- break;
134
- case 'onVodPlayerStoped':
135
- this.emit(key, data.reason);
136
- break;
137
- case 'onVodPlayerError':
138
- this.emit(key, data.error);
139
- break;
140
- default:
141
- break;
142
- }
143
- });
144
- }
145
- _renderVodVideoFrame(data, width, height, timestamp, rotation) {
146
- if (!this.renderer || !this.view) {
147
- return;
148
- }
149
- if (data) {
150
- const newData = data.slice(0); // Electron 12 及以下版本,来自底层的帧数据必须复制一次,否则 WebGL 渲染阶段会奔溃
151
- const realRotation = rotation * 90; //ratation是0, 1, 2, 3. 绘制内部使用0, 90, 180, 270
152
- this.renderer.drawFrame({
153
- data: newData,
154
- width,
155
- height,
156
- timestamp,
157
- rotation: realRotation,
158
- isNeedRotate: false,
159
- });
160
- }
161
- }
162
- handleVideoSizeChange(userId, streamType, width, height) {
163
- if (this.vodPlayerVideoBuffer.width !== width || this.vodPlayerVideoBuffer.height !== height) {
164
- this.vodPlayerVideoBuffer.buffer = (0, util_1.allocBuffer)(width * height * this.pixelLength);
165
- this.vodPlayerVideoBuffer.id = (0, util_1.generateUniqueId)();
166
- this.vodPlayerVideoBuffer.width = width;
167
- this.vodPlayerVideoBuffer.height = height;
168
- this.vodPlayerVideoBuffer.pixelFormat = this.pixelFormat;
169
- this.nativeVodPlayer.setVideoBuffer(userId, this.vodPlayerVideoBuffer.buffer, streamType, width, height, this.vodPlayerVideoBuffer.pixelFormat, this.vodPlayerVideoBuffer.id);
170
- }
171
- }
172
- _initRender(view) {
173
- if (this.renderer) {
174
- this.destroyRender();
175
- }
176
- view.innerHTML = ''; // 事先清空一下,避免画面叠加
177
- this.renderer = (0, Renderer_1.createRenderer)(trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420, view, {
178
- type: Renderer_1.RenderType.Video,
179
- onContextLost: () => {
180
- this.renderer = (0, Renderer_1.createRenderer)(trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420, view, { type: Renderer_1.RenderType.Canvas2D });
181
- },
182
- });
183
- }
184
- destroyRender() {
185
- try {
186
- this.renderer.destroy();
187
- this.renderer = null;
188
- }
189
- catch (err) {
190
- logger_1.default.error('[VodPlayer]destroyRender failed:', err);
191
- }
192
- }
193
- }
194
- exports.VodPlayer = VodPlayer;