trtc-electron-sdk 12.2.115-beta.10 → 12.2.115-beta.11

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.
@@ -487,7 +487,12 @@ class TRTCMediaMixingDesigner {
487
487
  var _a;
488
488
  logger_1.default.log(`${this.logPrefix}onRightButtonClicked:`, event.target, event.currentTarget, event.buttons);
489
489
  event.preventDefault();
490
- (_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit('onRightButtonClicked', Object.assign({}, this.mediaList[this.selectedMediaIndex]));
490
+ (_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit('onRightButtonClicked', Object.assign({}, this.mediaList[this.selectedMediaIndex]), {
491
+ windowX: event.clientX,
492
+ windowY: event.clientY,
493
+ screenX: event.screenX,
494
+ screenY: event.screenY
495
+ });
491
496
  }
492
497
  }
493
498
  exports.default = TRTCMediaMixingDesigner;
@@ -1,9 +1,10 @@
1
1
  declare class PromiseStore {
2
+ private logPrefix;
2
3
  private promiseStore;
3
4
  constructor();
4
- addPromise(key: string, resolve: (data: any) => void, reject: (data: any) => void): void;
5
- resolvePromise(key: string, value: any): void;
6
- rejectPromise(key: string, value: any): void;
5
+ addPromise(key: string, resolve: (data: void | PromiseLike<void>) => void, reject: (reason?: any) => void): void;
6
+ resolvePromise(key: string, value: void | PromiseLike<void>): void;
7
+ rejectPromise(key: string, reason?: any): void;
7
8
  destroy(): void;
8
9
  }
9
10
  export default PromiseStore;
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const logger_1 = __importDefault(require("../logger"));
3
7
  class PromiseStore {
4
8
  constructor() {
9
+ this.logPrefix = '[PromiseStore]';
5
10
  this.promiseStore = new Map();
6
11
  }
7
12
  addPromise(key, resolve, reject) {
@@ -23,21 +28,30 @@ class PromiseStore {
23
28
  });
24
29
  this.promiseStore.delete(key);
25
30
  }
31
+ else {
32
+ logger_1.default.warn(`${this.logPrefix}resolvePromise '${key}' not existed`);
33
+ }
26
34
  }
27
- rejectPromise(key, value) {
35
+ rejectPromise(key, reason) {
28
36
  var _a;
29
37
  const storedPromises = (_a = this.promiseStore) === null || _a === void 0 ? void 0 : _a.get(key);
30
38
  if (storedPromises) {
31
39
  storedPromises.forEach(({ reject }) => {
32
- reject(value);
40
+ reject(reason);
33
41
  });
34
42
  this.promiseStore.delete(key);
35
43
  }
44
+ else {
45
+ logger_1.default.warn(`${this.logPrefix}rejectPromise '${key}' not existed`);
46
+ }
36
47
  }
37
48
  destroy() {
38
49
  this.promiseStore.forEach((value) => {
39
50
  value.forEach(({ reject }) => {
40
- reject();
51
+ reject({
52
+ code: Number.NEGATIVE_INFINITY,
53
+ message: 'Instance destroyed, reject all pending promises',
54
+ });
41
55
  });
42
56
  });
43
57
  this.promiseStore.clear();
@@ -0,0 +1,423 @@
1
+ import { TRTCCameraCaptureParams, Rect, TRTCScreenCaptureProperty } from '../../trtc_define';
2
+ import { TRTCMediaSource, TRTCMediaMixingEncParam, ITRTCMediaMixingManager, TRTCPhoneMirrorParam, TRTCStreamLayout } from './types';
3
+ import { TRTCDeviceManager } from '../DeviceManager';
4
+ declare const NodeTRTCEngine: any;
5
+ /**
6
+ * @namespace TRTCMediaMixingEvent
7
+ * @description 目前只支持 `Windows` 操作系统
8
+ */
9
+ export declare enum TRTCMediaMixingEvent {
10
+ /**
11
+ * @description 媒体源选中事件
12
+ *
13
+ * @event TRTCMediaMixingEvent#onSourceSelected
14
+ * @param {TRTCMediaInfo | null} mediaSource 新选中的媒体源数据,取消选中则为`null`
15
+ */
16
+ onSourceSelected = "onSourceSelected",
17
+ /**
18
+ * @description 媒体源移动事件
19
+ *
20
+ * @event TRTCMediaMixingEvent#onSourceMoved
21
+ * @param {TRTCMediaInfo} mediaSource 被移动的媒体源
22
+ * @param {Rect} rect 移动后的位置、区域数据
23
+ */
24
+ onSourceMoved = "onSourceMoved",
25
+ /**
26
+ * @description 媒体源尺寸变化事件
27
+ *
28
+ * @event TRTCMediaMixingEvent#onSourceResized
29
+ * @param {TRTCMediaInfo} mediaSource 尺寸变化的媒体源
30
+ * @param {Rect} rect 尺寸变化后的位置、区域数据
31
+ */
32
+ onSourceResized = "onSourceResized",
33
+ /**
34
+ * @description 媒体源鼠标右键事件
35
+ *
36
+ * @event TRTCMediaMixingEvent#onRightButtonClicked
37
+ * @param {TRTCMediaInfo} mediaSource 鼠标右键点击的媒体源
38
+ * @param {Object} clickPoint 鼠标右键点击的位置
39
+ * @param {Number} clickPoint.windowX 鼠标右键点击相对窗口的 X 坐标
40
+ * @param {Number} clickPoint.windowY 鼠标右键点击相对窗口的 Y 坐标
41
+ * @param {Number} clickPoint.screenX 鼠标右键点击相对屏幕的 X 坐标
42
+ * @param {Number} clickPoint.screenY 鼠标右键点击相对屏幕的 Y 坐标
43
+ */
44
+ onRightButtonClicked = "onRightButtonClicked",
45
+ /**
46
+ * @description 错误事件
47
+ *
48
+ * @event TRTCMediaMixingEvent#onError
49
+ * @param {TRTCMediaMixingErrorCode} errCode 错误码
50
+ * @param {String} errorMessage 错误信息
51
+ *
52
+ */
53
+ onError = "onError",
54
+ /**
55
+ * @description 设备插入事件
56
+ *
57
+ * @event TRTCMediaMixingEvent#onSourcePlugged
58
+ * @param {TRTCPhoneMirrorParam} source 投屏手机状态信息
59
+ * @param {String} detail 投屏手机状态变化详情
60
+ */
61
+ onSourcePlugged = "onSourcePlugged",
62
+ /**
63
+ * @description 设备链接事件
64
+ *
65
+ * @event TRTCMediaMixingEvent#onSourceConnected
66
+ * @param {TRTCPhoneMirrorParam} source 投屏手机状态信息
67
+ * @param {String} detail 投屏手机状态变化详情
68
+ */
69
+ onSourceConnected = "onSourceConnected",
70
+ /**
71
+ * @description 设备断开链接事件
72
+ *
73
+ * @event TRTCMediaMixingEvent#onSourceDisconnected
74
+ * @param {TRTCPhoneMirrorParam} source 投屏手机状态信息
75
+ * @param {String} detail 投屏手机状态变化详情
76
+ */
77
+ onSourceDisconnected = "onSourceDisconnected",
78
+ /**
79
+ * @description 设备拔出事件
80
+ *
81
+ * @event TRTCMediaMixingEvent#onSourceUnplugged
82
+ * @param {TRTCPhoneMirrorParam} source 投屏手机状态信息
83
+ * @param {String} detail 投屏手机状态变化详情
84
+ */
85
+ onSourceUnplugged = "onSourceUnplugged",
86
+ /**
87
+ * @description 媒体源画面大小发生变化
88
+ *
89
+ * 当输入媒体源的画面大小发生变化时,会通过该接口返回该输入源最新的尺寸,您可以根据该尺寸来动态调整画面的比例。
90
+ * @event TRTCMediaMixingEvent#onMediaSourceSizeChanged
91
+ * @param {TRTCMediaSource} mediasource 媒体源信息
92
+ * @param {Object} size 媒体源最新的画面大小
93
+ * @param {Number} size.width 媒体源最新宽度
94
+ * @param {Number} size.height 媒体源最新高度
95
+ */
96
+ onMediaSourceSizeChanged = "onMediaSourceSizeChanged",
97
+ onMediaMixingServerLost = "onMediaMixingServerLost"
98
+ }
99
+ /**
100
+ * 本地混流管理器
101
+ *
102
+ * 目前只支持 `Windows` 操作系统
103
+ */
104
+ export declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
105
+ private logPrefix;
106
+ private nodeMediaMixingPlugin;
107
+ private nodeTRTCCloud;
108
+ private deviceManager;
109
+ private eventEmitter;
110
+ private promiseStore;
111
+ private publishParams;
112
+ private mediaMixingDesigner;
113
+ private windowID;
114
+ private view;
115
+ private resizeObserver;
116
+ private mixingVideoWidth;
117
+ private mixingVideoHeight;
118
+ private sourceList;
119
+ private streamLayoutManager;
120
+ private trtcParamsStore;
121
+ private paramsStore;
122
+ private autoControlServer;
123
+ constructor(options: {
124
+ deviceManager: TRTCDeviceManager;
125
+ nodeTRTCCloud: typeof NodeTRTCEngine.NodeRemoteTRTCCloud;
126
+ trtcParamsStore: Record<string, any>;
127
+ autoControlServer: boolean;
128
+ });
129
+ destroy(): Promise<void>;
130
+ /**
131
+ * @deprecated
132
+ * @private
133
+ * 设置视频流预览参数
134
+ *
135
+ * @param windowID {Number|Uint8Array} - 操作系统层的窗口 ID,Electron 下可以通过 Electron API [BrowserWindow.getNativeWindowHandle()]{@link https://www.electronjs.org/docs/latest/api/browser-window#wingetnativewindowhandle} 接口获取
136
+ * @param viewOrRegion {HTMLElement | Rect | null} - 本地混流视频显示位置
137
+ * - 传入 HTMLElement 元素,则 SDK 将本地混流视频显示在 HTMLElement 元素内,同时支持点击选中、移动、缩放媒体源,支持触发右键菜单事件。HTMLElement 元素必须是块元素。
138
+ * - 传入 Rect 显示区域,则 SDK 将本地混流视频显示在 Rect 指定区域内,不支持点击选中、移动、缩放媒体源,不支持触发右键菜单事件,这些功能您可以在 Web 页面中自行实现。
139
+ * - 传入 null 则 SDK 将停止显示本地混流视频。
140
+ *
141
+ * @example
142
+ * // Display in HTML Element
143
+ * import TRTCCloud from 'trtc-electron-sdk';
144
+ *
145
+ * const trtcCloud = TRTCCloud.getTRTCShareInstance({
146
+ * isIPCMode: true
147
+ * });
148
+ *
149
+ * const mediaMixingManager = trtcCloud.getMediaMixingManager();
150
+ *
151
+ * const windowID = 0; // Use Electron API BrowserWindow.getNativeWindowHandle()
152
+ * const previewDOM = document.getElementById("preview-local-mixed-media-stream");
153
+ * mediaMixingManager.setDisplayParams(windowID, previewDOM);
154
+ *
155
+ * @example
156
+ * // Display in a rectangle section
157
+ * import TRTCCloud from 'trtc-electron-sdk';
158
+ *
159
+ * const trtcCloud = TRTCCloud.getTRTCShareInstance({
160
+ * isIPCMode: true
161
+ * });
162
+ *
163
+ * const mediaMixingManager = trtcCloud.getMediaMixingManager();
164
+ *
165
+ * const windowID = 0; // Use Electron API BrowserWindow.getNativeWindowHandle()
166
+ * const previewDOM = document.getElementById("preview-local-mixed-media-stream");
167
+ * const domRect = previewDOM.getBoundingClientRect();
168
+ * const rect = {
169
+ * left: domRect.left * window.devicePixelRatio,
170
+ * right: domRect.right * window.devicePixelRatio,
171
+ * top: domRect.top * window.devicePixelRatio,
172
+ * bottom: domRect.bottom * window.devicePixelRatio
173
+ * };
174
+ *
175
+ * mediaMixingManager.setDisplayParams(windowID, rect);
176
+ */
177
+ setDisplayParams(windowID: number | Uint8Array, viewOrRegion: HTMLElement | Rect | null): void;
178
+ /**
179
+ * 设置视频流预览区域
180
+ *
181
+ * @param windowID {Uint8Array|Number} - 操作系统层的窗口 ID,Electron 下可以通过 Electron API [BrowserWindow.getNativeWindowHandle()]{@link https://www.electronjs.org/docs/latest/api/browser-window#wingetnativewindowhandle} 接口获取
182
+ * @param viewOrRegion {HTMLElement | Rect | null} - 本地混流视频显示位置
183
+ * - 传入 HTMLElement 元素,则 SDK 将本地混流视频显示在 HTMLElement 元素内,同时支持点击选中、移动、缩放媒体源,支持触发右键菜单事件。HTMLElement 元素必须是块元素。
184
+ * - 传入 Rect 显示区域,则 SDK 将本地混流视频显示在 Rect 指定区域内,不支持点击选中、移动、缩放媒体源,不支持触发右键菜单事件,这些功能您可以在 Web 页面中自行实现。
185
+ * - 传入 null 则 SDK 将停止显示本地混流视频。
186
+ *
187
+ * @example
188
+ * // Display in HTML Element
189
+ * import TRTCCloud from 'trtc-electron-sdk';
190
+ *
191
+ * const trtcCloud = TRTCCloud.getTRTCShareInstance({
192
+ * isIPCMode: true
193
+ * });
194
+ *
195
+ * const mediaMixingManager = trtcCloud.getMediaMixingManager();
196
+ *
197
+ * const windowID = 0; // Use Electron API BrowserWindow.getNativeWindowHandle()
198
+ * const previewDOM = document.getElementById("preview-local-mixed-media-stream");
199
+ * mediaMixingManager.bindPreviewArea(windowID, previewDOM);
200
+ *
201
+ * @example
202
+ * // Display in a rectangle section
203
+ * import TRTCCloud from 'trtc-electron-sdk';
204
+ *
205
+ * const trtcCloud = TRTCCloud.getTRTCShareInstance({
206
+ * isIPCMode: true
207
+ * });
208
+ *
209
+ * const mediaMixingManager = trtcCloud.getMediaMixingManager();
210
+ *
211
+ * const windowID = 0; // Use Electron API BrowserWindow.getNativeWindowHandle()
212
+ * const previewDOM = document.getElementById("preview-local-mixed-media-stream");
213
+ * const domRect = previewDOM.getBoundingClientRect();
214
+ * const rect = {
215
+ * left: domRect.left * window.devicePixelRatio,
216
+ * right: domRect.right * window.devicePixelRatio,
217
+ * top: domRect.top * window.devicePixelRatio,
218
+ * bottom: domRect.bottom * window.devicePixelRatio
219
+ * };
220
+ *
221
+ * mediaMixingManager.bindPreviewArea(windowID, rect);
222
+ */
223
+ bindPreviewArea(windowID: Uint8Array | number, viewOrRegion: HTMLElement | Rect | null): void;
224
+ /**
225
+ * 添加本地混流媒体源
226
+ * @param mediaSource {TRTCMediaSource} - 媒体源信息
227
+ * @returns {Promise<Rect>}
228
+ */
229
+ addMediaSource(mediaSource: TRTCMediaSource): Promise<void>;
230
+ /**
231
+ * 删除本地混流媒体源
232
+ * @param mediaSource {TRTCMediaSource} - 媒体源信息
233
+ * @returns {Promise<void>}
234
+ */
235
+ removeMediaSource(mediaSource: TRTCMediaSource): Promise<void>;
236
+ /**
237
+ * 更新本地混流媒体源
238
+ * @param mediaSource {TRTCMediaSource} - 媒体源信息
239
+ * @returns {Promise<void>}
240
+ */
241
+ updateMediaSource(mediaSource: TRTCMediaSource): Promise<void>;
242
+ /**
243
+ * 设置摄像头采集参数
244
+ * @param cameraID {string} - 摄像头 ID
245
+ * @param params {TRTCCameraCaptureParams} - 摄像头采集参数
246
+ */
247
+ setCameraCaptureParam(cameraID: string, params: TRTCCameraCaptureParams): void;
248
+ /**
249
+ * 设置手机投屏参数
250
+ * @param phoneMirrorSourceId {string} - 手机投屏媒体源 ID
251
+ * @param param {TRTCPhoneMirrorParam} - 手机投屏参数,目前只支持优先投屏
252
+ */
253
+ setPhoneMirrorParam(phoneMirrorSourceId: string, param: TRTCPhoneMirrorParam): void;
254
+ /**
255
+ * 设置屏幕采集参数
256
+ * @param screenOrWindowID {String} - 屏幕 ID 或 窗口 ID
257
+ * @param property {TRTCScreenCaptureProperty} - 屏幕采集属性
258
+ */
259
+ setScreenCaptureProperty(screenOrWindowID: string, property: TRTCScreenCaptureProperty): void;
260
+ /**
261
+ * 本地混流开始推流
262
+ * @returns {Promise<void>}
263
+ */
264
+ startPublish(): Promise<void>;
265
+ /**
266
+ * 本地混流停止推流
267
+ * @returns {Promise<void>}
268
+ */
269
+ stopPublish(): Promise<void>;
270
+ /**
271
+ * 更新本地混流编码参数
272
+ * @param params {TRTCMediaMixingEncParam} - 推流视频编码参数、背景色等参数
273
+ * @returns {Promise<void>}
274
+ */
275
+ updatePublishParams(params: TRTCMediaMixingEncParam): Promise<void>;
276
+ /**
277
+ * 设置连麦视频流布局
278
+ *
279
+ * @param layout {TRTCStreamLayout} - 视频流布局信息
280
+ *
281
+ * @example
282
+ * // 设置自定义连麦布局
283
+ * import TRTCCloud, { TRTCStreamLayout, TRTCStreamLayoutMode, TRTCVideoFillMode } from 'trtc-electron-sdk';
284
+ *
285
+ * const trtcCloud = TRTCCloud.getTRTCShareInstance({
286
+ * isIPCMode: true
287
+ * });
288
+ *
289
+ * const mediaMixingManager = trtcCloud.getMediaMixingManager();
290
+ * if (mediaMixingManager) {
291
+ * const streamLayout: TRTCStreamLayout = {
292
+ * "layoutMode": TRTCStreamLayoutMode.Custom,
293
+ * "userList": [
294
+ * {
295
+ * "userId": "", // 本地用户 userId
296
+ * "rect": {
297
+ * "left": 0,
298
+ * "top": 0,
299
+ * "right": 296,
300
+ * "bottom": 494
301
+ * },
302
+ * "fillMode": TRTCVideoFillMode.TRTCVideoFillMode_Fill, // 视频填满显示区
303
+ * "zOrder": 0
304
+ * },
305
+ * {
306
+ * "userId": "849014",
307
+ * "rect": {
308
+ * "left": 296,
309
+ * "top": 0,
310
+ * "right": 592,
311
+ * "bottom": 247
312
+ * },
313
+ * "fillMode": TRTCVideoFillMode.TRTCVideoFillMode_Fill,
314
+ * "zOrder": 1
315
+ * },
316
+ * {
317
+ * "userId": "p20",
318
+ * "rect": {
319
+ * "left": 296,
320
+ * "top": 247,
321
+ * "right": 592,
322
+ * "bottom": 494
323
+ * },
324
+ * "fillMode": TRTCVideoFillMode.TRTCVideoFillMode_Fill,
325
+ * "zOrder": 2
326
+ * }
327
+ * ]
328
+ * };
329
+ * mediaMixingManager.setStreamLayout(streamLayout);
330
+ * }
331
+ *
332
+ * @example
333
+ * // 清除连麦布局,本地混流恢复居中填充显示(默认效果)
334
+ * import TRTCCloud, { TRTCStreamLayout, TRTCStreamLayoutMode, TRTCVideoFillMode } from 'trtc-electron-sdk';
335
+ *
336
+ * const trtcCloud = TRTCCloud.getTRTCShareInstance({
337
+ * isIPCMode: true
338
+ * });
339
+ *
340
+ * const mediaMixingManager = trtcCloud.getMediaMixingManager();
341
+ * if (mediaMixingManager) {
342
+ * const streamLayout: TRTCStreamLayout = {
343
+ * "layoutMode": TRTCStreamLayoutMode.None
344
+ * };
345
+ * mediaMixingManager.setStreamLayout(streamLayout);
346
+ * }
347
+ */
348
+ setStreamLayout(layout: TRTCStreamLayout): void;
349
+ /**
350
+ * @private
351
+ * @deprecated
352
+ */
353
+ setMediaServerPath(path?: string): Promise<void>;
354
+ /**
355
+ * @private
356
+ * 启动独立混流渲染进程
357
+ *
358
+ * 开发模式,默认路径:node_modules\\trtc-electron-sdk\\build\\Release\\liteav_media_server.exe
359
+ * 构建模式,默认路径:${resourcesPath}\\liteav_media_server.exe
360
+ *
361
+ * 如果用户应用有特殊配置,默认路径可能找不到服务进程程序,需要自行传入路径。
362
+ *
363
+ * @param path {string} - 混流渲染程序路径,不传入参数时,SDK 内部按照默认路径启动服务进程。
364
+ *
365
+ * @returns {Promise<void>}
366
+ */
367
+ startMediaMixingServer(path?: string): Promise<void>;
368
+ /**
369
+ * @private
370
+ * 关闭独立混流渲染进程
371
+ *
372
+ * @returns {Promise<void>}
373
+ */
374
+ stopMediaMixingServer(): Promise<void>;
375
+ /**
376
+ * 注册事件监听
377
+ *
378
+ * @param event {TRTCMediaMixingEvent} - 事件名称
379
+ * @param func {Function} - 事件回调函数
380
+ */
381
+ on(event: TRTCMediaMixingEvent, func: (...args: any[]) => void): void;
382
+ /**
383
+ * 取消事件监听
384
+ *
385
+ * @param event {TRTCMediaMixingEvent} - 事件名
386
+ * @param func {Function} - 事件回调函数
387
+ */
388
+ off(event: TRTCMediaMixingEvent, func: (...args: any[]) => void): void;
389
+ private initResizeObserver;
390
+ private onPreviewAreaResize;
391
+ private onVisibilityChange;
392
+ private setDisplayRect;
393
+ private createDesigner;
394
+ private destroyDesigner;
395
+ private updateMixingVideoSize;
396
+ private listenDesignerEvent;
397
+ private unlistenDesignerEvent;
398
+ private onError;
399
+ private onSourceSelected;
400
+ private onSourceMoved;
401
+ private onSourceResized;
402
+ private onRightButtonClicked;
403
+ private isSameMediaSource;
404
+ private isMediaSourceExisted;
405
+ private findMediaSourceIndex;
406
+ private findSelectedMediaSource;
407
+ private unselectMediaSource;
408
+ private handleCppCallbackEvent;
409
+ private onMediaSourceAddedOrRemoved;
410
+ private onMediaSourceSizeChanged;
411
+ private onPhoneMirrorSourceChanged;
412
+ private onMediaServerState;
413
+ private onMediaMixingServerLost;
414
+ private recoverMediaMixingServer;
415
+ startCameraDeviceTest(windowID: number | Uint8Array, rect?: Rect): Promise<number>;
416
+ stopCameraDeviceTest(): Promise<number>;
417
+ setCameraTestRenderMirror(mirror: boolean): void;
418
+ setCameraTestDeviceId(cameraId: string): void;
419
+ setCameraTestResolution(width: number, height: number): void;
420
+ setCameraTestVideoPluginPath(path: string): void;
421
+ setCameraTestVideoPluginParameter(params: string): void;
422
+ }
423
+ export default TRTCMediaMixingManager;