yjz-web-sdk 1.0.11-beta.3 → 1.0.11-beta.4

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/lib/uni-sdk.js ADDED
@@ -0,0 +1,1260 @@
1
+ !function(){"use strict";try{if("undefined"!=typeof document){var e=document.createElement("style");e.appendChild(document.createTextNode(".vContainer[data-v-ae395fc8]{transition:transform .2s linear;transform-origin:center center;margin:0;overflow:hidden;background:transparent;transform:translateZ(0);will-change:transform}.flex[data-v-ae395fc8]{display:flex}.flex-1[data-v-ae395fc8]{flex:1 1 0}.items-center[data-v-ae395fc8]{align-items:center}.justify-center[data-v-ae395fc8]{justify-content:center}.video-control[data-v-ae395fc8]{width:100%;height:100%;display:block;-webkit-user-select:none;user-select:none;object-fit:cover;background:transparent;clip-path:inset(0 1px);-webkit-user-drag:none;touch-action:none;backface-visibility:hidden;-webkit-backface-visibility:hidden;transform:translateZ(0)}.circle-cursor[data-v-ae395fc8]{cursor:url(\"data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20fill='none'%3e%3ccircle%20cx='12'%20cy='12'%20r='12'%20fill='%23fff'%20opacity='.6'/%3e%3ccircle%20cx='12'%20cy='12'%20r='10'%20fill='%23000'%20opacity='.6'/%3e%3c/svg%3e\") 12 12,auto}.triangle-cursor[data-v-ae395fc8]{cursor:url(\"data:image/svg+xml,%3csvg%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20width='22'%20height='22'%3e%3cpath%20d='M143.832313%205.834982H143.686438A108.676545%20108.676545%200%200%200%205.834982%20143.686438l34.499333-11.815839-34.499333%2011.815839%200.072938%200.218812%200.145874%200.437624%200.583498%201.750494%202.333993%206.71023%208.752474%2025.528047L49.232663%20269.867929a2254749.467572%202254749.467572%200%200%201%20223.917444%20652.351017l9.335972%2027.205605%202.552804%207.585476%200.729373%202.188119a72.572592%2072.572592%200%200%200%20126.181491%2040.844876%2072.134968%2072.134968%200%200%200%2014.076895-18.963693c3.282178-6.41848%205.689108-13.639271%208.023101-20.3495l0.072937-0.291749%2072.572592-209.329989%2047.409231-136.830334%2015.53564-44.710551%200.145874-0.364687%200.510561-0.145874%2045.002301-15.900327%20137.486769-48.649165c99.340573-35.228705%20202.984445-71.989094%20209.913487-74.906584l3.355115-1.312871c8.023101-3.136303%2022.391744-8.606599%2033.915834-20.130689a72.499655%2072.499655%200%200%200%200-102.549813L999.240712%20304.877823c-1.823432-1.969307-7.293728-7.731351-13.274585-11.961714a89.056417%2089.056417%200%200%200-27.205605-12.3264h-0.145874l-2.552805-0.875247L948.184617%20277.161657l-27.86204-9.263034-94.672588-31.800653A405018.007245%20405018.007245%200%200%201%20268.919745%2048.138604L178.039896%2017.504947%20152.657723%208.752473%20145.874556%206.637292%20144.196999%205.90792%20143.832313%205.834982z'%20fill='%23000000'%20opacity='.7'%3e%3c/path%3e%3c/svg%3e\") 1 1,auto}.default-cursor[data-v-ae395fc8]{cursor:default}.no-events[data-v-ae395fc8]{pointer-events:none!important}.ime-input[data-v-ae395fc8]{position:absolute;opacity:0;right:0;bottom:0;width:1px;height:1px;border:none;outline:none;resize:none;z-index:-1}.hb-player-container{position:relative;display:flex;flex:1 1 0;align-items:center;justify-content:center;width:100%;height:100%;overflow:hidden}.hb-keyboard-container{position:relative;width:100%;height:100%;transition:transform .2s linear;transform-origin:center center;transform:translateZ(0);will-change:transform;margin:0;overflow:hidden}.hb-remote-video{width:100%;height:100%;display:block;-webkit-user-select:none;user-select:none;-webkit-user-drag:none;touch-action:none;object-fit:cover;backface-visibility:hidden;transform:translateZ(0);clip-path:inset(0 1px)}.hb-ime-input{position:absolute;opacity:0;right:0;bottom:0;width:1px;height:1px;border:none;outline:none;resize:none;z-index:-1}.circle-cursor{cursor:url(@/assets/icon/circle.svg) 12 12,auto}.triangle-cursor{cursor:url(@/assets/icon/triangle.svg) 1 1,auto}.default-cursor{cursor:default}.no-events{pointer-events:none!important}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}}();
2
+ var __defProp = Object.defineProperty;
3
+ var __typeError = (msg) => {
4
+ throw TypeError(msg);
5
+ };
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
9
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
10
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
11
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
12
+ var _screenStatus, _isComposing, _direction, _screenWidth, _screenHeight, _clarityLevel, _gestureMode;
13
+ import { W as WheelData, t as transformCoordinate, A as ActionType, v as valueToPercentage, T as TouchData, g as getKeyEventData, I as InputData, i as isFunctionKey, E as EventEmitter, C as ChannelDataType, a as WebRTCSdk, b as EmitType, F as FailCode, c as ContainerDirection, K as KeyEventData, j as ActionCommandEventValue, h as ActionCommandEventType, d as ClarityData, G as GestureData } from "./ScreenControlUtil-CeBJPwr0.js";
14
+ var DocumentEvent = /* @__PURE__ */ ((DocumentEvent2) => {
15
+ DocumentEvent2["KEY_DOWN"] = "keydown";
16
+ DocumentEvent2["POINTER_ENTER"] = "pointerenter";
17
+ DocumentEvent2["POINTER_LEAVE"] = "pointerleave";
18
+ DocumentEvent2["POINTER_DOWN"] = "pointerdown";
19
+ DocumentEvent2["POINTER_UP"] = "pointerup";
20
+ DocumentEvent2["POINTER_MOVE"] = "pointermove";
21
+ DocumentEvent2["WHEEL"] = "wheel";
22
+ DocumentEvent2["COMPOSITION_START"] = "compositionstart";
23
+ DocumentEvent2["COMPOSITION_END"] = "compositionend";
24
+ DocumentEvent2["INPUT"] = "input";
25
+ return DocumentEvent2;
26
+ })(DocumentEvent || {});
27
+ var MenuKey = /* @__PURE__ */ ((MenuKey2) => {
28
+ MenuKey2[MenuKey2["HOME"] = 3] = "HOME";
29
+ MenuKey2[MenuKey2["BACK"] = 4] = "BACK";
30
+ MenuKey2[MenuKey2["TASK"] = 187] = "TASK";
31
+ return MenuKey2;
32
+ })(MenuKey || {});
33
+ var ClarityLevel = /* @__PURE__ */ ((ClarityLevel2) => {
34
+ ClarityLevel2[ClarityLevel2["FLUENT"] = 1] = "FLUENT";
35
+ ClarityLevel2[ClarityLevel2["STANDARD"] = 2] = "STANDARD";
36
+ ClarityLevel2[ClarityLevel2["HIGH_DEFINITION"] = 3] = "HIGH_DEFINITION";
37
+ return ClarityLevel2;
38
+ })(ClarityLevel || {});
39
+ const CLARITY_LEVEL_LIST = [
40
+ {
41
+ label: "流畅",
42
+ value: 1
43
+ /* FLUENT */
44
+ },
45
+ {
46
+ label: "标清",
47
+ value: 2
48
+ /* STANDARD */
49
+ },
50
+ {
51
+ label: "高清",
52
+ value: 3
53
+ /* HIGH_DEFINITION */
54
+ }
55
+ ];
56
+ var GestureMode = /* @__PURE__ */ ((GestureMode2) => {
57
+ GestureMode2[GestureMode2["THREE_BUTTON_NAVIGATION"] = 0] = "THREE_BUTTON_NAVIGATION";
58
+ GestureMode2[GestureMode2["GESTURE_NAVIGATION"] = 2] = "GESTURE_NAVIGATION";
59
+ return GestureMode2;
60
+ })(GestureMode || {});
61
+ const CLASS_NAME = {
62
+ CONTAINER_CLASS_NAME: "hb-player-container",
63
+ KEYBOARD_CONTAINER_CLASS_NAME: "hb-keyboard-container",
64
+ REMOTE_VIDEO_CLASS_NAME: "hb-remote-video",
65
+ INPUT_METHOD_EDITOR_CLASS_NAME: "hb-ime-input"
66
+ };
67
+ var CursorType = /* @__PURE__ */ ((CursorType2) => {
68
+ CursorType2[CursorType2["DEFAULT_CURSOR"] = 0] = "DEFAULT_CURSOR";
69
+ CursorType2[CursorType2["CIRCLE_CURSOR"] = 1] = "CIRCLE_CURSOR";
70
+ CursorType2[CursorType2["TRIANGLE_CURSOR"] = 2] = "TRIANGLE_CURSOR";
71
+ return CursorType2;
72
+ })(CursorType || {});
73
+ const cursorClassMap = {
74
+ [
75
+ 0
76
+ /* DEFAULT_CURSOR */
77
+ ]: "default-cursor",
78
+ [
79
+ 1
80
+ /* CIRCLE_CURSOR */
81
+ ]: "circle-cursor",
82
+ [
83
+ 2
84
+ /* TRIANGLE_CURSOR */
85
+ ]: "triangle-cursor"
86
+ };
87
+ class Logger {
88
+ constructor({
89
+ prefix,
90
+ enabledDebug = false
91
+ }) {
92
+ __publicField(this, "prefix");
93
+ __publicField(this, "enabledDebug");
94
+ this.prefix = prefix;
95
+ this.enabledDebug = enabledDebug;
96
+ }
97
+ output(type, ...args) {
98
+ const logFn = console[type];
99
+ if (typeof logFn !== "function") return;
100
+ if (this.enabledDebug) {
101
+ logFn([this.prefix], ...args);
102
+ }
103
+ }
104
+ log(...args) {
105
+ this.output("log", ...args);
106
+ }
107
+ warn(...args) {
108
+ this.output("warn", ...args);
109
+ }
110
+ error(...args) {
111
+ this.output("error", ...args);
112
+ }
113
+ }
114
+ class RemoteVideoController {
115
+ constructor({
116
+ rootContainer,
117
+ loadedSuccess,
118
+ loadedFailure,
119
+ enabledDebug = false,
120
+ cursorType = CursorType.DEFAULT_CURSOR,
121
+ remoteViewBackgroundColor = "transparent"
122
+ }) {
123
+ __publicField(this, "rootContainer");
124
+ __publicField(this, "remoteElement", null);
125
+ __publicField(this, "cursorType");
126
+ __publicField(this, "remoteViewBackgroundColor", "transparent");
127
+ __publicField(this, "logger");
128
+ // 解码成功
129
+ __publicField(this, "loadedSuccess");
130
+ // 解码失败
131
+ __publicField(this, "loadedFailure");
132
+ // 屏幕状态
133
+ __privateAdd(this, _screenStatus, false);
134
+ __publicField(this, "documentClickListener", () => {
135
+ if (this.remoteElement) {
136
+ this.remoteElement.muted = false;
137
+ this.remoteElement.play().catch(this.logger.error);
138
+ }
139
+ });
140
+ __publicField(this, "handleMetaDataListener", () => {
141
+ var _a;
142
+ __privateSet(this, _screenStatus, true);
143
+ (_a = this.loadedSuccess) == null ? void 0 : _a.call(this);
144
+ });
145
+ this.logger = new Logger({
146
+ prefix: "RemoteVideoController",
147
+ enabledDebug
148
+ });
149
+ this.rootContainer = rootContainer;
150
+ this.cursorType = cursorType;
151
+ this.remoteViewBackgroundColor = remoteViewBackgroundColor;
152
+ this.loadedSuccess = loadedSuccess;
153
+ this.loadedFailure = loadedFailure;
154
+ this.init();
155
+ }
156
+ validateParams() {
157
+ const rootContainer = this.rootContainer;
158
+ if (!(rootContainer instanceof HTMLElement)) {
159
+ throw new Error("提供挂载节点元素");
160
+ }
161
+ }
162
+ createVideoElement() {
163
+ const videoElement = document.createElement("video");
164
+ videoElement.classList.add(CLASS_NAME.REMOTE_VIDEO_CLASS_NAME);
165
+ videoElement.classList.add(cursorClassMap[this.cursorType]);
166
+ videoElement.style = `background-color: ${this.remoteViewBackgroundColor}`;
167
+ return videoElement;
168
+ }
169
+ mountNode() {
170
+ const video = this.createVideoElement();
171
+ video.muted = true;
172
+ this.remoteElement = video;
173
+ this.rootContainer.appendChild(video);
174
+ }
175
+ async init() {
176
+ this.logger.log("实例初始化");
177
+ this.validateParams();
178
+ this.mountNode();
179
+ this.addEvent();
180
+ }
181
+ addDocumentClick() {
182
+ document.addEventListener("click", this.documentClickListener);
183
+ }
184
+ offDocumentClick() {
185
+ document.removeEventListener("click", this.documentClickListener);
186
+ }
187
+ addEvent() {
188
+ var _a;
189
+ this.addDocumentClick();
190
+ (_a = this.remoteElement) == null ? void 0 : _a.addEventListener("loadedmetadata", this.handleMetaDataListener);
191
+ }
192
+ offEvent() {
193
+ var _a;
194
+ this.offDocumentClick();
195
+ (_a = this.remoteElement) == null ? void 0 : _a.removeEventListener("loadedmetadata", this.handleMetaDataListener);
196
+ }
197
+ startPlay(track) {
198
+ const video = this.remoteElement;
199
+ if (!video) return;
200
+ video.play();
201
+ this.replaceVideoTrack(video, track);
202
+ }
203
+ replaceVideoTrack(video, newTrack) {
204
+ const videoEl = video;
205
+ if (!videoEl.srcObject) {
206
+ videoEl.srcObject = new MediaStream();
207
+ }
208
+ const mediaStream = videoEl.srcObject;
209
+ this.updateTrack(mediaStream, newTrack);
210
+ videoEl.playbackRate = 1;
211
+ videoEl.playsInline = true;
212
+ videoEl.disablePictureInPicture = true;
213
+ videoEl.setAttribute("playsinline", "true");
214
+ videoEl.setAttribute("webkit-playsinline", "true");
215
+ videoEl.setAttribute("x5-video-player-type", "h5");
216
+ videoEl.setAttribute("x5-video-player-fullscreen", "false");
217
+ videoEl.setAttribute("x5-video-orientation", "portraint");
218
+ videoEl.preload = "auto";
219
+ }
220
+ updateTrack(stream, newTrack) {
221
+ if (newTrack.kind === "video") {
222
+ stream.getVideoTracks().forEach((oldTrack) => {
223
+ stream.removeTrack(oldTrack);
224
+ oldTrack.stop();
225
+ });
226
+ stream.addTrack(newTrack);
227
+ } else if (newTrack.kind === "audio") {
228
+ if (!stream.getAudioTracks().some((t) => t.id === newTrack.id)) {
229
+ stream.addTrack(newTrack);
230
+ }
231
+ }
232
+ }
233
+ stopPlay() {
234
+ __privateSet(this, _screenStatus, false);
235
+ const video = this.remoteElement;
236
+ if (video && video.srcObject) {
237
+ const stream = video.srcObject;
238
+ stream.getTracks().forEach((t) => t.stop());
239
+ video.pause();
240
+ video.srcObject = null;
241
+ }
242
+ }
243
+ destroy() {
244
+ this.logger.log("实例销毁");
245
+ this.stopPlay();
246
+ this.offEvent();
247
+ }
248
+ }
249
+ _screenStatus = new WeakMap();
250
+ class RemoteCanvasController {
251
+ constructor({ remoteElement }) {
252
+ __publicField(this, "remoteElement");
253
+ __publicField(this, "audioElement");
254
+ this.remoteElement = remoteElement;
255
+ }
256
+ startDecode(arrayBuffer) {
257
+ }
258
+ startPlay(track) {
259
+ }
260
+ stopPlay() {
261
+ }
262
+ destroy() {
263
+ }
264
+ }
265
+ class RemoteController {
266
+ constructor({
267
+ rootContainer,
268
+ loadedSuccess,
269
+ loadedFailure,
270
+ enabledDebug = false,
271
+ enabledDecode = false,
272
+ cursorType = CursorType.DEFAULT_CURSOR,
273
+ remoteViewBackgroundColor = "transparent"
274
+ }) {
275
+ __publicField(this, "remoteController");
276
+ const options = {
277
+ rootContainer,
278
+ enabledDebug,
279
+ loadedFailure,
280
+ loadedSuccess,
281
+ cursorType,
282
+ remoteViewBackgroundColor
283
+ };
284
+ const RemoteControllerFn = enabledDecode ? RemoteCanvasController : RemoteVideoController;
285
+ this.remoteController = new RemoteControllerFn({
286
+ ...options
287
+ });
288
+ }
289
+ get audioElement() {
290
+ return this.remoteController.audioElement;
291
+ }
292
+ get remoteElement() {
293
+ return this.remoteController.remoteElement;
294
+ }
295
+ startPlay(track) {
296
+ this.remoteController.startPlay(track);
297
+ }
298
+ startDecode(arrayBuffer) {
299
+ var _a, _b;
300
+ (_b = (_a = this.remoteController).startDecode) == null ? void 0 : _b.call(_a, arrayBuffer);
301
+ }
302
+ stopPlay() {
303
+ this.remoteController.stopPlay();
304
+ }
305
+ destroy() {
306
+ this.remoteController.destroy();
307
+ }
308
+ }
309
+ function getEventXY(event, rect) {
310
+ if ("clientX" in event && "clientY" in event) {
311
+ return [event.clientX - rect.left, event.clientY - rect.top];
312
+ } else {
313
+ return [0, 0];
314
+ }
315
+ }
316
+ class MouseTouchControl {
317
+ constructor({ remoteElement, isGroup, widthRatio, videoAngle, streamAngle, cloudDeviceSize, touchDataUpdateCallback, wheelDataUpdateCallback, enabledDebug = false, isMove = false }) {
318
+ __publicField(this, "logger");
319
+ __publicField(this, "remoteElement", null);
320
+ __publicField(this, "cloudDeviceSize", { width: 0, height: 0 });
321
+ __publicField(this, "streamAngle", 0);
322
+ __publicField(this, "videoAngle", 0);
323
+ __publicField(this, "widthRatio", 0);
324
+ __publicField(this, "isGroup", false);
325
+ __publicField(this, "pointers");
326
+ __publicField(this, "groupIndexCounter", 0);
327
+ __publicField(this, "isMove", false);
328
+ __publicField(this, "touchDataUpdateCallback");
329
+ __publicField(this, "wheelDataUpdateCallback");
330
+ __publicField(this, "handleWheel", (e) => {
331
+ var _a;
332
+ const delta = Math.sign(e.deltaY) * -1;
333
+ const wheelData = new WheelData(delta);
334
+ (_a = this.wheelDataUpdateCallback) == null ? void 0 : _a.call(this, wheelData);
335
+ });
336
+ __publicField(this, "handlePointerEvent", (event, action, pointerId) => {
337
+ var _a;
338
+ if (!this.remoteElement) return;
339
+ const rect = this.remoteElement.getBoundingClientRect();
340
+ let [x, y] = getEventXY(event, rect);
341
+ const cloudWidth = this.cloudDeviceSize.width;
342
+ const cloudHeight = this.cloudDeviceSize.height;
343
+ const result = transformCoordinate(
344
+ rect.width,
345
+ rect.height,
346
+ cloudWidth,
347
+ cloudHeight,
348
+ this.videoAngle,
349
+ this.streamAngle,
350
+ x,
351
+ y
352
+ );
353
+ if (!result) return;
354
+ x = result[0];
355
+ y = result[1];
356
+ let pointerState = this.pointers.get(pointerId);
357
+ if (action === ActionType.ACTION_DOWN) {
358
+ pointerState = {
359
+ x,
360
+ y,
361
+ downTime: event.timeStamp,
362
+ isDown: true,
363
+ bound: Math.trunc(6 / this.widthRatio),
364
+ index: 0,
365
+ groupIndex: this.groupIndexCounter++
366
+ };
367
+ this.pointers.set(pointerId, pointerState);
368
+ } else {
369
+ if (!pointerState) return;
370
+ if (action === ActionType.ACTION_MOVE) {
371
+ let dx = x - pointerState.x;
372
+ let dy = y - pointerState.y;
373
+ if (this.isMove) {
374
+ dy = 0;
375
+ y = pointerState.y;
376
+ }
377
+ if (Math.abs(dx) < pointerState.bound && Math.abs(dy) < pointerState.bound) {
378
+ return;
379
+ }
380
+ pointerState.x = x;
381
+ pointerState.y = y;
382
+ pointerState.index++;
383
+ }
384
+ }
385
+ const [px, py] = valueToPercentage(
386
+ rect.width,
387
+ rect.height,
388
+ cloudWidth,
389
+ cloudHeight,
390
+ this.videoAngle,
391
+ this.streamAngle,
392
+ x,
393
+ y
394
+ );
395
+ const offsetTime = Math.trunc(event.timeStamp - pointerState.downTime);
396
+ const touchData = this.isGroup ? new TouchData(
397
+ action,
398
+ pointerId,
399
+ px,
400
+ py,
401
+ offsetTime,
402
+ "web",
403
+ pointerState.index,
404
+ pointerState.groupIndex
405
+ ) : new TouchData(
406
+ action,
407
+ pointerId,
408
+ px,
409
+ py,
410
+ offsetTime,
411
+ "web"
412
+ );
413
+ this.logger.log(touchData);
414
+ (_a = this.touchDataUpdateCallback) == null ? void 0 : _a.call(this, touchData);
415
+ if (action === ActionType.ACTION_UP) {
416
+ this.pointers.delete(pointerId);
417
+ }
418
+ });
419
+ __publicField(this, "handleMouseDown", (event) => {
420
+ event.preventDefault();
421
+ event.stopPropagation();
422
+ if (this.remoteElement) this.remoteElement.setPointerCapture(event.pointerId);
423
+ this.handlePointerEvent(event, ActionType.ACTION_DOWN, event.pointerId);
424
+ });
425
+ __publicField(this, "handleMouseMove", (event) => {
426
+ event.preventDefault();
427
+ event.stopPropagation();
428
+ this.handlePointerEvent(event, ActionType.ACTION_MOVE, event.pointerId);
429
+ if (!this.remoteElement) return;
430
+ const rect = this.remoteElement.getBoundingClientRect();
431
+ const { clientX: x, clientY: y } = event;
432
+ if (x < rect.left || x > rect.right || y < rect.top || y > rect.bottom) {
433
+ this.handleMouseUp(event);
434
+ }
435
+ });
436
+ __publicField(this, "handleMouseUp", (event) => {
437
+ event.preventDefault();
438
+ event.stopPropagation();
439
+ this.handlePointerEvent(event, ActionType.ACTION_UP, event.pointerId);
440
+ if (this.remoteElement) {
441
+ this.remoteElement.releasePointerCapture(event.pointerId);
442
+ }
443
+ });
444
+ __publicField(this, "handleMouseEnter", (event) => {
445
+ event.preventDefault();
446
+ event.stopPropagation();
447
+ if (event.buttons === 1 && !this.pointers.has(event.pointerId)) {
448
+ if (this.remoteElement) {
449
+ this.remoteElement.setPointerCapture(event.pointerId);
450
+ }
451
+ this.handlePointerEvent(event, ActionType.ACTION_DOWN, event.pointerId);
452
+ }
453
+ });
454
+ __publicField(this, "handleMouseLeave", (event) => {
455
+ event.preventDefault();
456
+ event.stopPropagation();
457
+ if (this.pointers.has(event.pointerId)) {
458
+ this.handlePointerEvent(event, ActionType.ACTION_UP, event.pointerId);
459
+ if (this.remoteElement) {
460
+ this.remoteElement.releasePointerCapture(event.pointerId);
461
+ }
462
+ }
463
+ });
464
+ this.logger = new Logger({
465
+ prefix: "MouseTouchControl",
466
+ enabledDebug
467
+ });
468
+ this.remoteElement = remoteElement;
469
+ this.cloudDeviceSize = cloudDeviceSize;
470
+ this.widthRatio = widthRatio;
471
+ this.videoAngle = videoAngle;
472
+ this.streamAngle = streamAngle;
473
+ this.isGroup = isGroup;
474
+ this.isMove = isMove;
475
+ this.pointers = /* @__PURE__ */ new Map();
476
+ this.touchDataUpdateCallback = touchDataUpdateCallback;
477
+ this.wheelDataUpdateCallback = wheelDataUpdateCallback;
478
+ this.init();
479
+ }
480
+ setVideoAngle(angle) {
481
+ this.videoAngle = angle;
482
+ }
483
+ setStreamAngle(angle) {
484
+ this.streamAngle = angle;
485
+ }
486
+ setWidthRatio(value) {
487
+ this.widthRatio = value;
488
+ }
489
+ setCloudDeviceSize(value) {
490
+ this.cloudDeviceSize = value;
491
+ }
492
+ validateParams() {
493
+ const video = this.remoteElement;
494
+ if (!(video instanceof HTMLVideoElement || video instanceof HTMLCanvasElement)) {
495
+ throw new Error("提供渲染挂载元素需为 canvas 或 video 元素");
496
+ }
497
+ }
498
+ addEvent() {
499
+ const remoteVideoElement = this.remoteElement;
500
+ if (remoteVideoElement) {
501
+ remoteVideoElement.addEventListener(DocumentEvent.POINTER_ENTER, this.handleMouseEnter);
502
+ remoteVideoElement.addEventListener(DocumentEvent.POINTER_MOVE, this.handleMouseMove);
503
+ remoteVideoElement.addEventListener(DocumentEvent.POINTER_LEAVE, this.handleMouseLeave);
504
+ remoteVideoElement.addEventListener(DocumentEvent.POINTER_DOWN, this.handleMouseDown);
505
+ remoteVideoElement.addEventListener(DocumentEvent.POINTER_UP, this.handleMouseUp);
506
+ remoteVideoElement.addEventListener(DocumentEvent.WHEEL, this.handleWheel);
507
+ }
508
+ }
509
+ offEvent() {
510
+ const remoteVideoElement = this.remoteElement;
511
+ if (remoteVideoElement) {
512
+ remoteVideoElement.removeEventListener(DocumentEvent.POINTER_ENTER, this.handleMouseEnter);
513
+ remoteVideoElement.removeEventListener(DocumentEvent.POINTER_MOVE, this.handleMouseMove);
514
+ remoteVideoElement.removeEventListener(DocumentEvent.POINTER_LEAVE, this.handleMouseLeave);
515
+ remoteVideoElement.removeEventListener(DocumentEvent.POINTER_DOWN, this.handleMouseDown);
516
+ remoteVideoElement.removeEventListener(DocumentEvent.POINTER_UP, this.handleMouseUp);
517
+ remoteVideoElement.removeEventListener(DocumentEvent.WHEEL, this.handleWheel);
518
+ }
519
+ }
520
+ init() {
521
+ this.validateParams();
522
+ this.addEvent();
523
+ }
524
+ destroy() {
525
+ this.logger.log("destroy");
526
+ this.offEvent();
527
+ }
528
+ }
529
+ class KeyboardControl {
530
+ constructor({
531
+ rootContainer,
532
+ inputDataUpdateCallback,
533
+ chineseDataUpdateCallback,
534
+ enabledDebug = false,
535
+ disabled = false,
536
+ enabledIMEKeyboard = false,
537
+ videoAngle
538
+ }) {
539
+ __publicField(this, "logger");
540
+ __publicField(this, "rootContainer");
541
+ __publicField(this, "keyboardContainerElement", null);
542
+ __publicField(this, "inputMethodEditorElement", null);
543
+ __publicField(this, "inputDataUpdateCallback");
544
+ __publicField(this, "chineseDataUpdateCallback");
545
+ __publicField(this, "videoAngle");
546
+ __publicField(this, "disabled", false);
547
+ __publicField(this, "enabledIMEKeyboard", false);
548
+ __privateAdd(this, _isComposing, false);
549
+ __publicField(this, "clearInput", () => {
550
+ if (this.inputMethodEditorElement) {
551
+ this.inputMethodEditorElement.value = "";
552
+ }
553
+ });
554
+ __publicField(this, "focusIME", () => {
555
+ requestAnimationFrame(() => {
556
+ var _a;
557
+ (_a = this.inputMethodEditorElement) == null ? void 0 : _a.focus();
558
+ });
559
+ });
560
+ __publicField(this, "blurIME", () => {
561
+ var _a;
562
+ (_a = this.inputMethodEditorElement) == null ? void 0 : _a.blur();
563
+ });
564
+ __publicField(this, "handleKeyDown", (e) => {
565
+ const data = getKeyEventData(e);
566
+ this.inputDataUpdateCallback(data);
567
+ });
568
+ __publicField(this, "handleKeyboardContainerPointerenter", () => {
569
+ if (!this.disabled) {
570
+ return;
571
+ }
572
+ if (this.inputMethodEditorElement) {
573
+ this.focusIME();
574
+ } else {
575
+ document.addEventListener(DocumentEvent.KEY_DOWN, this.handleKeyDown);
576
+ }
577
+ });
578
+ __publicField(this, "handleKeyboardContainerPointerleave", () => {
579
+ if (!this.disabled) {
580
+ return;
581
+ }
582
+ if (this.inputMethodEditorElement) {
583
+ this.blurIME();
584
+ } else {
585
+ document.removeEventListener(DocumentEvent.KEY_DOWN, this.handleKeyDown);
586
+ }
587
+ });
588
+ __publicField(this, "handleIMECompositionStart", (_e) => {
589
+ __privateSet(this, _isComposing, true);
590
+ });
591
+ __publicField(this, "handleIMECompositionEnd", (e) => {
592
+ __privateSet(this, _isComposing, false);
593
+ const text = e.data;
594
+ if (text && text.length > 0) {
595
+ this.chineseDataUpdateCallback(new InputData(text));
596
+ }
597
+ this.clearInput();
598
+ });
599
+ __publicField(this, "handleIMEInput", (e) => {
600
+ const inputEvent = e;
601
+ if (__privateGet(this, _isComposing)) return;
602
+ const text = inputEvent.data;
603
+ if (text && text.length > 0) {
604
+ this.chineseDataUpdateCallback(new InputData(text));
605
+ }
606
+ this.clearInput();
607
+ });
608
+ __publicField(this, "handleIMEKeyDown", (event) => {
609
+ if (__privateGet(this, _isComposing)) return;
610
+ if (isFunctionKey(event)) {
611
+ const data = getKeyEventData(event);
612
+ if (data.keyCode === 50 && data.meta === 4096) return;
613
+ this.inputDataUpdateCallback(data);
614
+ }
615
+ });
616
+ this.logger = new Logger({
617
+ prefix: "KeyboardControl",
618
+ enabledDebug
619
+ });
620
+ this.disabled = disabled;
621
+ this.rootContainer = rootContainer;
622
+ this.inputDataUpdateCallback = inputDataUpdateCallback;
623
+ this.chineseDataUpdateCallback = chineseDataUpdateCallback;
624
+ this.videoAngle = videoAngle;
625
+ this.enabledIMEKeyboard = enabledIMEKeyboard;
626
+ this.init();
627
+ }
628
+ createKeyboardContainerElement() {
629
+ const keyboardContainerElement = document.createElement("div");
630
+ keyboardContainerElement.className = CLASS_NAME.KEYBOARD_CONTAINER_CLASS_NAME;
631
+ keyboardContainerElement.style.rotate = `${this.videoAngle}deg`;
632
+ return keyboardContainerElement;
633
+ }
634
+ createInputMethodEditor() {
635
+ const textareaElement = document.createElement("textarea");
636
+ textareaElement.classList.add(CLASS_NAME.INPUT_METHOD_EDITOR_CLASS_NAME);
637
+ textareaElement.autocomplete = "off";
638
+ textareaElement.autocapitalize = "off";
639
+ textareaElement.spellcheck = false;
640
+ return textareaElement;
641
+ }
642
+ mountNode() {
643
+ const keyboardContainerElement = this.createKeyboardContainerElement();
644
+ if (this.enabledIMEKeyboard) {
645
+ const inputMethodEditorElement = this.createInputMethodEditor();
646
+ keyboardContainerElement.appendChild(inputMethodEditorElement);
647
+ this.inputMethodEditorElement = inputMethodEditorElement;
648
+ }
649
+ this.rootContainer.appendChild(keyboardContainerElement);
650
+ this.keyboardContainerElement = keyboardContainerElement;
651
+ }
652
+ init() {
653
+ this.mountNode();
654
+ this.addEvent();
655
+ }
656
+ setKeyboardContainerSize(width, height) {
657
+ if (this.keyboardContainerElement) {
658
+ this.keyboardContainerElement.style.width = `${width}px`;
659
+ this.keyboardContainerElement.style.height = `${height}px`;
660
+ }
661
+ }
662
+ setKeyboardContainerElementStyle(style) {
663
+ if (this.keyboardContainerElement) {
664
+ this.keyboardContainerElement.style.rotate = `${style.rotate}deg`;
665
+ }
666
+ }
667
+ setVideoAngle(value) {
668
+ this.videoAngle = value;
669
+ this.setKeyboardContainerElementStyle({
670
+ rotate: value
671
+ });
672
+ }
673
+ openIMEKeyboard() {
674
+ var _a;
675
+ if (this.inputMethodEditorElement) {
676
+ return;
677
+ }
678
+ const inputMethodEditorElement = this.createInputMethodEditor();
679
+ if (inputMethodEditorElement) {
680
+ this.inputMethodEditorElement = inputMethodEditorElement;
681
+ (_a = this.keyboardContainerElement) == null ? void 0 : _a.appendChild(inputMethodEditorElement);
682
+ this.addInputMethodEditorEvent();
683
+ }
684
+ }
685
+ closeIMEKeyboard() {
686
+ var _a;
687
+ if (!this.inputMethodEditorElement) {
688
+ return;
689
+ }
690
+ this.offInputMethodEditorEvent();
691
+ (_a = this.keyboardContainerElement) == null ? void 0 : _a.removeChild(this.inputMethodEditorElement);
692
+ }
693
+ addKeyboardContainerEvent() {
694
+ var _a, _b;
695
+ (_a = this.keyboardContainerElement) == null ? void 0 : _a.addEventListener(DocumentEvent.POINTER_ENTER, this.handleKeyboardContainerPointerenter);
696
+ (_b = this.keyboardContainerElement) == null ? void 0 : _b.addEventListener(DocumentEvent.POINTER_LEAVE, this.handleKeyboardContainerPointerleave);
697
+ }
698
+ offKeyboardContainerEvent() {
699
+ var _a, _b;
700
+ (_a = this.keyboardContainerElement) == null ? void 0 : _a.removeEventListener(DocumentEvent.POINTER_ENTER, this.handleKeyboardContainerPointerenter);
701
+ (_b = this.keyboardContainerElement) == null ? void 0 : _b.removeEventListener(DocumentEvent.POINTER_LEAVE, this.handleKeyboardContainerPointerleave);
702
+ document.removeEventListener(DocumentEvent.KEY_DOWN, this.handleKeyDown);
703
+ }
704
+ addInputMethodEditorEvent() {
705
+ var _a, _b, _c, _d;
706
+ (_a = this.inputMethodEditorElement) == null ? void 0 : _a.addEventListener(DocumentEvent.COMPOSITION_START, this.handleIMECompositionStart);
707
+ (_b = this.inputMethodEditorElement) == null ? void 0 : _b.addEventListener(DocumentEvent.COMPOSITION_END, this.handleIMECompositionEnd);
708
+ (_c = this.inputMethodEditorElement) == null ? void 0 : _c.addEventListener(DocumentEvent.INPUT, this.handleIMEInput);
709
+ (_d = this.inputMethodEditorElement) == null ? void 0 : _d.addEventListener(DocumentEvent.KEY_DOWN, this.handleIMEKeyDown);
710
+ }
711
+ offInputMethodEditorEvent() {
712
+ var _a, _b, _c, _d;
713
+ (_a = this.inputMethodEditorElement) == null ? void 0 : _a.removeEventListener(DocumentEvent.COMPOSITION_START, this.handleIMECompositionStart);
714
+ (_b = this.inputMethodEditorElement) == null ? void 0 : _b.removeEventListener(DocumentEvent.COMPOSITION_END, this.handleIMECompositionEnd);
715
+ (_c = this.inputMethodEditorElement) == null ? void 0 : _c.removeEventListener(DocumentEvent.INPUT, this.handleIMEInput);
716
+ (_d = this.inputMethodEditorElement) == null ? void 0 : _d.removeEventListener(DocumentEvent.KEY_DOWN, this.handleIMEKeyDown);
717
+ }
718
+ addEvent() {
719
+ this.addKeyboardContainerEvent();
720
+ this.addInputMethodEditorEvent();
721
+ }
722
+ offEvent() {
723
+ this.offKeyboardContainerEvent();
724
+ this.offInputMethodEditorEvent();
725
+ }
726
+ destroy() {
727
+ var _a;
728
+ this.offEvent();
729
+ (_a = this.keyboardContainerElement) == null ? void 0 : _a.remove();
730
+ this.keyboardContainerElement = null;
731
+ this.inputMethodEditorElement = null;
732
+ }
733
+ }
734
+ _isComposing = new WeakMap();
735
+ const _WebRTCWrapper = class _WebRTCWrapper extends EventEmitter {
736
+ constructor({
737
+ connectConfig,
738
+ enabledDebug = false
739
+ }) {
740
+ super();
741
+ __publicField(this, "logger");
742
+ __publicField(this, "webRtcSDKInstance", null);
743
+ __privateAdd(this, _direction);
744
+ __privateAdd(this, _screenWidth);
745
+ __privateAdd(this, _screenHeight);
746
+ __privateAdd(this, _clarityLevel);
747
+ __privateAdd(this, _gestureMode);
748
+ this.logger = new Logger({
749
+ prefix: "WebRTCWrapper",
750
+ enabledDebug
751
+ });
752
+ const webRtcSDKInstance = new WebRTCSdk(connectConfig);
753
+ this.webRtcSDKInstance = webRtcSDKInstance;
754
+ this.addEvent();
755
+ }
756
+ addEvent() {
757
+ if (this.webRtcSDKInstance) {
758
+ const webRtcSDKInstance = this.webRtcSDKInstance;
759
+ webRtcSDKInstance.addListener(EmitType.streamTrack, (track) => {
760
+ this.emit(_WebRTCWrapper.EVENTS.RECEIVE_MEDIA_STREAM_TRACK, track);
761
+ });
762
+ webRtcSDKInstance.addListener(EmitType.iceConnectionState, (state) => {
763
+ this.logger.log("iceConnectionState", state);
764
+ if (state === _WebRTCWrapper.EVENTS.CONNECTED) {
765
+ this.emit(_WebRTCWrapper.EVENTS.CONNECTED);
766
+ }
767
+ });
768
+ webRtcSDKInstance.addListener(EmitType.webrtcError, (error) => {
769
+ this.logger.log("webrtcError", error);
770
+ if (error.code !== FailCode.CAMERA && error.code !== FailCode.DATACHANNEL_ERR && error.code !== FailCode.STREAM_STATE && error.code !== FailCode.AUTH_FAILED) {
771
+ this.emit(_WebRTCWrapper.EVENTS.STOP_CONNECT, error);
772
+ this.destroy();
773
+ }
774
+ this.emit(_WebRTCWrapper.EVENTS.ERROR, error);
775
+ });
776
+ if ("arrayBuffer" in EmitType) {
777
+ webRtcSDKInstance.addListener(EmitType.arrayBuffer, (buffer) => {
778
+ this.emit(_WebRTCWrapper.EVENTS.RECEIVE_ARRAY_BUFFER, buffer);
779
+ });
780
+ }
781
+ webRtcSDKInstance.addListener(EmitType.statisticInfo, (info) => {
782
+ this.emit(_WebRTCWrapper.EVENTS.STATISTIC_INFO, info);
783
+ });
784
+ webRtcSDKInstance.addListener(EmitType.cloudStatusChanged, (cloudStatus) => {
785
+ if (cloudStatus) {
786
+ this.logger.log("cloudStatusChanged", cloudStatus);
787
+ const { direction, screenWidth, screenHeight, clarityLevel, gestureMode } = cloudStatus;
788
+ if (__privateGet(this, _direction) === void 0 || __privateGet(this, _direction) !== direction) {
789
+ this.emit(_WebRTCWrapper.EVENTS.DIRECTION_CHANGE, direction === ContainerDirection.Vertical ? 0 : -90);
790
+ __privateSet(this, _direction, direction);
791
+ }
792
+ if (__privateGet(this, _screenWidth) === void 0 || __privateGet(this, _screenHeight) === void 0 || (__privateGet(this, _screenWidth) !== screenWidth || __privateGet(this, _screenHeight) !== screenHeight)) {
793
+ this.emit(_WebRTCWrapper.EVENTS.RESIZE, {
794
+ screenWidth,
795
+ screenHeight
796
+ });
797
+ __privateSet(this, _screenWidth, screenWidth);
798
+ __privateSet(this, _screenHeight, screenHeight);
799
+ }
800
+ if (__privateGet(this, _clarityLevel) === void 0 || __privateGet(this, _clarityLevel) !== clarityLevel) {
801
+ this.emit(_WebRTCWrapper.EVENTS.CLARITY_LEVEL_CHANGE, clarityLevel);
802
+ __privateSet(this, _clarityLevel, clarityLevel);
803
+ }
804
+ if (__privateGet(this, _gestureMode) === void 0 || __privateGet(this, _gestureMode) !== gestureMode) {
805
+ this.emit(_WebRTCWrapper.EVENTS.GESTURE_MODE_CHANGE, gestureMode);
806
+ __privateSet(this, _gestureMode, gestureMode);
807
+ }
808
+ }
809
+ });
810
+ }
811
+ }
812
+ offEvents() {
813
+ var _a;
814
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.removeAllListeners();
815
+ }
816
+ startConnection() {
817
+ var _a;
818
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.startConnection();
819
+ }
820
+ sendChannelData(type, data) {
821
+ var _a;
822
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.sendChannelData(type, data);
823
+ }
824
+ sendClickData(data) {
825
+ this.sendChannelData(ChannelDataType.ClickData, data);
826
+ }
827
+ sendActionWheel(data) {
828
+ this.sendChannelData(ChannelDataType.ActionWheel, data);
829
+ }
830
+ sendActionInput(data) {
831
+ this.sendChannelData(ChannelDataType.ActionInput, data);
832
+ }
833
+ sendActionChinese(data) {
834
+ this.sendChannelData(ChannelDataType.ActionChinese, data);
835
+ }
836
+ goBack() {
837
+ const keyEvent = new KeyEventData(MenuKey.BACK, 0);
838
+ this.sendActionInput(keyEvent);
839
+ }
840
+ goHome() {
841
+ const keyEvent = new KeyEventData(MenuKey.HOME, 0);
842
+ this.sendActionInput(keyEvent);
843
+ }
844
+ goTask() {
845
+ const keyEvent = new KeyEventData(MenuKey.TASK, 0);
846
+ this.sendActionInput(keyEvent);
847
+ }
848
+ enableAudio() {
849
+ this.sendChannelData(ChannelDataType.ActionCommandEvent, {
850
+ action: ActionCommandEventType.ACTION_CONTROL_AUDIO,
851
+ value: ActionCommandEventValue.ENABLE
852
+ });
853
+ }
854
+ disableAudio() {
855
+ this.sendChannelData(ChannelDataType.ActionCommandEvent, {
856
+ action: ActionCommandEventType.ACTION_CONTROL_AUDIO,
857
+ value: ActionCommandEventValue.DISABLE
858
+ });
859
+ }
860
+ /**
861
+ * @param level
862
+ * 高清: 3
863
+ * 标清: 2
864
+ * 流畅: 1
865
+ */
866
+ changeLevel(level) {
867
+ if (level < ClarityLevel.FLUENT || level > ClarityLevel.HIGH_DEFINITION) {
868
+ this.logger.error("清晰度等级错误,只能是1-3之间,分别是:流畅、标清 和 高清");
869
+ return;
870
+ }
871
+ this.sendChannelData(ChannelDataType.ActionClarity, new ClarityData(level));
872
+ }
873
+ /**
874
+ * @param value
875
+ * 发送剪贴板的内容
876
+ */
877
+ sendClipboardData(value) {
878
+ this.sendChannelData(ChannelDataType.ClipboardData, value);
879
+ }
880
+ setNavigationMode(mode) {
881
+ const data = new GestureData(mode);
882
+ this.sendChannelData(ChannelDataType.ActionGesture, data);
883
+ }
884
+ switchToGestureNavigation() {
885
+ this.setNavigationMode(GestureMode.GESTURE_NAVIGATION);
886
+ }
887
+ switchToThreeButtonNavigation() {
888
+ this.setNavigationMode(GestureMode.THREE_BUTTON_NAVIGATION);
889
+ }
890
+ destroy() {
891
+ var _a;
892
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.stop();
893
+ this.offEvents();
894
+ this.webRtcSDKInstance = null;
895
+ }
896
+ };
897
+ _direction = new WeakMap();
898
+ _screenWidth = new WeakMap();
899
+ _screenHeight = new WeakMap();
900
+ _clarityLevel = new WeakMap();
901
+ _gestureMode = new WeakMap();
902
+ __publicField(_WebRTCWrapper, "EVENTS", {
903
+ CONNECTED: "connected",
904
+ DIRECTION_CHANGE: "directionChange",
905
+ RESIZE: "resize",
906
+ CLARITY_LEVEL_CHANGE: "clarityLevel",
907
+ GESTURE_MODE_CHANGE: "gestureMode",
908
+ RECEIVE_MEDIA_STREAM_TRACK: "receiveMediaStreamTrack",
909
+ RECEIVE_ARRAY_BUFFER: "receiveArrayBuffer",
910
+ ERROR: "error",
911
+ STOP_CONNECT: "stopConnect",
912
+ STATISTIC_INFO: "statisticInfo",
913
+ CLICK_DATA: ChannelDataType.ClickData
914
+ });
915
+ let WebRTCWrapper = _WebRTCWrapper;
916
+ var SDKEvents = /* @__PURE__ */ ((SDKEvents2) => {
917
+ SDKEvents2["CHANNEL_EVENT"] = "channelEvent";
918
+ SDKEvents2["GROUP_CONTROL_EVENT"] = "groupControlEvent";
919
+ SDKEvents2["LOADED_SUCCESS"] = "loadedSuccess";
920
+ SDKEvents2["LOADED_FAILURE"] = "loadedFailure";
921
+ return SDKEvents2;
922
+ })(SDKEvents || {});
923
+ const _UniSDK = class _UniSDK extends EventEmitter {
924
+ constructor({
925
+ mountedElement,
926
+ connectConfig,
927
+ cloudDeviceSize = {
928
+ width: 720,
929
+ height: 1280
930
+ },
931
+ disabled = false,
932
+ enabledDebug = false,
933
+ isGroup = false,
934
+ disabledVerticalSwipe = false,
935
+ enabledIMEKeyboard = false,
936
+ remoteViewBackgroundColor = "transparent",
937
+ videoAngle = 0,
938
+ cursorType = 0,
939
+ enabledDecode = false
940
+ }) {
941
+ super();
942
+ __publicField(this, "logger");
943
+ __publicField(this, "mountedElement");
944
+ __publicField(this, "connectConfig");
945
+ __publicField(this, "cloudDeviceSize");
946
+ __publicField(this, "videoContainerElement", null);
947
+ __publicField(this, "containerResizeObserver", null);
948
+ __publicField(this, "remoteViewBackgroundColor", "transparent");
949
+ __publicField(this, "remoteController", null);
950
+ __publicField(this, "webRtcSDKInstance", null);
951
+ __publicField(this, "mouseTouchControl", null);
952
+ __publicField(this, "keyboardControl", null);
953
+ __publicField(this, "isGroup", false);
954
+ __publicField(this, "videoAngle", 0);
955
+ __publicField(this, "streamAngle", 0);
956
+ __publicField(this, "widthRatio", 0);
957
+ __publicField(this, "heightRatio", 0);
958
+ __publicField(this, "cursorType", 0);
959
+ __publicField(this, "disabled", false);
960
+ __publicField(this, "enabledDebug", false);
961
+ __publicField(this, "disabledVerticalSwipe", false);
962
+ __publicField(this, "enabledIMEKeyboard", false);
963
+ __publicField(this, "enabledDecode", false);
964
+ this.logger = new Logger({
965
+ prefix: "SDK",
966
+ enabledDebug
967
+ });
968
+ this.mountedElement = mountedElement;
969
+ this.connectConfig = connectConfig;
970
+ this.disabled = disabled;
971
+ this.remoteViewBackgroundColor = remoteViewBackgroundColor;
972
+ this.videoAngle = videoAngle;
973
+ this.cursorType = cursorType;
974
+ this.cloudDeviceSize = cloudDeviceSize;
975
+ this.isGroup = isGroup;
976
+ this.disabledVerticalSwipe = disabledVerticalSwipe;
977
+ this.enabledIMEKeyboard = enabledIMEKeyboard;
978
+ this.enabledDebug = enabledDebug;
979
+ this.enabledDecode = enabledDecode;
980
+ }
981
+ setVideoAngle(angle) {
982
+ var _a;
983
+ this.videoAngle = angle;
984
+ (_a = this.keyboardControl) == null ? void 0 : _a.setVideoAngle(angle);
985
+ }
986
+ getVideoAngle() {
987
+ return this.videoAngle;
988
+ }
989
+ setStreamAngle(angle) {
990
+ var _a;
991
+ this.streamAngle = angle;
992
+ (_a = this.mouseTouchControl) == null ? void 0 : _a.setStreamAngle(angle);
993
+ }
994
+ setCloudDeviceSize(value) {
995
+ var _a;
996
+ this.cloudDeviceSize = value;
997
+ (_a = this.mouseTouchControl) == null ? void 0 : _a.setCloudDeviceSize(value);
998
+ }
999
+ validateParams() {
1000
+ this.logger.log("validateParams");
1001
+ if (this.mountedElement instanceof HTMLElement) {
1002
+ return true;
1003
+ }
1004
+ if (this.mountedElement && typeof this.mountedElement === "string") {
1005
+ const element = document.querySelector(this.mountedElement);
1006
+ if (!element) {
1007
+ throw new Error(`挂载的 "${this.mountedElement}" 节点不存在`);
1008
+ }
1009
+ this.mountedElement = element;
1010
+ } else {
1011
+ throw new Error("挂载节点找不到");
1012
+ }
1013
+ }
1014
+ init() {
1015
+ this.validateParams();
1016
+ this.createNode();
1017
+ this.mounted();
1018
+ this.addEvent();
1019
+ }
1020
+ createVideoContainerElement() {
1021
+ const videoContainerElement = document.createElement("div");
1022
+ videoContainerElement.className = CLASS_NAME.CONTAINER_CLASS_NAME;
1023
+ return videoContainerElement;
1024
+ }
1025
+ setKeyboardContainerSize(width, height) {
1026
+ var _a, _b;
1027
+ (_b = (_a = this.keyboardControl) == null ? void 0 : _a.setKeyboardContainerSize) == null ? void 0 : _b.call(_a, width, height);
1028
+ }
1029
+ createNode() {
1030
+ this.logger.log("createNode");
1031
+ const videoContainerElement = this.createVideoContainerElement();
1032
+ this.videoContainerElement = videoContainerElement;
1033
+ }
1034
+ calculateSize(w, h) {
1035
+ var _a;
1036
+ const isRotated = this.videoAngle % 180 !== 0;
1037
+ const containerWidth = isRotated ? h : w;
1038
+ const containerHeight = isRotated ? w : h;
1039
+ const cloudDeviceSize = this.cloudDeviceSize;
1040
+ const vWidth = cloudDeviceSize.width;
1041
+ const vHeight = cloudDeviceSize.height;
1042
+ const aspect = vWidth / vHeight;
1043
+ const videoHeight = containerWidth / aspect;
1044
+ let width;
1045
+ let height;
1046
+ if (videoHeight > containerHeight) {
1047
+ height = containerHeight;
1048
+ width = height * aspect;
1049
+ } else {
1050
+ width = containerWidth;
1051
+ height = videoHeight;
1052
+ }
1053
+ this.widthRatio = vWidth / width;
1054
+ this.heightRatio = vHeight / height;
1055
+ (_a = this.mouseTouchControl) == null ? void 0 : _a.setWidthRatio(this.widthRatio);
1056
+ this.setKeyboardContainerSize(width, height);
1057
+ }
1058
+ addContainerResizeListener() {
1059
+ if (!this.videoContainerElement) {
1060
+ return;
1061
+ }
1062
+ const resizeObserver = new ResizeObserver(([entry]) => {
1063
+ const { width, height } = entry.contentRect;
1064
+ this.calculateSize(width, height);
1065
+ });
1066
+ resizeObserver.observe(this.videoContainerElement);
1067
+ this.containerResizeObserver = resizeObserver;
1068
+ }
1069
+ offContainerResizeListener() {
1070
+ if (this.containerResizeObserver && this.videoContainerElement) {
1071
+ this.containerResizeObserver.unobserve(this.videoContainerElement);
1072
+ }
1073
+ }
1074
+ addEvent() {
1075
+ this.addContainerResizeListener();
1076
+ }
1077
+ offEvents() {
1078
+ this.logger.log("offEvents");
1079
+ this.offContainerResizeListener();
1080
+ this.removeAllListeners();
1081
+ }
1082
+ createRemoteController() {
1083
+ const remoteController = new RemoteController({
1084
+ rootContainer: this.videoContainerElement,
1085
+ enabledDecode: this.enabledDecode,
1086
+ loadedSuccess: () => {
1087
+ this.logger.log("loadedSuccess");
1088
+ this.emit(_UniSDK.EVENTS.LOADED_SUCCESS);
1089
+ },
1090
+ loadedFailure: (reason) => {
1091
+ this.logger.log("loadedFailure");
1092
+ this.emit(_UniSDK.EVENTS.LOADED_FAILURE, reason);
1093
+ },
1094
+ enabledDebug: this.enabledDebug
1095
+ });
1096
+ this.remoteController = remoteController;
1097
+ return remoteController;
1098
+ }
1099
+ createMouseTouchControl(remoteElement) {
1100
+ const mouseTouchControl = new MouseTouchControl({
1101
+ remoteElement,
1102
+ isGroup: this.isGroup,
1103
+ isMove: this.disabledVerticalSwipe,
1104
+ videoAngle: this.videoAngle,
1105
+ widthRatio: this.widthRatio,
1106
+ streamAngle: this.streamAngle,
1107
+ cloudDeviceSize: this.cloudDeviceSize,
1108
+ touchDataUpdateCallback: (data) => {
1109
+ var _a;
1110
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.sendClickData(data);
1111
+ },
1112
+ wheelDataUpdateCallback: (data) => {
1113
+ var _a;
1114
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.sendActionWheel(data);
1115
+ },
1116
+ enabledDebug: this.enabledDebug
1117
+ });
1118
+ this.mouseTouchControl = mouseTouchControl;
1119
+ return mouseTouchControl;
1120
+ }
1121
+ createKeyboardControl() {
1122
+ const keyboardControl = new KeyboardControl({
1123
+ rootContainer: this.videoContainerElement,
1124
+ videoAngle: this.videoAngle,
1125
+ disabled: this.disabled,
1126
+ enabledIMEKeyboard: this.enabledIMEKeyboard,
1127
+ inputDataUpdateCallback: (data) => {
1128
+ var _a;
1129
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.sendActionInput(data);
1130
+ },
1131
+ chineseDataUpdateCallback: (data) => {
1132
+ var _a;
1133
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.sendActionChinese(data);
1134
+ },
1135
+ enabledDebug: this.enabledDebug
1136
+ });
1137
+ this.keyboardControl = keyboardControl;
1138
+ return keyboardControl;
1139
+ }
1140
+ async mounted() {
1141
+ this.logger.log("mounted");
1142
+ if (this.mountedElement instanceof HTMLElement) {
1143
+ this.mountedElement.appendChild(this.videoContainerElement);
1144
+ requestAnimationFrame(() => {
1145
+ var _a;
1146
+ const { width, height } = this.videoContainerElement.getBoundingClientRect();
1147
+ this.calculateSize(width, height);
1148
+ const remoteController = this.createRemoteController();
1149
+ const webRtcSDKInstance = new WebRTCWrapper({
1150
+ connectConfig: {
1151
+ ...this.connectConfig,
1152
+ isGroup: this.isGroup
1153
+ },
1154
+ enabledDebug: this.enabledDebug
1155
+ });
1156
+ webRtcSDKInstance.startConnection();
1157
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.RECEIVE_MEDIA_STREAM_TRACK, (track) => {
1158
+ remoteController.startPlay(track);
1159
+ });
1160
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.RECEIVE_ARRAY_BUFFER, (buffer) => {
1161
+ remoteController.startDecode(buffer);
1162
+ });
1163
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.DIRECTION_CHANGE, (value) => {
1164
+ this.setStreamAngle(value);
1165
+ });
1166
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.RESIZE, (screen) => {
1167
+ this.setCloudDeviceSize({
1168
+ width: screen.screenWidth,
1169
+ height: screen.screenHeight
1170
+ });
1171
+ });
1172
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.CONNECTED, () => {
1173
+ this.emit(_UniSDK.EVENTS.CONNECTED);
1174
+ });
1175
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.STOP_CONNECT, () => {
1176
+ var _a2;
1177
+ (_a2 = this.remoteController) == null ? void 0 : _a2.stopPlay();
1178
+ });
1179
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.STATISTIC_INFO, (info) => {
1180
+ this.emit(_UniSDK.EVENTS.STATISTIC_INFO, info);
1181
+ });
1182
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.CLARITY_LEVEL_CHANGE, (level) => {
1183
+ this.emit(_UniSDK.EVENTS.CLARITY_LEVEL_CHANGE, level);
1184
+ });
1185
+ this.webRtcSDKInstance = webRtcSDKInstance;
1186
+ const keyboardControl = this.createKeyboardControl();
1187
+ (_a = keyboardControl.keyboardContainerElement) == null ? void 0 : _a.append(remoteController.remoteElement);
1188
+ this.createMouseTouchControl(remoteController.remoteElement);
1189
+ });
1190
+ }
1191
+ }
1192
+ startConnection() {
1193
+ var _a;
1194
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.startConnection();
1195
+ }
1196
+ goBack() {
1197
+ var _a;
1198
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.goBack();
1199
+ }
1200
+ goHome() {
1201
+ var _a;
1202
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.goHome();
1203
+ }
1204
+ goTask() {
1205
+ var _a;
1206
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.goTask();
1207
+ }
1208
+ enableAudio() {
1209
+ var _a;
1210
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.enableAudio();
1211
+ }
1212
+ disableAudio() {
1213
+ var _a;
1214
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.disableAudio();
1215
+ }
1216
+ changeLevel(value) {
1217
+ var _a;
1218
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.changeLevel(value);
1219
+ }
1220
+ sendClipboardData(value) {
1221
+ var _a;
1222
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.sendClipboardData(value);
1223
+ }
1224
+ openIMEKeyboard() {
1225
+ var _a;
1226
+ (_a = this.keyboardControl) == null ? void 0 : _a.openIMEKeyboard();
1227
+ }
1228
+ closeIMEKeyboard() {
1229
+ var _a;
1230
+ (_a = this.keyboardControl) == null ? void 0 : _a.closeIMEKeyboard();
1231
+ }
1232
+ switchToGestureNavigation() {
1233
+ var _a;
1234
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.switchToGestureNavigation();
1235
+ }
1236
+ switchToThreeButtonNavigation() {
1237
+ var _a;
1238
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.switchToThreeButtonNavigation();
1239
+ }
1240
+ destroy() {
1241
+ var _a, _b, _c, _d;
1242
+ this.logger.log("destroy");
1243
+ (_a = this.remoteController) == null ? void 0 : _a.destroy();
1244
+ (_b = this.mouseTouchControl) == null ? void 0 : _b.destroy();
1245
+ (_c = this.webRtcSDKInstance) == null ? void 0 : _c.destroy();
1246
+ this.offEvents();
1247
+ (_d = this.videoContainerElement) == null ? void 0 : _d.remove();
1248
+ }
1249
+ };
1250
+ __publicField(_UniSDK, "EVENTS", {
1251
+ ...SDKEvents,
1252
+ ...WebRTCWrapper.EVENTS
1253
+ });
1254
+ __publicField(_UniSDK, "CURSOR_TYPE", CursorType);
1255
+ __publicField(_UniSDK, "CLARITY_LEVEL", ClarityLevel);
1256
+ __publicField(_UniSDK, "CLARITY_LEVEL_LIST", CLARITY_LEVEL_LIST);
1257
+ let UniSDK = _UniSDK;
1258
+ export {
1259
+ UniSDK
1260
+ };