trtc-electron-sdk 12.2.115-beta.2 → 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.
- package/liteav/MediaMixingDesigner/index.d.ts +12 -8
- package/liteav/MediaMixingDesigner/index.js +135 -79
- package/liteav/base/DevicePixelRatioObserver.d.ts +12 -0
- package/liteav/base/DevicePixelRatioObserver.js +32 -0
- package/liteav/base/PromiseStore.d.ts +10 -0
- package/liteav/base/PromiseStore.js +58 -0
- package/liteav/constant.d.ts +1 -0
- package/liteav/constant.js +4 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingManager.d.ts +429 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingManager.js +1290 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingService.d.ts +60 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingService.js +80 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/BaseStreamLayoutManager.d.ts +32 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/BaseStreamLayoutManager.js +114 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/CustomStreamLayoutManager.d.ts +11 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/CustomStreamLayoutManager.js +135 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/NoneStreamLayoutManager.d.ts +11 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/NoneStreamLayoutManager.js +73 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/index.d.ts +7 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/index.js +34 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/types.d.ts +25 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/types.js +2 -0
- package/liteav/extensions/MediaMixingManager/index.d.ts +4 -227
- package/liteav/extensions/MediaMixingManager/index.js +30 -589
- package/liteav/extensions/MediaMixingManager/types.d.ts +107 -0
- package/liteav/extensions/MediaMixingManager/types.js +26 -0
- package/liteav/trtc.d.ts +67 -13
- package/liteav/trtc.js +159 -61
- package/liteav/trtc_define.d.ts +29 -3
- package/liteav/trtc_define.js +97 -29
- package/liteav/utils.d.ts +27 -0
- package/liteav/utils.js +85 -1
- package/package.json +2 -2
- package/scripts/download.js +153 -169
|
@@ -1,592 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
13
20
|
};
|
|
14
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/** 摄像头 */
|
|
28
|
-
kCamera: 0,
|
|
29
|
-
/** 屏幕/窗口分享 */
|
|
30
|
-
kScreen: 1,
|
|
31
|
-
/** 图片 */
|
|
32
|
-
kImage: 2,
|
|
33
|
-
};
|
|
34
|
-
var TRTCMediaSourceType;
|
|
35
|
-
(function (TRTCMediaSourceType) {
|
|
36
|
-
TRTCMediaSourceType[TRTCMediaSourceType["kCamera"] = 0] = "kCamera";
|
|
37
|
-
TRTCMediaSourceType[TRTCMediaSourceType["kScreen"] = 1] = "kScreen";
|
|
38
|
-
TRTCMediaSourceType[TRTCMediaSourceType["kImage"] = 2] = "kImage";
|
|
39
|
-
})(TRTCMediaSourceType = exports.TRTCMediaSourceType || (exports.TRTCMediaSourceType = {}));
|
|
40
|
-
/**
|
|
41
|
-
* 媒体源数据
|
|
42
|
-
*
|
|
43
|
-
* @typedef {Object} TRTCMediaSource
|
|
44
|
-
* @property {TRTCMediaSourceType} sourceType 媒体源类型
|
|
45
|
-
* @property {String} sourceId 媒体源唯一 ID
|
|
46
|
-
* @property {Number} zOrder 媒体源展示层级,取值 0 - 15
|
|
47
|
-
* @property {Rect} rect 媒体源显示区域
|
|
48
|
-
* @property {Boolean} isSelected 媒体源是否选中,可选属性,默认:false
|
|
49
|
-
* @property {TRTCVideoRotation} rotation 媒体源选中角度,可选属性
|
|
50
|
-
* @property {TRTCVideoFillMode} fillMode 媒体源显示模式,可选属性,默认 `TRTCVideoFillMode_Fit`
|
|
51
|
-
* @property {TRTCVideoMirrorType} mirrorType 媒体源是否镜像,可选属性,默认不镜像
|
|
52
|
-
*/
|
|
53
|
-
const TRTCMediaSource_HACK_JSDOC = null;
|
|
54
|
-
/**
|
|
55
|
-
* 媒体源本地混流编码参数
|
|
56
|
-
*
|
|
57
|
-
* @typedef {Object} TRTCMediaMixingEncParam
|
|
58
|
-
* @property {TRTCVideoEncParam} videoEncoderParams 本地混流编码参数
|
|
59
|
-
* @property {Number} canvasColor 混流视频背景色,默认值:0x0 代表黑色。格式为十六进制数字,比如:`0x61B9F1` 代表 RGB 颜色(97、158、241)。
|
|
60
|
-
*/
|
|
61
|
-
const TRTCMediaMixingEncParam_HACK_JSDOC = null;
|
|
62
|
-
/**
|
|
63
|
-
* @namespace TRTCMediaMixingEvent
|
|
64
|
-
* @description 目前只支持 `Windows` 操作系统
|
|
65
|
-
*/
|
|
66
|
-
var TRTCMediaMixingEvent;
|
|
67
|
-
(function (TRTCMediaMixingEvent) {
|
|
68
|
-
/**
|
|
69
|
-
* @description 媒体源选中事件
|
|
70
|
-
*
|
|
71
|
-
* @event TRTCMediaMixingEvent#onSourceSelected
|
|
72
|
-
* @param {TRTCMediaInfo | null} mediaSource 新选中的媒体源数据,取消选中则为`null`
|
|
73
|
-
*/
|
|
74
|
-
TRTCMediaMixingEvent["onSourceSelected"] = "onSourceSelected";
|
|
75
|
-
/**
|
|
76
|
-
* @description 媒体源移动事件
|
|
77
|
-
*
|
|
78
|
-
* @event TRTCMediaMixingEvent#onSourceMoved
|
|
79
|
-
* @param {TRTCMediaInfo} mediaSource 被移动的媒体源
|
|
80
|
-
* @param {Rect} rect 移动后的位置、区域数据
|
|
81
|
-
*/
|
|
82
|
-
TRTCMediaMixingEvent["onSourceMoved"] = "onSourceMoved";
|
|
83
|
-
/**
|
|
84
|
-
* @description 媒体源尺寸变化事件
|
|
85
|
-
*
|
|
86
|
-
* @event TRTCMediaMixingEvent#onSourceResized
|
|
87
|
-
* @param {TRTCMediaInfo} mediaSource 尺寸变化的媒体源
|
|
88
|
-
* @param {Rect} rect 尺寸变化后的位置、区域数据
|
|
89
|
-
*/
|
|
90
|
-
TRTCMediaMixingEvent["onSourceResized"] = "onSourceResized";
|
|
91
|
-
/**
|
|
92
|
-
* @description 媒体源鼠标右键事件
|
|
93
|
-
*
|
|
94
|
-
* @event TRTCMediaMixingEvent#onRightButtonClicked
|
|
95
|
-
* @param {TRTCMediaInfo} mediaSource 鼠标右键点击的媒体源
|
|
96
|
-
*/
|
|
97
|
-
TRTCMediaMixingEvent["onRightButtonClicked"] = "onRightButtonClicked";
|
|
98
|
-
})(TRTCMediaMixingEvent = exports.TRTCMediaMixingEvent || (exports.TRTCMediaMixingEvent = {}));
|
|
99
|
-
var TRTCMediaMixingErrorCode;
|
|
100
|
-
(function (TRTCMediaMixingErrorCode) {
|
|
101
|
-
TRTCMediaMixingErrorCode[TRTCMediaMixingErrorCode["Success"] = 0] = "Success";
|
|
102
|
-
TRTCMediaMixingErrorCode[TRTCMediaMixingErrorCode["Error"] = -1] = "Error";
|
|
103
|
-
TRTCMediaMixingErrorCode[TRTCMediaMixingErrorCode["InvalidParams"] = -2] = "InvalidParams";
|
|
104
|
-
TRTCMediaMixingErrorCode[TRTCMediaMixingErrorCode["NotFoundSource"] = -3] = "NotFoundSource";
|
|
105
|
-
TRTCMediaMixingErrorCode[TRTCMediaMixingErrorCode["ImageSourceLoadFailed"] = -4] = "ImageSourceLoadFailed";
|
|
106
|
-
})(TRTCMediaMixingErrorCode = exports.TRTCMediaMixingErrorCode || (exports.TRTCMediaMixingErrorCode = {}));
|
|
107
|
-
/**
|
|
108
|
-
* 本地混流管理器
|
|
109
|
-
*/
|
|
110
|
-
class TRTCMediaMixingManager {
|
|
111
|
-
constructor(options) {
|
|
112
|
-
this.logPrefix = '[TRTCMediaMixingManager]';
|
|
113
|
-
this.mediaMixingDesigner = null;
|
|
114
|
-
this.windowID = 0;
|
|
115
|
-
this.view = null;
|
|
116
|
-
this.resizeObserver = null;
|
|
117
|
-
this.sourceList = [];
|
|
118
|
-
this.eventEmitter = new events_1.EventEmitter();
|
|
119
|
-
this.eventHandler = this.eventHandler.bind(this);
|
|
120
|
-
this.nodeMediaMixingPlugin = new NodeTRTCEngine.NodeRemoteMultiSourcePlugin();
|
|
121
|
-
this.nodeMediaMixingPlugin.setRemoteMultiSourcePluginCallback(this.eventHandler);
|
|
122
|
-
this.deviceManager = options.deviceManager;
|
|
123
|
-
this.nodeTRTCCloud = options.nodeTRTCCloud;
|
|
124
|
-
this.setMediaServerPath('');
|
|
125
|
-
this.publishParams = {
|
|
126
|
-
videoEncoderParams: {
|
|
127
|
-
videoResolution: trtc_define_1.TRTCVideoResolution.TRTCVideoResolution_1920_1080,
|
|
128
|
-
resMode: trtc_define_1.TRTCVideoResolutionMode.TRTCVideoResolutionModeLandscape,
|
|
129
|
-
videoFps: 30,
|
|
130
|
-
videoBitrate: 3000,
|
|
131
|
-
minVideoBitrate: 3000,
|
|
132
|
-
enableAdjustRes: true,
|
|
133
|
-
},
|
|
134
|
-
canvasColor: 0x0
|
|
135
|
-
};
|
|
136
|
-
this.onSourceSelected = this.onSourceSelected.bind(this);
|
|
137
|
-
this.onSourceMoved = this.onSourceMoved.bind(this);
|
|
138
|
-
this.onSourceResized = this.onSourceResized.bind(this);
|
|
139
|
-
this.onRightButtonClicked = this.onRightButtonClicked.bind(this);
|
|
140
|
-
this.onPreviewAreaResize = this.onPreviewAreaResize.bind(this);
|
|
141
|
-
this.onVisibilityChange = this.onVisibilityChange.bind(this);
|
|
142
|
-
document.addEventListener('visibilitychange', this.onVisibilityChange);
|
|
143
|
-
}
|
|
144
|
-
destroy() {
|
|
145
|
-
document.removeEventListener('visibilitychange', this.onVisibilityChange);
|
|
146
|
-
if (this.resizeObserver && this.view) {
|
|
147
|
-
this.resizeObserver.unobserve(this.view);
|
|
148
|
-
this.resizeObserver.disconnect();
|
|
149
|
-
}
|
|
150
|
-
this.view = null;
|
|
151
|
-
this.windowID = 0;
|
|
152
|
-
this.destroyDesigner();
|
|
153
|
-
this.nodeTRTCCloud = null;
|
|
154
|
-
this.deviceManager = null;
|
|
155
|
-
this.nodeMediaMixingPlugin = null;
|
|
156
|
-
this.eventEmitter = null;
|
|
157
|
-
}
|
|
158
|
-
eventHandler(args) {
|
|
159
|
-
logger_1.default.log(`${this.logPrefix} event:`, args);
|
|
160
|
-
// const key = args[0] as string;
|
|
161
|
-
// const data = args[1] as { [key: string]: never };
|
|
162
|
-
// To do: 待完善
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* 设置混流视频预览参数
|
|
166
|
-
*
|
|
167
|
-
* @param windowID {Number|Uint8Array} - 操作系统层的窗口 ID,Electron 下可以通过 Electron API [BrowserWindow.getNativeWindowHandle()]{@link https://www.electronjs.org/docs/latest/api/browser-window#wingetnativewindowhandle} 接口获取
|
|
168
|
-
* @param viewOrRegion {HTMLElement | Rect | null} - 本地混流视频显示位置
|
|
169
|
-
* - 传入 HTMLElement 元素,则 SDK 将本地混流视频显示在 HTMLElement 元素内,同时支持点击选中、移动、缩放媒体源,支持触发右键菜单事件。HTMLElement 元素必须是块元素。
|
|
170
|
-
* - 传入 Rect 显示区域,则 SDK 将本地混流视频显示在 Rect 指定区域内,不支持点击选中、移动、缩放媒体源,不支持触发右键菜单事件,这些功能您可以在 Web 页面中自行实现。
|
|
171
|
-
* - 传入 null 则 SDK 将停止显示本地混流视频。
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* // Display in HTML Element
|
|
175
|
-
* import TRTCCloud from 'trtc-electron-sdk';
|
|
176
|
-
*
|
|
177
|
-
* const trtcCloud = TRTCCloud.getTRTCShareInstance({
|
|
178
|
-
* isIPCMode: true
|
|
179
|
-
* });
|
|
180
|
-
*
|
|
181
|
-
* const mediaMixingManager = trtcCloud.getMediaMixingManager();
|
|
182
|
-
*
|
|
183
|
-
* const windowID = 0; // Use Electron API BrowserWindow.getNativeWindowHandle()
|
|
184
|
-
* const previewDOM = document.getElementById("preview-local-mixed-media-stream");
|
|
185
|
-
* mediaMixingManager.setDisplayParams(windowID, previewDOM);
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
188
|
-
* // Display in a rectangle section
|
|
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
|
-
* const domRect = previewDOM.getBoundingClientRect();
|
|
200
|
-
* const rect = {
|
|
201
|
-
* left: domRect.left * window.devicePixelRatio,
|
|
202
|
-
* right: domRect.right * window.devicePixelRatio,
|
|
203
|
-
* top: domRect.top * window.devicePixelRatio,
|
|
204
|
-
* bottom: domRect.bottom * window.devicePixelRatio
|
|
205
|
-
* };
|
|
206
|
-
*
|
|
207
|
-
* mediaMixingManager.setDisplayParams(windowID, previewDOM);
|
|
208
|
-
*/
|
|
209
|
-
setDisplayParams(windowID, viewOrRegion) {
|
|
210
|
-
logger_1.default.log(`${this.logPrefix}setDisplayParams:`, windowID, viewOrRegion);
|
|
211
|
-
let newWindowID = 0;
|
|
212
|
-
if (windowID instanceof Uint8Array) {
|
|
213
|
-
newWindowID = (0, utils_1.convertUint8ArrayToNumber)(windowID);
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
newWindowID = windowID;
|
|
217
|
-
}
|
|
218
|
-
this.windowID = newWindowID;
|
|
219
|
-
if (newWindowID !== 0 && viewOrRegion !== null) {
|
|
220
|
-
if (viewOrRegion instanceof HTMLElement) {
|
|
221
|
-
this.destroyDesigner();
|
|
222
|
-
this.view = viewOrRegion;
|
|
223
|
-
this.setDisplayRect();
|
|
224
|
-
this.initResizeObserver();
|
|
225
|
-
this.createDesigner();
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
// Rect
|
|
229
|
-
this.nodeMediaMixingPlugin.setDisplayParams(newWindowID, viewOrRegion);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
this.destroyDesigner();
|
|
234
|
-
this.nodeMediaMixingPlugin.setDisplayParams(newWindowID, { left: 0, right: 0, top: 0, bottom: 0 });
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* 添加媒体源
|
|
239
|
-
* @param mediaSource {TRTCMediaSource} - 媒体源信息
|
|
240
|
-
* @returns {Promise<Rect>}
|
|
241
|
-
*/
|
|
242
|
-
addMediaSource(mediaSource) {
|
|
243
|
-
var _a;
|
|
244
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
-
logger_1.default.log(`${this.logPrefix}addMediaSource:`, mediaSource);
|
|
246
|
-
const index = this.findMediaSourceIndex(mediaSource);
|
|
247
|
-
if (index !== -1) {
|
|
248
|
-
throw new Error("Media source already existed");
|
|
249
|
-
}
|
|
250
|
-
const newMediaSource = (0, utils_1.safelyParse)(JSON.stringify(mediaSource));
|
|
251
|
-
if (newMediaSource.isSelected) {
|
|
252
|
-
const oldSelectedIndex = this.findSelectedMediaSource();
|
|
253
|
-
if (oldSelectedIndex !== -1) {
|
|
254
|
-
this.unselectMediaSource(oldSelectedIndex);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
const rect = yield this.nodeMediaMixingPlugin.addMediaSource(newMediaSource);
|
|
258
|
-
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.addMedia({
|
|
259
|
-
id: `${newMediaSource.sourceType}__${newMediaSource.sourceId}`,
|
|
260
|
-
rect: newMediaSource.rect,
|
|
261
|
-
isSelected: newMediaSource.isSelected || false,
|
|
262
|
-
origin: newMediaSource
|
|
263
|
-
});
|
|
264
|
-
this.sourceList.push(newMediaSource);
|
|
265
|
-
return rect;
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* 删除媒体源
|
|
270
|
-
* @param mediaSource {TRTCMediaSource} - 媒体源信息
|
|
271
|
-
* @returns {Promise<void>}
|
|
272
|
-
*/
|
|
273
|
-
removeMediaSource(mediaSource) {
|
|
274
|
-
var _a;
|
|
275
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
-
logger_1.default.log(`${this.logPrefix}removeMediaSource:`, mediaSource);
|
|
277
|
-
const index = this.findMediaSourceIndex(mediaSource);
|
|
278
|
-
if (index === -1) {
|
|
279
|
-
throw new Error("Not existing media source to remove");
|
|
280
|
-
}
|
|
281
|
-
yield this.nodeMediaMixingPlugin.removeMediaSource(mediaSource);
|
|
282
|
-
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.removeMedia({
|
|
283
|
-
id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
|
|
284
|
-
rect: mediaSource.rect,
|
|
285
|
-
isSelected: mediaSource.isSelected || false,
|
|
286
|
-
origin: (0, utils_1.safelyParse)(JSON.stringify(mediaSource))
|
|
287
|
-
});
|
|
288
|
-
this.sourceList.splice(index, 1);
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* 更新媒体源
|
|
293
|
-
* @param mediaSource {TRTCMediaSource} - 媒体源信息
|
|
294
|
-
* @returns {Promise<void>}
|
|
295
|
-
*/
|
|
296
|
-
updateMediaSource(mediaSource) {
|
|
297
|
-
var _a;
|
|
298
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
299
|
-
logger_1.default.log(`${this.logPrefix}updateMediaSource:`, mediaSource);
|
|
300
|
-
const index = this.findMediaSourceIndex(mediaSource);
|
|
301
|
-
if (index === -1) {
|
|
302
|
-
throw new Error("Not existing media source to update");
|
|
303
|
-
}
|
|
304
|
-
const newMediaSource = Object.assign(Object.assign({}, this.sourceList[index]), (0, utils_1.safelyParse)(JSON.stringify(mediaSource)));
|
|
305
|
-
if (mediaSource.isSelected) {
|
|
306
|
-
const oldSelectedIndex = this.findSelectedMediaSource();
|
|
307
|
-
if (oldSelectedIndex !== -1 && oldSelectedIndex !== index) {
|
|
308
|
-
this.unselectMediaSource(oldSelectedIndex);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
yield this.nodeMediaMixingPlugin.updateMediaSource(newMediaSource);
|
|
312
|
-
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.updateMedia({
|
|
313
|
-
id: `${mediaSource.sourceType}__${mediaSource.sourceId}`,
|
|
314
|
-
rect: mediaSource.rect,
|
|
315
|
-
isSelected: mediaSource.isSelected || false,
|
|
316
|
-
origin: (0, utils_1.safelyParse)(JSON.stringify(mediaSource))
|
|
317
|
-
});
|
|
318
|
-
this.sourceList[index] = newMediaSource;
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* 设置摄像头采集参数
|
|
323
|
-
* @param cameraID {string} - 摄像头 ID
|
|
324
|
-
* @param params {TRTCCameraCaptureParams} - 摄像头采集参数
|
|
325
|
-
*/
|
|
326
|
-
setCameraCaptureParam(cameraID, params) {
|
|
327
|
-
this.nodeMediaMixingPlugin.setCameraCaptureParam(cameraID, params);
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* 开始推流
|
|
331
|
-
* @returns {Promise<void>}
|
|
332
|
-
*/
|
|
333
|
-
startPublish() {
|
|
334
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
335
|
-
logger_1.default.log(`${this.logPrefix}startPublish`);
|
|
336
|
-
return yield this.nodeMediaMixingPlugin.startPublish();
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* 停止推流
|
|
341
|
-
* @returns {Promise<void>}
|
|
342
|
-
*/
|
|
343
|
-
stopPublish() {
|
|
344
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
345
|
-
logger_1.default.log(`${this.logPrefix}stopPublish`);
|
|
346
|
-
return yield this.nodeMediaMixingPlugin.stopPublish();
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* 更新本地混流编码参数
|
|
351
|
-
* @param params {TRTCMediaMixingEncParam} - 推流视频编码参数、背景色等参数
|
|
352
|
-
* @returns {Promise<void>}
|
|
353
|
-
*/
|
|
354
|
-
updatePublishParams(params) {
|
|
355
|
-
var _a;
|
|
356
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
357
|
-
logger_1.default.log(`${this.logPrefix}updatePublishParams:`, params);
|
|
358
|
-
this.publishParams = params;
|
|
359
|
-
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.updateOptions({
|
|
360
|
-
videoResolution: this.publishParams.videoEncoderParams.videoResolution,
|
|
361
|
-
resMode: this.publishParams.videoEncoderParams.resMode
|
|
362
|
-
});
|
|
363
|
-
return yield this.nodeMediaMixingPlugin.updatePublishParams(params);
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* @private
|
|
368
|
-
* 设置服务进程程序路径
|
|
369
|
-
*
|
|
370
|
-
* 开发模式,默认路径:node_modules\\trtc-electron-sdk\\build\\Release\\liteav_media_server.exe
|
|
371
|
-
* 构建模式,默认路径:${resourcesPath}\\liteav_media_server.exe
|
|
372
|
-
*
|
|
373
|
-
* 如果用户应用有特殊配置,默认路径可能找不到服务进程程序,需要自行传入路径。
|
|
374
|
-
*
|
|
375
|
-
* @param path {string} - 服务进程程序路径
|
|
376
|
-
*
|
|
377
|
-
* @returns {Promise<void>}
|
|
378
|
-
*/
|
|
379
|
-
setMediaServerPath(path) {
|
|
380
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
381
|
-
let serverPath = '';
|
|
382
|
-
if (path && path.trim() !== '') {
|
|
383
|
-
serverPath = path;
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
const { resourcesPath, execPath } = globalThis.process;
|
|
387
|
-
if (execPath.endsWith('electron.exe')) {
|
|
388
|
-
serverPath = '..\\..\\..\\..\\node_modules\\trtc-electron-sdk\\build\\Release\\liteav_media_server.exe';
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
serverPath = `${resourcesPath}\\liteav_media_server.exe`;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
logger_1.default.log(`${this.logPrefix} server path:${serverPath}`);
|
|
395
|
-
return yield this.nodeMediaMixingPlugin.setMediaServerPath(serverPath);
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* 注册事件监听
|
|
400
|
-
*
|
|
401
|
-
* @param event {TRTCMediaMixingEvent} - 事件名称
|
|
402
|
-
* @param func {Function} - 事件回调函数
|
|
403
|
-
*/
|
|
404
|
-
on(event, func) {
|
|
405
|
-
var _a;
|
|
406
|
-
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.on(event, func);
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* 取消事件监听
|
|
410
|
-
*
|
|
411
|
-
* @param event {TRTCMediaMixingEvent} - 事件名
|
|
412
|
-
* @param func {Function} - 事件回调函数
|
|
413
|
-
*/
|
|
414
|
-
off(event, func) {
|
|
415
|
-
var _a;
|
|
416
|
-
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.off(event, func);
|
|
417
|
-
}
|
|
418
|
-
initResizeObserver() {
|
|
419
|
-
if (this.view) {
|
|
420
|
-
this.resizeObserver = new ResizeObserver(this.onPreviewAreaResize);
|
|
421
|
-
this.resizeObserver.observe(this.view);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
onPreviewAreaResize(entries) {
|
|
425
|
-
logger_1.default.log(`${this.logPrefix}onPreviewAreaResize:`, entries);
|
|
426
|
-
for (const entry of entries) {
|
|
427
|
-
if (this.windowID && entry.target === this.view) {
|
|
428
|
-
this.setDisplayRect();
|
|
429
|
-
break;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
onVisibilityChange() {
|
|
434
|
-
logger_1.default.log(`${this.logPrefix}onVisibilityChange document.hidden:${document.hidden}`);
|
|
435
|
-
if (document.hidden) {
|
|
436
|
-
this.setDisplayParams(this.windowID, { left: 0, right: 0, top: 0, bottom: 0 });
|
|
437
|
-
}
|
|
438
|
-
else {
|
|
439
|
-
this.setDisplayRect();
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
setDisplayRect() {
|
|
443
|
-
if (this.windowID && this.view) {
|
|
444
|
-
const clientRect = this.view.getBoundingClientRect();
|
|
445
|
-
const rect = {
|
|
446
|
-
left: clientRect.left * window.devicePixelRatio,
|
|
447
|
-
right: clientRect.right * window.devicePixelRatio,
|
|
448
|
-
top: clientRect.top * window.devicePixelRatio,
|
|
449
|
-
bottom: clientRect.bottom * window.devicePixelRatio,
|
|
450
|
-
};
|
|
451
|
-
this.nodeMediaMixingPlugin.setDisplayParams(this.windowID, rect);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
createDesigner() {
|
|
455
|
-
var _a, _b;
|
|
456
|
-
if (this.view) {
|
|
457
|
-
this.mediaMixingDesigner = new index_1.default({
|
|
458
|
-
view: this.view,
|
|
459
|
-
videoResolution: ((_a = this.publishParams) === null || _a === void 0 ? void 0 : _a.videoEncoderParams.videoResolution) || trtc_define_1.TRTCVideoResolution.TRTCVideoResolution_1920_1080,
|
|
460
|
-
resMode: ((_b = this.publishParams) === null || _b === void 0 ? void 0 : _b.videoEncoderParams.resMode) || trtc_define_1.TRTCVideoResolutionMode.TRTCVideoResolutionModeLandscape,
|
|
461
|
-
canExceedContainer: true,
|
|
462
|
-
});
|
|
463
|
-
this.listenDesignerEvent();
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
destroyDesigner() {
|
|
467
|
-
var _a;
|
|
468
|
-
if (this.mediaMixingDesigner) {
|
|
469
|
-
this.unlistenDesignerEvent();
|
|
470
|
-
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
471
|
-
this.mediaMixingDesigner = null;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
listenDesignerEvent() {
|
|
475
|
-
var _a, _b, _c, _d, _e;
|
|
476
|
-
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.on('onError', this.onError);
|
|
477
|
-
(_b = this.mediaMixingDesigner) === null || _b === void 0 ? void 0 : _b.on('onSourceSelected', this.onSourceSelected);
|
|
478
|
-
(_c = this.mediaMixingDesigner) === null || _c === void 0 ? void 0 : _c.on('onSourceMoved', this.onSourceMoved);
|
|
479
|
-
(_d = this.mediaMixingDesigner) === null || _d === void 0 ? void 0 : _d.on('onSourceResized', this.onSourceResized);
|
|
480
|
-
(_e = this.mediaMixingDesigner) === null || _e === void 0 ? void 0 : _e.on('onRightButtonClicked', this.onRightButtonClicked);
|
|
481
|
-
}
|
|
482
|
-
unlistenDesignerEvent() {
|
|
483
|
-
var _a, _b, _c, _d, _e;
|
|
484
|
-
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.off('onError', this.onError);
|
|
485
|
-
(_b = this.mediaMixingDesigner) === null || _b === void 0 ? void 0 : _b.off('onSourceSelected', this.onSourceSelected);
|
|
486
|
-
(_c = this.mediaMixingDesigner) === null || _c === void 0 ? void 0 : _c.off('onSourceMoved', this.onSourceMoved);
|
|
487
|
-
(_d = this.mediaMixingDesigner) === null || _d === void 0 ? void 0 : _d.off('onSourceResized', this.onSourceResized);
|
|
488
|
-
(_e = this.mediaMixingDesigner) === null || _e === void 0 ? void 0 : _e.off('onRightButtonClicked', this.onRightButtonClicked);
|
|
489
|
-
}
|
|
490
|
-
onError(errorCode, errorMessage) {
|
|
491
|
-
logger_1.default.log(`${this.logPrefix}onError:`, errorCode, errorMessage);
|
|
492
|
-
}
|
|
493
|
-
onSourceSelected(media) {
|
|
494
|
-
var _a;
|
|
495
|
-
logger_1.default.log(`${this.logPrefix}onSourceSelected:`, media);
|
|
496
|
-
if (media === null || media === void 0 ? void 0 : media.origin) {
|
|
497
|
-
this.updateMediaSource(Object.assign(Object.assign({}, media.origin), { isSelected: true }));
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
const selected = this.sourceList.find(item => item.isSelected);
|
|
501
|
-
if (selected) {
|
|
502
|
-
this.updateMediaSource(Object.assign(Object.assign({}, selected), { isSelected: false }));
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit('onSourceSelected', media ? media.origin : null);
|
|
506
|
-
}
|
|
507
|
-
onSourceMoved(media, rect) {
|
|
508
|
-
var _a;
|
|
509
|
-
logger_1.default.log(`${this.logPrefix}onSourceMoved:`, media, rect);
|
|
510
|
-
if (media === null || media === void 0 ? void 0 : media.origin) {
|
|
511
|
-
this.updateMediaSource(Object.assign(Object.assign({}, media.origin), { rect }));
|
|
512
|
-
}
|
|
513
|
-
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit('onSourceMoved', media.origin, rect);
|
|
514
|
-
}
|
|
515
|
-
onSourceResized(media, rect) {
|
|
516
|
-
var _a;
|
|
517
|
-
logger_1.default.log(`${this.logPrefix}onSourceResized:`, media, rect);
|
|
518
|
-
if (media === null || media === void 0 ? void 0 : media.origin) {
|
|
519
|
-
this.updateMediaSource(Object.assign(Object.assign({}, media.origin), { rect }));
|
|
520
|
-
}
|
|
521
|
-
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit('onSourceResized', media.origin, rect);
|
|
522
|
-
}
|
|
523
|
-
onRightButtonClicked(media) {
|
|
524
|
-
var _a;
|
|
525
|
-
logger_1.default.log(`${this.logPrefix}onRightButtonClicked:`, media);
|
|
526
|
-
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit('onRightButtonClicked', media.origin);
|
|
527
|
-
}
|
|
528
|
-
isSameMediaSource(mediaSource1, mediaSource2) {
|
|
529
|
-
return mediaSource1.sourceId === mediaSource2.sourceId && mediaSource1.sourceType === mediaSource2.sourceType;
|
|
530
|
-
}
|
|
531
|
-
isMediaSourceExisted(mediaSource) {
|
|
532
|
-
return this.sourceList.some(item => this.isSameMediaSource(item, mediaSource));
|
|
533
|
-
}
|
|
534
|
-
findMediaSourceIndex(mediaSource) {
|
|
535
|
-
return this.sourceList.findIndex(item => item.sourceId === mediaSource.sourceId && item.sourceType === mediaSource.sourceType);
|
|
536
|
-
}
|
|
537
|
-
findSelectedMediaSource() {
|
|
538
|
-
let index = -1;
|
|
539
|
-
const length = this.sourceList.length;
|
|
540
|
-
for (let i = 0; i < length; i++) {
|
|
541
|
-
if (this.sourceList[i].isSelected) {
|
|
542
|
-
index = i;
|
|
543
|
-
break;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
return index;
|
|
547
|
-
}
|
|
548
|
-
unselectMediaSource(index) {
|
|
549
|
-
var _a;
|
|
550
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
551
|
-
this.sourceList[index].isSelected = false;
|
|
552
|
-
yield this.nodeMediaMixingPlugin.updateMediaSource(this.sourceList[index]);
|
|
553
|
-
(_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.updateMedia({
|
|
554
|
-
id: `${this.sourceList[index].sourceType}__${this.sourceList[index].sourceId}`,
|
|
555
|
-
rect: this.sourceList[index].rect,
|
|
556
|
-
isSelected: this.sourceList[index].isSelected || false,
|
|
557
|
-
origin: (0, utils_1.safelyParse)(JSON.stringify(this.sourceList[index]))
|
|
558
|
-
});
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
// ****** 这一部分接口暴露不合理,暂时不对暴露在 API 文档上 **************/
|
|
562
|
-
startCameraDeviceTest(windowID, rect) {
|
|
563
|
-
var _a;
|
|
564
|
-
return ((_a = this.deviceManager) === null || _a === void 0 ? void 0 : _a.startCameraDeviceTest(windowID, rect)) || Promise.reject();
|
|
565
|
-
}
|
|
566
|
-
stopCameraDeviceTest() {
|
|
567
|
-
var _a;
|
|
568
|
-
return ((_a = this.deviceManager) === null || _a === void 0 ? void 0 : _a.stopCameraDeviceTest()) || Promise.reject();
|
|
569
|
-
}
|
|
570
|
-
setCameraTestRenderMirror(mirror) {
|
|
571
|
-
var _a;
|
|
572
|
-
(_a = this.deviceManager) === null || _a === void 0 ? void 0 : _a.setCameraTestRenderMirror(mirror);
|
|
573
|
-
}
|
|
574
|
-
setCameraTestDeviceId(cameraId) {
|
|
575
|
-
var _a;
|
|
576
|
-
(_a = this.deviceManager) === null || _a === void 0 ? void 0 : _a.setCameraTestDeviceId(cameraId);
|
|
577
|
-
}
|
|
578
|
-
setCameraTestResolution(width, height) {
|
|
579
|
-
var _a;
|
|
580
|
-
(_a = this.deviceManager) === null || _a === void 0 ? void 0 : _a.setCameraTestResolution(width, height);
|
|
581
|
-
}
|
|
582
|
-
setCameraTestVideoPluginPath(path) {
|
|
583
|
-
var _a;
|
|
584
|
-
(_a = this.deviceManager) === null || _a === void 0 ? void 0 : _a.setCameraTestVideoPluginPath(path);
|
|
585
|
-
}
|
|
586
|
-
setCameraTestVideoPluginParameter(params) {
|
|
587
|
-
var _a;
|
|
588
|
-
(_a = this.deviceManager) === null || _a === void 0 ? void 0 : _a.setCameraTestVideoPluginParameter(params);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
exports.TRTCMediaMixingManager = TRTCMediaMixingManager;
|
|
592
|
-
exports.default = TRTCMediaMixingManager;
|
|
22
|
+
exports.TRTCMediaMixingServiceEvent = exports.TRTCMediaMixingEvent = exports.TRTCMediaMixingService = exports.TRTCMediaMixingManager = exports.TRTCStreamLayoutMode = exports.TRTCMediaSourceType = exports.TRTCMediaMixingErrorCode = void 0;
|
|
23
|
+
const MediaMixingManager_1 = __importStar(require("./MediaMixingManager"));
|
|
24
|
+
exports.TRTCMediaMixingManager = MediaMixingManager_1.default;
|
|
25
|
+
Object.defineProperty(exports, "TRTCMediaMixingEvent", { enumerable: true, get: function () { return MediaMixingManager_1.TRTCMediaMixingEvent; } });
|
|
26
|
+
const MediaMixingService_1 = __importStar(require("./MediaMixingService"));
|
|
27
|
+
exports.TRTCMediaMixingService = MediaMixingService_1.default;
|
|
28
|
+
Object.defineProperty(exports, "TRTCMediaMixingServiceEvent", { enumerable: true, get: function () { return MediaMixingService_1.TRTCMediaMixingServiceEvent; } });
|
|
29
|
+
var types_1 = require("./types");
|
|
30
|
+
Object.defineProperty(exports, "TRTCMediaMixingErrorCode", { enumerable: true, get: function () { return types_1.TRTCMediaMixingErrorCode; } });
|
|
31
|
+
Object.defineProperty(exports, "TRTCMediaSourceType", { enumerable: true, get: function () { return types_1.TRTCMediaSourceType; } });
|
|
32
|
+
Object.defineProperty(exports, "TRTCStreamLayoutMode", { enumerable: true, get: function () { return types_1.TRTCStreamLayoutMode; } });
|
|
33
|
+
exports.default = MediaMixingManager_1.default;
|