trtc-electron-sdk 13.1.709-beta.0 → 13.1.709-beta.1

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.
@@ -1,21 +1,33 @@
1
1
  import TRTCCloud from '../trtc';
2
+ /**
3
+ * 本地视频渲染控制器
4
+ * 负责管理本地视频的自定义渲染状态和回调控制
5
+ */
2
6
  declare class LocalVideoRenderController {
3
- private logPrefix;
4
- private trtcCloud;
7
+ private readonly logPrefix;
8
+ private readonly trtcCloud;
5
9
  private currentState;
6
10
  private isExternalRenderEnabled;
7
11
  private isLocalPreviewStarted;
8
12
  private hasLocalPreviewView;
9
13
  private isLocalSharingStarted;
10
14
  private hasLocalSharingView;
15
+ private hasCustomRenderCallback;
11
16
  constructor(trtcCloud: TRTCCloud);
12
17
  startLocalPreview(views: Array<HTMLElement> | HTMLElement | null): void;
13
18
  stopLocalPreview(): void;
14
19
  updateLocalView(views: Array<HTMLElement> | HTMLElement | null): void;
15
20
  startScreenCapture(view?: HTMLElement | null): void;
16
21
  stopScreenCapture(): void;
22
+ setCustomRenderCallback(hasCallback: boolean): void;
17
23
  setExternalRenderEnabled(enabled: boolean): void;
24
+ private validateViews;
18
25
  private update;
26
+ /**
27
+ * 计算目标渲染状态
28
+ * 根据当前条件判断是否需要监听视频渲染回调
29
+ * @returns 目标渲染状态
30
+ */
19
31
  private calcTargetState;
20
32
  }
21
33
  export default LocalVideoRenderController;
@@ -5,6 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const type_1 = require("./type");
7
7
  const logger_1 = __importDefault(require("../logger"));
8
+ /**
9
+ * 本地视频渲染控制器
10
+ * 负责管理本地视频的自定义渲染状态和回调控制
11
+ */
8
12
  class LocalVideoRenderController {
9
13
  constructor(trtcCloud) {
10
14
  this.logPrefix = '[LocalVideoRenderController]';
@@ -15,67 +19,127 @@ class LocalVideoRenderController {
15
19
  this.hasLocalPreviewView = false;
16
20
  this.isLocalSharingStarted = false;
17
21
  this.hasLocalSharingView = false;
22
+ this.hasCustomRenderCallback = false;
18
23
  }
19
24
  startLocalPreview(views) {
20
- this.isLocalPreviewStarted = true;
21
- this.hasLocalPreviewView = views !== null && views !== undefined;
22
- if (Array.isArray(views)) {
23
- this.hasLocalPreviewView = views.length >= 1;
25
+ try {
26
+ this.isLocalPreviewStarted = true;
27
+ this.hasLocalPreviewView = this.validateViews(views);
28
+ this.update();
29
+ }
30
+ catch (error) {
31
+ logger_1.default.error(`${this.logPrefix}startLocalPreview failed:`, error);
32
+ throw error;
24
33
  }
25
- this.update();
26
34
  }
27
35
  stopLocalPreview() {
28
- this.isLocalPreviewStarted = false;
29
- this.hasLocalPreviewView = false;
30
- this.update();
36
+ try {
37
+ this.isLocalPreviewStarted = false;
38
+ this.hasLocalPreviewView = false;
39
+ this.update();
40
+ }
41
+ catch (error) {
42
+ logger_1.default.error(`${this.logPrefix}stopLocalPreview failed:`, error);
43
+ throw error;
44
+ }
31
45
  }
32
46
  updateLocalView(views) {
33
- this.hasLocalPreviewView = views !== null && views !== undefined;
34
- if (Array.isArray(views)) {
35
- this.hasLocalPreviewView = views.length >= 1;
47
+ try {
48
+ this.hasLocalPreviewView = this.validateViews(views);
49
+ this.update();
50
+ }
51
+ catch (error) {
52
+ logger_1.default.error(`${this.logPrefix}updateLocalView failed:`, error);
53
+ throw error;
36
54
  }
37
- this.update();
38
55
  }
39
56
  startScreenCapture(view = null) {
40
- this.isLocalSharingStarted = true;
41
- this.hasLocalSharingView = view !== null && view !== undefined;
42
- this.update();
57
+ try {
58
+ this.isLocalSharingStarted = true;
59
+ this.hasLocalSharingView = view !== null && view !== undefined;
60
+ this.update();
61
+ }
62
+ catch (error) {
63
+ logger_1.default.error(`${this.logPrefix}startScreenCapture failed:`, error);
64
+ throw error;
65
+ }
43
66
  }
44
67
  stopScreenCapture() {
45
- this.isLocalSharingStarted = false;
46
- this.hasLocalSharingView = false;
47
- this.update();
68
+ try {
69
+ this.isLocalSharingStarted = false;
70
+ this.hasLocalSharingView = false;
71
+ this.update();
72
+ }
73
+ catch (error) {
74
+ logger_1.default.error(`${this.logPrefix}stopScreenCapture failed:`, error);
75
+ throw error;
76
+ }
77
+ }
78
+ setCustomRenderCallback(hasCallback) {
79
+ try {
80
+ this.hasCustomRenderCallback = hasCallback;
81
+ this.update();
82
+ }
83
+ catch (error) {
84
+ logger_1.default.error(`${this.logPrefix}setCustomRenderCallback failed:`, error);
85
+ throw error;
86
+ }
48
87
  }
49
88
  setExternalRenderEnabled(enabled) {
50
89
  this.isExternalRenderEnabled = enabled;
51
90
  }
91
+ validateViews(views) {
92
+ if (views === null || views === undefined) {
93
+ return false;
94
+ }
95
+ if (Array.isArray(views)) {
96
+ return views.length >= 1 && views.every(view => view instanceof HTMLElement);
97
+ }
98
+ return views instanceof HTMLElement;
99
+ }
52
100
  update() {
53
- const targetState = this.calcTargetState();
54
- if (targetState !== this.currentState) {
55
- if (targetState === type_1.LocalVideoRenderCallbackState.NotListening) {
56
- logger_1.default.log(`${this.logPrefix}update not listening`);
57
- this.trtcCloud.removeLocalVideoRenderCallback();
101
+ try {
102
+ const targetState = this.calcTargetState();
103
+ if (targetState !== this.currentState) {
104
+ if (targetState === type_1.LocalVideoRenderCallbackState.NotListening) {
105
+ logger_1.default.log(`${this.logPrefix}update not listening`);
106
+ this.trtcCloud.removeLocalVideoRenderCallback();
107
+ }
108
+ else {
109
+ logger_1.default.log(`${this.logPrefix}update listening`);
110
+ this.trtcCloud.addLocalVideoRenderCallback();
111
+ }
112
+ this.currentState = targetState;
58
113
  }
59
- else {
60
- logger_1.default.log(`${this.logPrefix}update listening`);
61
- this.trtcCloud.addLocalVideoRenderCallback();
62
- }
63
- this.currentState = targetState;
64
114
  }
65
- else {
66
- return;
115
+ catch (error) {
116
+ logger_1.default.error(`${this.logPrefix}update failed:`, error);
117
+ // 在错误情况下保持当前状态不变,避免状态不一致
67
118
  }
68
119
  }
120
+ /**
121
+ * 计算目标渲染状态
122
+ * 根据当前条件判断是否需要监听视频渲染回调
123
+ * @returns 目标渲染状态
124
+ */
69
125
  calcTargetState() {
126
+ // 外部渲染已启用,需要监听回调
70
127
  if (this.isExternalRenderEnabled) {
71
128
  return type_1.LocalVideoRenderCallbackState.Listening;
72
129
  }
130
+ // 本地预览已启动且有预览视图,需要监听回调
73
131
  if (this.isLocalPreviewStarted && this.hasLocalPreviewView) {
74
132
  return type_1.LocalVideoRenderCallbackState.Listening;
75
133
  }
134
+ // 本地预览已启动且有自定义渲染回调,需要监听回调
135
+ if (this.isLocalPreviewStarted && this.hasCustomRenderCallback) {
136
+ return type_1.LocalVideoRenderCallbackState.Listening;
137
+ }
138
+ // 屏幕共享已启动且有共享视图,需要监听回调
76
139
  if (this.isLocalSharingStarted && this.hasLocalSharingView) {
77
140
  return type_1.LocalVideoRenderCallbackState.Listening;
78
141
  }
142
+ // 默认不监听回调
79
143
  return type_1.LocalVideoRenderCallbackState.NotListening;
80
144
  }
81
145
  }