yjz-web-sdk 1.0.10 → 1.0.11-beta.10

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.
Files changed (77) hide show
  1. package/README.md +90 -0
  2. package/lib/ScreenControlUtil-D4-BTCo9.js +5230 -0
  3. package/lib/components/RemotePlayer/index.vue.d.ts +1 -73
  4. package/lib/composables/useCursorStyle.d.ts +1 -1
  5. package/lib/composables/useKeyboardControl.d.ts +5 -1
  6. package/lib/composables/useMouseTouchControl.d.ts +5 -4
  7. package/lib/composables/useRemoteVideo.d.ts +8 -25
  8. package/lib/composables/useResizeObserver.d.ts +1 -1
  9. package/lib/core/WebRTCSdk.d.ts +3 -0
  10. package/lib/core/data/WebRtcError.d.ts +3 -3
  11. package/lib/core/data/WebrtcDataType.d.ts +1 -11
  12. package/lib/core/groupctrl/SdkController.d.ts +2 -2
  13. package/lib/core/rtc/WebRTCClient.d.ts +13 -3
  14. package/lib/core/rtc/WebRTCConfig.d.ts +3 -1
  15. package/lib/core/rtc/WebRtcNegotiate.d.ts +3 -3
  16. package/lib/core/signal/SignalingClient.d.ts +1 -1
  17. package/lib/core/util/KeyCodeUtil.d.ts +6 -0
  18. package/lib/core/util/TurnTestUtil.d.ts +4 -4
  19. package/lib/index.d.ts +3 -3
  20. package/lib/uni/KeyboardControl.d.ts +53 -0
  21. package/lib/uni/Logger.d.ts +13 -0
  22. package/lib/uni/MouseTouchControl.d.ts +56 -0
  23. package/lib/uni/RemoteCanvasController.d.ts +11 -0
  24. package/lib/uni/RemoteController.d.ts +23 -0
  25. package/lib/uni/RemoteVideoController.d.ts +38 -0
  26. package/lib/uni/WebRTCWrapper.d.ts +57 -0
  27. package/lib/uni/constants.d.ts +42 -0
  28. package/lib/uni/index.d.ts +110 -0
  29. package/lib/{components/RemotePlayer → uni}/type.d.ts +1 -0
  30. package/lib/uni-sdk.js +1263 -0
  31. package/lib/yjz-web-sdk.js +312 -5955
  32. package/package.json +10 -20
  33. package/lib/core/data/TurnType.d.ts +0 -21
  34. package/lib/core/util/MapCache.d.ts +0 -20
  35. package/lib/render/Canvas2DRenderer.d.ts +0 -10
  36. package/lib/render/WebGLRenderer.d.ts +0 -16
  37. package/lib/render/WebGPURenderer.d.ts +0 -18
  38. package/lib/types/index.d.ts +0 -13
  39. package/lib/util/WasmUtil.d.ts +0 -17
  40. package/lib/worker/worker.d.ts +0 -1
  41. package/src/assets/icon/circle.svg +0 -1
  42. package/src/assets/icon/triangle.svg +0 -1
  43. package/src/assets/wasm/h264-atomic.wasm +0 -0
  44. package/src/assets/wasm/h264-simd.wasm +0 -0
  45. package/src/components/RemotePlayer/index.vue +0 -170
  46. package/src/components/RemotePlayer/type.ts +0 -11
  47. package/src/composables/useCursorStyle.ts +0 -15
  48. package/src/composables/useKeyboardControl.ts +0 -32
  49. package/src/composables/useMouseTouchControl.ts +0 -158
  50. package/src/composables/useRemoteVideo.ts +0 -248
  51. package/src/composables/useResizeObserver.ts +0 -27
  52. package/src/core/WebRTCSdk.ts +0 -561
  53. package/src/core/data/MessageType.ts +0 -70
  54. package/src/core/data/TurnType.ts +0 -25
  55. package/src/core/data/WebRtcError.ts +0 -93
  56. package/src/core/data/WebrtcDataType.ts +0 -354
  57. package/src/core/groupctrl/GroupCtrlSocketManager.ts +0 -94
  58. package/src/core/groupctrl/SdkController.ts +0 -96
  59. package/src/core/rtc/WebRTCClient.ts +0 -862
  60. package/src/core/rtc/WebRTCConfig.ts +0 -86
  61. package/src/core/rtc/WebRtcNegotiate.ts +0 -164
  62. package/src/core/signal/SignalingClient.ts +0 -221
  63. package/src/core/util/FileTypeUtils.ts +0 -75
  64. package/src/core/util/KeyCodeUtil.ts +0 -162
  65. package/src/core/util/Logger.ts +0 -83
  66. package/src/core/util/MapCache.ts +0 -135
  67. package/src/core/util/ScreenControlUtil.ts +0 -174
  68. package/src/core/util/TurnTestUtil.ts +0 -123
  69. package/src/env.d.ts +0 -30
  70. package/src/index.ts +0 -61
  71. package/src/render/Canvas2DRenderer.ts +0 -38
  72. package/src/render/WebGLRenderer.ts +0 -150
  73. package/src/render/WebGPURenderer.ts +0 -194
  74. package/src/types/index.ts +0 -15
  75. package/src/types/webgpu.d.ts +0 -1158
  76. package/src/util/WasmUtil.ts +0 -291
  77. package/src/worker/worker.ts +0 -292
package/lib/uni-sdk.js ADDED
@@ -0,0 +1,1263 @@
1
+ !function(){"use strict";try{if("undefined"!=typeof document){var e=document.createElement("style");e.appendChild(document.createTextNode(".vContainer[data-v-a76aee48]{transition:transform .2s linear;transform-origin:center center;margin:0;overflow:hidden;background:transparent;transform:translateZ(0);will-change:transform}.flex[data-v-a76aee48]{display:flex}.flex-1[data-v-a76aee48]{flex:1 1 0}.items-center[data-v-a76aee48]{align-items:center}.justify-center[data-v-a76aee48]{justify-content:center}.video-control[data-v-a76aee48]{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-a76aee48]{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-a76aee48]{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-a76aee48]{cursor:default}.no-events[data-v-a76aee48]{pointer-events:none!important}.ime-input[data-v-a76aee48]{position:fixed;right:0;bottom:0;width:1px;height:1px;opacity:0;pointer-events:none}.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-D4-BTCo9.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: "RemoteController",
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("destroy");
245
+ this.stopPlay();
246
+ this.offEvent();
247
+ }
248
+ }
249
+ _screenStatus = new WeakMap();
250
+ class RemoteCanvasController {
251
+ constructor() {
252
+ __publicField(this, "remoteElement", null);
253
+ __publicField(this, "audioElement");
254
+ }
255
+ startDecode(arrayBuffer) {
256
+ }
257
+ startPlay(track) {
258
+ }
259
+ stopPlay() {
260
+ }
261
+ destroy() {
262
+ }
263
+ }
264
+ class RemoteController {
265
+ constructor({
266
+ rootContainer,
267
+ loadedSuccess,
268
+ loadedFailure,
269
+ enabledDebug = false,
270
+ enabledDecode = false,
271
+ cursorType = CursorType.DEFAULT_CURSOR,
272
+ remoteViewBackgroundColor = "transparent"
273
+ }) {
274
+ __publicField(this, "remoteController");
275
+ const options = {
276
+ rootContainer,
277
+ enabledDebug,
278
+ loadedFailure,
279
+ loadedSuccess,
280
+ cursorType,
281
+ remoteViewBackgroundColor
282
+ };
283
+ const RemoteControllerFn = enabledDecode ? RemoteCanvasController : RemoteVideoController;
284
+ this.remoteController = new RemoteControllerFn({
285
+ ...options
286
+ });
287
+ }
288
+ get audioElement() {
289
+ return this.remoteController.audioElement;
290
+ }
291
+ get remoteElement() {
292
+ return this.remoteController.remoteElement;
293
+ }
294
+ startPlay(track) {
295
+ this.remoteController.startPlay(track);
296
+ }
297
+ startDecode(arrayBuffer) {
298
+ var _a, _b;
299
+ (_b = (_a = this.remoteController).startDecode) == null ? void 0 : _b.call(_a, arrayBuffer);
300
+ }
301
+ stopPlay() {
302
+ this.remoteController.stopPlay();
303
+ }
304
+ destroy() {
305
+ this.remoteController.destroy();
306
+ }
307
+ }
308
+ function getEventXY(event, rect) {
309
+ if ("clientX" in event && "clientY" in event) {
310
+ return [event.clientX - rect.left, event.clientY - rect.top];
311
+ } else {
312
+ return [0, 0];
313
+ }
314
+ }
315
+ class MouseTouchControl {
316
+ constructor({ remoteElement, isGroup, widthRatio, videoAngle, streamAngle, cloudDeviceSize, touchDataUpdateCallback, wheelDataUpdateCallback, enabledDebug = false, isMove = false }) {
317
+ __publicField(this, "logger");
318
+ __publicField(this, "remoteElement", null);
319
+ __publicField(this, "cloudDeviceSize", { width: 0, height: 0 });
320
+ __publicField(this, "streamAngle", 0);
321
+ __publicField(this, "videoAngle", 0);
322
+ __publicField(this, "widthRatio", 0);
323
+ __publicField(this, "isGroup", false);
324
+ __publicField(this, "pointers");
325
+ __publicField(this, "groupIndexCounter", 0);
326
+ __publicField(this, "isMove", false);
327
+ __publicField(this, "touchDataUpdateCallback");
328
+ __publicField(this, "wheelDataUpdateCallback");
329
+ __publicField(this, "handleWheel", (e) => {
330
+ var _a;
331
+ const delta = Math.sign(e.deltaY) * -1;
332
+ const wheelData = new WheelData(delta);
333
+ (_a = this.wheelDataUpdateCallback) == null ? void 0 : _a.call(this, wheelData);
334
+ });
335
+ __publicField(this, "handlePointerEvent", (event, action, pointerId) => {
336
+ var _a;
337
+ if (!this.remoteElement) return;
338
+ const rect = this.remoteElement.getBoundingClientRect();
339
+ let [x, y] = getEventXY(event, rect);
340
+ const cloudWidth = this.cloudDeviceSize.width;
341
+ const cloudHeight = this.cloudDeviceSize.height;
342
+ const result = transformCoordinate(
343
+ rect.width,
344
+ rect.height,
345
+ cloudWidth,
346
+ cloudHeight,
347
+ this.videoAngle,
348
+ this.streamAngle,
349
+ x,
350
+ y
351
+ );
352
+ if (!result) return;
353
+ x = result[0];
354
+ y = result[1];
355
+ let pointerState = this.pointers.get(pointerId);
356
+ if (action === ActionType.ACTION_DOWN) {
357
+ pointerState = {
358
+ x,
359
+ y,
360
+ downTime: event.timeStamp,
361
+ isDown: true,
362
+ bound: Math.trunc(6 / this.widthRatio),
363
+ index: 0,
364
+ groupIndex: this.groupIndexCounter++
365
+ };
366
+ this.pointers.set(pointerId, pointerState);
367
+ } else {
368
+ if (!pointerState) return;
369
+ if (action === ActionType.ACTION_MOVE) {
370
+ let dx = x - pointerState.x;
371
+ let dy = y - pointerState.y;
372
+ if (this.isMove) {
373
+ dy = 0;
374
+ y = pointerState.y;
375
+ }
376
+ if (Math.abs(dx) < pointerState.bound && Math.abs(dy) < pointerState.bound) {
377
+ return;
378
+ }
379
+ pointerState.x = x;
380
+ pointerState.y = y;
381
+ pointerState.index++;
382
+ }
383
+ }
384
+ const [px, py] = valueToPercentage(
385
+ rect.width,
386
+ rect.height,
387
+ cloudWidth,
388
+ cloudHeight,
389
+ this.videoAngle,
390
+ this.streamAngle,
391
+ x,
392
+ y
393
+ );
394
+ const offsetTime = Math.trunc(event.timeStamp - pointerState.downTime);
395
+ const touchData = this.isGroup ? new TouchData(
396
+ action,
397
+ pointerId,
398
+ px,
399
+ py,
400
+ offsetTime,
401
+ "web",
402
+ pointerState.index,
403
+ pointerState.groupIndex
404
+ ) : new TouchData(
405
+ action,
406
+ pointerId,
407
+ px,
408
+ py,
409
+ offsetTime,
410
+ "web"
411
+ );
412
+ this.logger.log(touchData);
413
+ (_a = this.touchDataUpdateCallback) == null ? void 0 : _a.call(this, touchData);
414
+ if (action === ActionType.ACTION_UP) {
415
+ this.pointers.delete(pointerId);
416
+ }
417
+ });
418
+ __publicField(this, "handleMouseDown", (event) => {
419
+ event.preventDefault();
420
+ event.stopPropagation();
421
+ if (this.remoteElement) this.remoteElement.setPointerCapture(event.pointerId);
422
+ this.handlePointerEvent(event, ActionType.ACTION_DOWN, event.pointerId);
423
+ });
424
+ __publicField(this, "handleMouseMove", (event) => {
425
+ event.preventDefault();
426
+ event.stopPropagation();
427
+ this.handlePointerEvent(event, ActionType.ACTION_MOVE, event.pointerId);
428
+ if (!this.remoteElement) return;
429
+ const rect = this.remoteElement.getBoundingClientRect();
430
+ const { clientX: x, clientY: y } = event;
431
+ if (x < rect.left || x > rect.right || y < rect.top || y > rect.bottom) {
432
+ this.handleMouseUp(event);
433
+ }
434
+ });
435
+ __publicField(this, "handleMouseUp", (event) => {
436
+ event.preventDefault();
437
+ event.stopPropagation();
438
+ this.handlePointerEvent(event, ActionType.ACTION_UP, event.pointerId);
439
+ if (this.remoteElement) {
440
+ this.remoteElement.releasePointerCapture(event.pointerId);
441
+ }
442
+ });
443
+ __publicField(this, "handleMouseEnter", (event) => {
444
+ event.preventDefault();
445
+ event.stopPropagation();
446
+ if (event.pointerType !== "mouse") return;
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 (event.pointerType !== "mouse") return;
458
+ if (this.pointers.has(event.pointerId)) {
459
+ this.handlePointerEvent(event, ActionType.ACTION_UP, event.pointerId);
460
+ if (this.remoteElement) {
461
+ this.remoteElement.releasePointerCapture(event.pointerId);
462
+ }
463
+ }
464
+ });
465
+ this.logger = new Logger({
466
+ prefix: "MouseTouchControl",
467
+ enabledDebug
468
+ });
469
+ this.remoteElement = remoteElement;
470
+ this.cloudDeviceSize = cloudDeviceSize;
471
+ this.widthRatio = widthRatio;
472
+ this.videoAngle = videoAngle;
473
+ this.streamAngle = streamAngle;
474
+ this.isGroup = isGroup;
475
+ this.isMove = isMove;
476
+ this.pointers = /* @__PURE__ */ new Map();
477
+ this.touchDataUpdateCallback = touchDataUpdateCallback;
478
+ this.wheelDataUpdateCallback = wheelDataUpdateCallback;
479
+ this.init();
480
+ }
481
+ setVideoAngle(angle) {
482
+ this.videoAngle = angle;
483
+ }
484
+ setStreamAngle(angle) {
485
+ this.streamAngle = angle;
486
+ }
487
+ setWidthRatio(value) {
488
+ this.widthRatio = value;
489
+ }
490
+ setCloudDeviceSize(value) {
491
+ this.cloudDeviceSize = value;
492
+ }
493
+ validateParams() {
494
+ const video = this.remoteElement;
495
+ if (!(video instanceof HTMLVideoElement || video instanceof HTMLCanvasElement)) {
496
+ throw new Error("提供渲染挂载元素需为 canvas 或 video 元素");
497
+ }
498
+ }
499
+ addEvent() {
500
+ const remoteVideoElement = this.remoteElement;
501
+ if (remoteVideoElement) {
502
+ remoteVideoElement.addEventListener(DocumentEvent.POINTER_ENTER, this.handleMouseEnter);
503
+ remoteVideoElement.addEventListener(DocumentEvent.POINTER_MOVE, this.handleMouseMove);
504
+ remoteVideoElement.addEventListener(DocumentEvent.POINTER_LEAVE, this.handleMouseLeave);
505
+ remoteVideoElement.addEventListener(DocumentEvent.POINTER_DOWN, this.handleMouseDown);
506
+ remoteVideoElement.addEventListener(DocumentEvent.POINTER_UP, this.handleMouseUp);
507
+ remoteVideoElement.addEventListener(DocumentEvent.WHEEL, this.handleWheel);
508
+ }
509
+ }
510
+ offEvent() {
511
+ const remoteVideoElement = this.remoteElement;
512
+ if (remoteVideoElement) {
513
+ remoteVideoElement.removeEventListener(DocumentEvent.POINTER_ENTER, this.handleMouseEnter);
514
+ remoteVideoElement.removeEventListener(DocumentEvent.POINTER_MOVE, this.handleMouseMove);
515
+ remoteVideoElement.removeEventListener(DocumentEvent.POINTER_LEAVE, this.handleMouseLeave);
516
+ remoteVideoElement.removeEventListener(DocumentEvent.POINTER_DOWN, this.handleMouseDown);
517
+ remoteVideoElement.removeEventListener(DocumentEvent.POINTER_UP, this.handleMouseUp);
518
+ remoteVideoElement.removeEventListener(DocumentEvent.WHEEL, this.handleWheel);
519
+ }
520
+ }
521
+ init() {
522
+ this.validateParams();
523
+ this.addEvent();
524
+ }
525
+ destroy() {
526
+ this.logger.log("destroy");
527
+ this.offEvent();
528
+ }
529
+ }
530
+ class KeyboardControl {
531
+ constructor({
532
+ rootContainer,
533
+ inputDataUpdateCallback,
534
+ chineseDataUpdateCallback,
535
+ enabledDebug = false,
536
+ disabled = false,
537
+ enabledIMEKeyboard = false,
538
+ videoAngle
539
+ }) {
540
+ __publicField(this, "logger");
541
+ __publicField(this, "rootContainer");
542
+ __publicField(this, "keyboardContainerElement", null);
543
+ __publicField(this, "inputMethodEditorElement", null);
544
+ __publicField(this, "inputDataUpdateCallback");
545
+ __publicField(this, "chineseDataUpdateCallback");
546
+ __publicField(this, "videoAngle");
547
+ __publicField(this, "disabled", false);
548
+ __publicField(this, "enabledIMEKeyboard", false);
549
+ __privateAdd(this, _isComposing, false);
550
+ __publicField(this, "clearInput", () => {
551
+ if (this.inputMethodEditorElement) {
552
+ this.inputMethodEditorElement.value = "";
553
+ }
554
+ });
555
+ __publicField(this, "focusIME", () => {
556
+ requestAnimationFrame(() => {
557
+ var _a;
558
+ (_a = this.inputMethodEditorElement) == null ? void 0 : _a.focus();
559
+ });
560
+ });
561
+ __publicField(this, "blurIME", () => {
562
+ var _a;
563
+ (_a = this.inputMethodEditorElement) == null ? void 0 : _a.blur();
564
+ });
565
+ __publicField(this, "handleKeyDown", (e) => {
566
+ e.preventDefault();
567
+ const data = getKeyEventData(e);
568
+ this.inputDataUpdateCallback(data);
569
+ });
570
+ __publicField(this, "handleKeyboardContainerPointerenter", () => {
571
+ if (this.disabled) {
572
+ return;
573
+ }
574
+ if (this.inputMethodEditorElement) {
575
+ this.focusIME();
576
+ } else {
577
+ document.addEventListener(DocumentEvent.KEY_DOWN, this.handleKeyDown);
578
+ }
579
+ });
580
+ __publicField(this, "handleKeyboardContainerPointerleave", () => {
581
+ if (this.disabled) {
582
+ return;
583
+ }
584
+ if (this.inputMethodEditorElement) {
585
+ this.blurIME();
586
+ } else {
587
+ document.removeEventListener(DocumentEvent.KEY_DOWN, this.handleKeyDown);
588
+ }
589
+ });
590
+ __publicField(this, "handleIMECompositionStart", (_e) => {
591
+ __privateSet(this, _isComposing, true);
592
+ });
593
+ __publicField(this, "handleIMECompositionEnd", (e) => {
594
+ __privateSet(this, _isComposing, false);
595
+ const text = e.data;
596
+ if (text && text.length > 0) {
597
+ this.chineseDataUpdateCallback(new InputData(text));
598
+ }
599
+ this.clearInput();
600
+ });
601
+ __publicField(this, "handleIMEInput", (e) => {
602
+ const inputEvent = e;
603
+ if (__privateGet(this, _isComposing)) return;
604
+ const text = inputEvent.data;
605
+ if (text && text.length > 0) {
606
+ this.chineseDataUpdateCallback(new InputData(text));
607
+ }
608
+ this.clearInput();
609
+ });
610
+ __publicField(this, "handleIMEKeyDown", (event) => {
611
+ if (__privateGet(this, _isComposing)) return;
612
+ if (isFunctionKey(event)) {
613
+ const data = getKeyEventData(event);
614
+ if (data.keyCode === 50 && data.meta === 4096) return;
615
+ this.inputDataUpdateCallback(data);
616
+ }
617
+ });
618
+ this.logger = new Logger({
619
+ prefix: "KeyboardControl",
620
+ enabledDebug
621
+ });
622
+ this.disabled = disabled;
623
+ this.rootContainer = rootContainer;
624
+ this.inputDataUpdateCallback = inputDataUpdateCallback;
625
+ this.chineseDataUpdateCallback = chineseDataUpdateCallback;
626
+ this.videoAngle = videoAngle;
627
+ this.enabledIMEKeyboard = enabledIMEKeyboard;
628
+ this.init();
629
+ }
630
+ createKeyboardContainerElement() {
631
+ const keyboardContainerElement = document.createElement("div");
632
+ keyboardContainerElement.className = CLASS_NAME.KEYBOARD_CONTAINER_CLASS_NAME;
633
+ keyboardContainerElement.style.rotate = `${this.videoAngle}deg`;
634
+ return keyboardContainerElement;
635
+ }
636
+ createInputMethodEditor() {
637
+ const textareaElement = document.createElement("textarea");
638
+ textareaElement.classList.add(CLASS_NAME.INPUT_METHOD_EDITOR_CLASS_NAME);
639
+ textareaElement.autocomplete = "off";
640
+ textareaElement.autocapitalize = "off";
641
+ textareaElement.spellcheck = false;
642
+ return textareaElement;
643
+ }
644
+ mountNode() {
645
+ const keyboardContainerElement = this.createKeyboardContainerElement();
646
+ if (this.enabledIMEKeyboard) {
647
+ const inputMethodEditorElement = this.createInputMethodEditor();
648
+ keyboardContainerElement.appendChild(inputMethodEditorElement);
649
+ this.inputMethodEditorElement = inputMethodEditorElement;
650
+ }
651
+ this.rootContainer.appendChild(keyboardContainerElement);
652
+ this.keyboardContainerElement = keyboardContainerElement;
653
+ }
654
+ init() {
655
+ this.mountNode();
656
+ this.addEvent();
657
+ }
658
+ setKeyboardContainerSize(width, height) {
659
+ if (this.keyboardContainerElement) {
660
+ this.keyboardContainerElement.style.width = `${width}px`;
661
+ this.keyboardContainerElement.style.height = `${height}px`;
662
+ }
663
+ }
664
+ setKeyboardContainerElementStyle(style) {
665
+ if (this.keyboardContainerElement) {
666
+ this.keyboardContainerElement.style.rotate = `${style.rotate}deg`;
667
+ }
668
+ }
669
+ setVideoAngle(value) {
670
+ this.videoAngle = value;
671
+ this.setKeyboardContainerElementStyle({
672
+ rotate: value
673
+ });
674
+ }
675
+ openIMEKeyboard() {
676
+ var _a;
677
+ if (this.inputMethodEditorElement) {
678
+ return;
679
+ }
680
+ const inputMethodEditorElement = this.createInputMethodEditor();
681
+ if (inputMethodEditorElement) {
682
+ this.inputMethodEditorElement = inputMethodEditorElement;
683
+ (_a = this.keyboardContainerElement) == null ? void 0 : _a.appendChild(inputMethodEditorElement);
684
+ this.addInputMethodEditorEvent();
685
+ }
686
+ }
687
+ closeIMEKeyboard() {
688
+ var _a;
689
+ if (!this.inputMethodEditorElement) {
690
+ return;
691
+ }
692
+ this.offInputMethodEditorEvent();
693
+ (_a = this.keyboardContainerElement) == null ? void 0 : _a.removeChild(this.inputMethodEditorElement);
694
+ }
695
+ addKeyboardContainerEvent() {
696
+ var _a, _b;
697
+ (_a = this.keyboardContainerElement) == null ? void 0 : _a.addEventListener(DocumentEvent.POINTER_ENTER, this.handleKeyboardContainerPointerenter);
698
+ (_b = this.keyboardContainerElement) == null ? void 0 : _b.addEventListener(DocumentEvent.POINTER_LEAVE, this.handleKeyboardContainerPointerleave);
699
+ }
700
+ offKeyboardContainerEvent() {
701
+ var _a, _b;
702
+ (_a = this.keyboardContainerElement) == null ? void 0 : _a.removeEventListener(DocumentEvent.POINTER_ENTER, this.handleKeyboardContainerPointerenter);
703
+ (_b = this.keyboardContainerElement) == null ? void 0 : _b.removeEventListener(DocumentEvent.POINTER_LEAVE, this.handleKeyboardContainerPointerleave);
704
+ document.removeEventListener(DocumentEvent.KEY_DOWN, this.handleKeyDown);
705
+ }
706
+ addInputMethodEditorEvent() {
707
+ var _a, _b, _c, _d;
708
+ (_a = this.inputMethodEditorElement) == null ? void 0 : _a.addEventListener(DocumentEvent.COMPOSITION_START, this.handleIMECompositionStart);
709
+ (_b = this.inputMethodEditorElement) == null ? void 0 : _b.addEventListener(DocumentEvent.COMPOSITION_END, this.handleIMECompositionEnd);
710
+ (_c = this.inputMethodEditorElement) == null ? void 0 : _c.addEventListener(DocumentEvent.INPUT, this.handleIMEInput);
711
+ (_d = this.inputMethodEditorElement) == null ? void 0 : _d.addEventListener(DocumentEvent.KEY_DOWN, this.handleIMEKeyDown);
712
+ }
713
+ offInputMethodEditorEvent() {
714
+ var _a, _b, _c, _d;
715
+ (_a = this.inputMethodEditorElement) == null ? void 0 : _a.removeEventListener(DocumentEvent.COMPOSITION_START, this.handleIMECompositionStart);
716
+ (_b = this.inputMethodEditorElement) == null ? void 0 : _b.removeEventListener(DocumentEvent.COMPOSITION_END, this.handleIMECompositionEnd);
717
+ (_c = this.inputMethodEditorElement) == null ? void 0 : _c.removeEventListener(DocumentEvent.INPUT, this.handleIMEInput);
718
+ (_d = this.inputMethodEditorElement) == null ? void 0 : _d.removeEventListener(DocumentEvent.KEY_DOWN, this.handleIMEKeyDown);
719
+ }
720
+ addEvent() {
721
+ this.addKeyboardContainerEvent();
722
+ this.addInputMethodEditorEvent();
723
+ }
724
+ offEvent() {
725
+ this.offKeyboardContainerEvent();
726
+ this.offInputMethodEditorEvent();
727
+ }
728
+ destroy() {
729
+ var _a;
730
+ this.offEvent();
731
+ (_a = this.keyboardContainerElement) == null ? void 0 : _a.remove();
732
+ this.keyboardContainerElement = null;
733
+ this.inputMethodEditorElement = null;
734
+ }
735
+ }
736
+ _isComposing = new WeakMap();
737
+ const _WebRTCWrapper = class _WebRTCWrapper extends EventEmitter {
738
+ constructor({
739
+ connectConfig,
740
+ enabledDebug = false
741
+ }) {
742
+ super();
743
+ __publicField(this, "logger");
744
+ __publicField(this, "webRtcSDKInstance", null);
745
+ __privateAdd(this, _direction);
746
+ __privateAdd(this, _screenWidth);
747
+ __privateAdd(this, _screenHeight);
748
+ __privateAdd(this, _clarityLevel);
749
+ __privateAdd(this, _gestureMode);
750
+ this.logger = new Logger({
751
+ prefix: "Wrapper",
752
+ enabledDebug
753
+ });
754
+ const webRtcSDKInstance = new WebRTCSdk(connectConfig);
755
+ this.webRtcSDKInstance = webRtcSDKInstance;
756
+ this.addEvent();
757
+ }
758
+ addEvent() {
759
+ if (this.webRtcSDKInstance) {
760
+ const webRtcSDKInstance = this.webRtcSDKInstance;
761
+ webRtcSDKInstance.addListener(EmitType.streamTrack, (track) => {
762
+ this.emit(_WebRTCWrapper.EVENTS.RECEIVE_MEDIA_STREAM_TRACK, track);
763
+ });
764
+ webRtcSDKInstance.addListener(EmitType.iceConnectionState, (state) => {
765
+ this.logger.log("iceConnectionState", state);
766
+ if (state === _WebRTCWrapper.EVENTS.CONNECTED) {
767
+ this.emit(_WebRTCWrapper.EVENTS.CONNECTED);
768
+ }
769
+ });
770
+ webRtcSDKInstance.addListener(EmitType.webrtcError, (error) => {
771
+ this.logger.log("webrtcError", error);
772
+ if (error.code !== FailCode.CAMERA && error.code !== FailCode.DATACHANNEL_ERR && error.code !== FailCode.STREAM_STATE && error.code !== FailCode.AUTH_FAILED) {
773
+ this.emit(_WebRTCWrapper.EVENTS.STOP_CONNECT, error);
774
+ this.destroy();
775
+ }
776
+ this.emit(_WebRTCWrapper.EVENTS.ERROR, error);
777
+ });
778
+ if ("arrayBuffer" in EmitType) {
779
+ webRtcSDKInstance.addListener(EmitType.arrayBuffer, (buffer) => {
780
+ this.emit(_WebRTCWrapper.EVENTS.RECEIVE_ARRAY_BUFFER, buffer);
781
+ });
782
+ }
783
+ webRtcSDKInstance.addListener(EmitType.statisticInfo, (info) => {
784
+ this.emit(_WebRTCWrapper.EVENTS.STATISTIC_INFO, info);
785
+ });
786
+ webRtcSDKInstance.addListener(EmitType.cloudStatusChanged, (cloudStatus) => {
787
+ if (cloudStatus) {
788
+ this.logger.log("cloudStatusChanged", cloudStatus);
789
+ const { direction, screenWidth, screenHeight, clarityLevel, gestureMode } = cloudStatus;
790
+ if (__privateGet(this, _direction) === void 0 || __privateGet(this, _direction) !== direction) {
791
+ this.emit(_WebRTCWrapper.EVENTS.DIRECTION_CHANGE, direction === ContainerDirection.Vertical ? 0 : -90);
792
+ __privateSet(this, _direction, direction);
793
+ }
794
+ if (__privateGet(this, _screenWidth) === void 0 || __privateGet(this, _screenHeight) === void 0 || (__privateGet(this, _screenWidth) !== screenWidth || __privateGet(this, _screenHeight) !== screenHeight)) {
795
+ this.emit(_WebRTCWrapper.EVENTS.RESIZE, {
796
+ screenWidth,
797
+ screenHeight
798
+ });
799
+ __privateSet(this, _screenWidth, screenWidth);
800
+ __privateSet(this, _screenHeight, screenHeight);
801
+ }
802
+ if (__privateGet(this, _clarityLevel) === void 0 || __privateGet(this, _clarityLevel) !== clarityLevel) {
803
+ this.emit(_WebRTCWrapper.EVENTS.CLARITY_LEVEL_CHANGE, clarityLevel);
804
+ __privateSet(this, _clarityLevel, clarityLevel);
805
+ }
806
+ if (__privateGet(this, _gestureMode) === void 0 || __privateGet(this, _gestureMode) !== gestureMode) {
807
+ this.emit(_WebRTCWrapper.EVENTS.GESTURE_MODE_CHANGE, gestureMode);
808
+ __privateSet(this, _gestureMode, gestureMode);
809
+ }
810
+ }
811
+ });
812
+ }
813
+ }
814
+ offEvents() {
815
+ var _a;
816
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.removeAllListeners();
817
+ }
818
+ startConnection() {
819
+ var _a;
820
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.startConnection();
821
+ }
822
+ sendChannelData(type, data) {
823
+ var _a;
824
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.sendChannelData(type, data);
825
+ }
826
+ sendClickData(data) {
827
+ this.sendChannelData(ChannelDataType.ClickData, data);
828
+ }
829
+ sendActionWheel(data) {
830
+ this.sendChannelData(ChannelDataType.ActionWheel, data);
831
+ }
832
+ sendActionInput(data) {
833
+ this.sendChannelData(ChannelDataType.ActionInput, data);
834
+ }
835
+ sendActionChinese(data) {
836
+ this.sendChannelData(ChannelDataType.ActionChinese, data);
837
+ }
838
+ goBack() {
839
+ const keyEvent = new KeyEventData(MenuKey.BACK, 0);
840
+ this.sendActionInput(keyEvent);
841
+ }
842
+ goHome() {
843
+ const keyEvent = new KeyEventData(MenuKey.HOME, 0);
844
+ this.sendActionInput(keyEvent);
845
+ }
846
+ goTask() {
847
+ const keyEvent = new KeyEventData(MenuKey.TASK, 0);
848
+ this.sendActionInput(keyEvent);
849
+ }
850
+ enableAudio() {
851
+ this.sendChannelData(ChannelDataType.ActionCommandEvent, {
852
+ action: ActionCommandEventType.ACTION_CONTROL_AUDIO,
853
+ value: ActionCommandEventValue.ENABLE
854
+ });
855
+ }
856
+ disableAudio() {
857
+ this.sendChannelData(ChannelDataType.ActionCommandEvent, {
858
+ action: ActionCommandEventType.ACTION_CONTROL_AUDIO,
859
+ value: ActionCommandEventValue.DISABLE
860
+ });
861
+ }
862
+ /**
863
+ * @param level
864
+ * 高清: 3
865
+ * 标清: 2
866
+ * 流畅: 1
867
+ */
868
+ changeLevel(level) {
869
+ if (level < ClarityLevel.FLUENT || level > ClarityLevel.HIGH_DEFINITION) {
870
+ this.logger.error("清晰度等级错误,只能是1-3之间,分别是:流畅、标清 和 高清");
871
+ return;
872
+ }
873
+ this.sendChannelData(ChannelDataType.ActionClarity, new ClarityData(level));
874
+ }
875
+ /**
876
+ * @param value
877
+ * 发送剪贴板的内容
878
+ */
879
+ sendClipboardData(value) {
880
+ this.sendChannelData(ChannelDataType.ClipboardData, value);
881
+ }
882
+ setNavigationMode(mode) {
883
+ const data = new GestureData(mode);
884
+ this.sendChannelData(ChannelDataType.ActionGesture, data);
885
+ }
886
+ switchToGestureNavigation() {
887
+ this.setNavigationMode(GestureMode.GESTURE_NAVIGATION);
888
+ }
889
+ switchToThreeButtonNavigation() {
890
+ this.setNavigationMode(GestureMode.THREE_BUTTON_NAVIGATION);
891
+ }
892
+ destroy() {
893
+ var _a;
894
+ this.logger.log("destroy");
895
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.stop();
896
+ this.offEvents();
897
+ this.webRtcSDKInstance = null;
898
+ }
899
+ };
900
+ _direction = new WeakMap();
901
+ _screenWidth = new WeakMap();
902
+ _screenHeight = new WeakMap();
903
+ _clarityLevel = new WeakMap();
904
+ _gestureMode = new WeakMap();
905
+ __publicField(_WebRTCWrapper, "EVENTS", {
906
+ CONNECTED: "connected",
907
+ DIRECTION_CHANGE: "directionChange",
908
+ RESIZE: "resize",
909
+ CLARITY_LEVEL_CHANGE: "clarityLevel",
910
+ GESTURE_MODE_CHANGE: "gestureMode",
911
+ RECEIVE_MEDIA_STREAM_TRACK: "receiveMediaStreamTrack",
912
+ RECEIVE_ARRAY_BUFFER: "receiveArrayBuffer",
913
+ ERROR: "error",
914
+ STOP_CONNECT: "stopConnect",
915
+ STATISTIC_INFO: "statisticInfo",
916
+ CLICK_DATA: ChannelDataType.ClickData
917
+ });
918
+ let WebRTCWrapper = _WebRTCWrapper;
919
+ var SDKEvents = /* @__PURE__ */ ((SDKEvents2) => {
920
+ SDKEvents2["CHANNEL_EVENT"] = "channelEvent";
921
+ SDKEvents2["GROUP_CONTROL_EVENT"] = "groupControlEvent";
922
+ SDKEvents2["LOADED_SUCCESS"] = "loadedSuccess";
923
+ SDKEvents2["LOADED_FAILURE"] = "loadedFailure";
924
+ return SDKEvents2;
925
+ })(SDKEvents || {});
926
+ const _UniSDK = class _UniSDK extends EventEmitter {
927
+ constructor({
928
+ mountedElement,
929
+ connectConfig,
930
+ cloudDeviceSize = {
931
+ width: 720,
932
+ height: 1280
933
+ },
934
+ disabled = false,
935
+ enabledDebug = false,
936
+ isGroup = false,
937
+ disabledVerticalSwipe = false,
938
+ enabledIMEKeyboard = false,
939
+ remoteViewBackgroundColor = "transparent",
940
+ videoAngle = 0,
941
+ cursorType = 0,
942
+ enabledDecode = false
943
+ }) {
944
+ super();
945
+ __publicField(this, "logger");
946
+ __publicField(this, "mountedElement");
947
+ __publicField(this, "connectConfig");
948
+ __publicField(this, "cloudDeviceSize");
949
+ __publicField(this, "videoContainerElement", null);
950
+ __publicField(this, "containerResizeObserver", null);
951
+ __publicField(this, "remoteViewBackgroundColor", "transparent");
952
+ __publicField(this, "remoteController", null);
953
+ __publicField(this, "webRtcSDKInstance", null);
954
+ __publicField(this, "mouseTouchControl", null);
955
+ __publicField(this, "keyboardControl", null);
956
+ __publicField(this, "isGroup", false);
957
+ __publicField(this, "videoAngle", 0);
958
+ __publicField(this, "streamAngle", 0);
959
+ __publicField(this, "widthRatio", 0);
960
+ __publicField(this, "heightRatio", 0);
961
+ __publicField(this, "cursorType", 0);
962
+ __publicField(this, "disabled", false);
963
+ __publicField(this, "enabledDebug", false);
964
+ __publicField(this, "disabledVerticalSwipe", false);
965
+ __publicField(this, "enabledIMEKeyboard", false);
966
+ __publicField(this, "enabledDecode", false);
967
+ this.logger = new Logger({
968
+ prefix: "SDK",
969
+ enabledDebug
970
+ });
971
+ this.mountedElement = mountedElement;
972
+ this.connectConfig = connectConfig;
973
+ this.disabled = disabled;
974
+ this.remoteViewBackgroundColor = remoteViewBackgroundColor;
975
+ this.videoAngle = videoAngle;
976
+ this.cursorType = cursorType;
977
+ this.cloudDeviceSize = cloudDeviceSize;
978
+ this.isGroup = isGroup;
979
+ this.disabledVerticalSwipe = disabledVerticalSwipe;
980
+ this.enabledIMEKeyboard = enabledIMEKeyboard;
981
+ this.enabledDebug = enabledDebug;
982
+ this.enabledDecode = enabledDecode;
983
+ }
984
+ setVideoAngle(angle) {
985
+ var _a;
986
+ this.videoAngle = angle;
987
+ (_a = this.keyboardControl) == null ? void 0 : _a.setVideoAngle(angle);
988
+ }
989
+ getVideoAngle() {
990
+ return this.videoAngle;
991
+ }
992
+ setStreamAngle(angle) {
993
+ var _a;
994
+ this.streamAngle = angle;
995
+ (_a = this.mouseTouchControl) == null ? void 0 : _a.setStreamAngle(angle);
996
+ }
997
+ setCloudDeviceSize(value) {
998
+ var _a;
999
+ this.cloudDeviceSize = value;
1000
+ (_a = this.mouseTouchControl) == null ? void 0 : _a.setCloudDeviceSize(value);
1001
+ }
1002
+ validateParams() {
1003
+ this.logger.log("validateParams");
1004
+ if (this.mountedElement instanceof HTMLElement) {
1005
+ return true;
1006
+ }
1007
+ if (this.mountedElement && typeof this.mountedElement === "string") {
1008
+ const element = document.querySelector(this.mountedElement);
1009
+ if (!element) {
1010
+ throw new Error(`挂载的 "${this.mountedElement}" 节点不存在`);
1011
+ }
1012
+ this.mountedElement = element;
1013
+ } else {
1014
+ throw new Error("挂载节点找不到");
1015
+ }
1016
+ }
1017
+ init() {
1018
+ this.validateParams();
1019
+ this.createNode();
1020
+ this.mounted();
1021
+ this.addEvent();
1022
+ }
1023
+ createVideoContainerElement() {
1024
+ const videoContainerElement = document.createElement("div");
1025
+ videoContainerElement.className = CLASS_NAME.CONTAINER_CLASS_NAME;
1026
+ return videoContainerElement;
1027
+ }
1028
+ setKeyboardContainerSize(width, height) {
1029
+ var _a, _b;
1030
+ (_b = (_a = this.keyboardControl) == null ? void 0 : _a.setKeyboardContainerSize) == null ? void 0 : _b.call(_a, width, height);
1031
+ }
1032
+ createNode() {
1033
+ this.logger.log("createNode");
1034
+ const videoContainerElement = this.createVideoContainerElement();
1035
+ this.videoContainerElement = videoContainerElement;
1036
+ }
1037
+ calculateSize(w, h) {
1038
+ var _a;
1039
+ const isRotated = this.videoAngle % 180 !== 0;
1040
+ const containerWidth = isRotated ? h : w;
1041
+ const containerHeight = isRotated ? w : h;
1042
+ const cloudDeviceSize = this.cloudDeviceSize;
1043
+ const vWidth = cloudDeviceSize.width;
1044
+ const vHeight = cloudDeviceSize.height;
1045
+ const aspect = vWidth / vHeight;
1046
+ const videoHeight = containerWidth / aspect;
1047
+ let width;
1048
+ let height;
1049
+ if (videoHeight > containerHeight) {
1050
+ height = containerHeight;
1051
+ width = height * aspect;
1052
+ } else {
1053
+ width = containerWidth;
1054
+ height = videoHeight;
1055
+ }
1056
+ this.widthRatio = vWidth / width;
1057
+ this.heightRatio = vHeight / height;
1058
+ (_a = this.mouseTouchControl) == null ? void 0 : _a.setWidthRatio(this.widthRatio);
1059
+ this.setKeyboardContainerSize(width, height);
1060
+ }
1061
+ addContainerResizeListener() {
1062
+ if (!this.videoContainerElement) {
1063
+ return;
1064
+ }
1065
+ const resizeObserver = new ResizeObserver(([entry]) => {
1066
+ const { width, height } = entry.contentRect;
1067
+ this.calculateSize(width, height);
1068
+ });
1069
+ resizeObserver.observe(this.videoContainerElement);
1070
+ this.containerResizeObserver = resizeObserver;
1071
+ }
1072
+ offContainerResizeListener() {
1073
+ if (this.containerResizeObserver && this.videoContainerElement) {
1074
+ this.containerResizeObserver.unobserve(this.videoContainerElement);
1075
+ }
1076
+ }
1077
+ addEvent() {
1078
+ this.addContainerResizeListener();
1079
+ }
1080
+ offEvents() {
1081
+ this.logger.log("offEvents");
1082
+ this.offContainerResizeListener();
1083
+ this.removeAllListeners();
1084
+ }
1085
+ createRemoteController() {
1086
+ const remoteController = new RemoteController({
1087
+ rootContainer: this.videoContainerElement,
1088
+ enabledDecode: this.enabledDecode,
1089
+ loadedSuccess: () => {
1090
+ this.logger.log("loadedSuccess");
1091
+ this.emit(_UniSDK.EVENTS.LOADED_SUCCESS);
1092
+ },
1093
+ loadedFailure: (reason) => {
1094
+ this.logger.log("loadedFailure");
1095
+ this.emit(_UniSDK.EVENTS.LOADED_FAILURE, reason);
1096
+ },
1097
+ enabledDebug: this.enabledDebug
1098
+ });
1099
+ this.remoteController = remoteController;
1100
+ return remoteController;
1101
+ }
1102
+ createMouseTouchControl(remoteElement) {
1103
+ const mouseTouchControl = new MouseTouchControl({
1104
+ remoteElement,
1105
+ isGroup: this.isGroup,
1106
+ isMove: this.disabledVerticalSwipe,
1107
+ videoAngle: this.videoAngle,
1108
+ widthRatio: this.widthRatio,
1109
+ streamAngle: this.streamAngle,
1110
+ cloudDeviceSize: this.cloudDeviceSize,
1111
+ touchDataUpdateCallback: (data) => {
1112
+ var _a;
1113
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.sendClickData(data);
1114
+ },
1115
+ wheelDataUpdateCallback: (data) => {
1116
+ var _a;
1117
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.sendActionWheel(data);
1118
+ },
1119
+ enabledDebug: this.enabledDebug
1120
+ });
1121
+ this.mouseTouchControl = mouseTouchControl;
1122
+ return mouseTouchControl;
1123
+ }
1124
+ createKeyboardControl() {
1125
+ const keyboardControl = new KeyboardControl({
1126
+ rootContainer: this.videoContainerElement,
1127
+ videoAngle: this.videoAngle,
1128
+ disabled: this.disabled,
1129
+ enabledIMEKeyboard: this.enabledIMEKeyboard,
1130
+ inputDataUpdateCallback: (data) => {
1131
+ var _a;
1132
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.sendActionInput(data);
1133
+ },
1134
+ chineseDataUpdateCallback: (data) => {
1135
+ var _a;
1136
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.sendActionChinese(data);
1137
+ },
1138
+ enabledDebug: this.enabledDebug
1139
+ });
1140
+ this.keyboardControl = keyboardControl;
1141
+ return keyboardControl;
1142
+ }
1143
+ async mounted() {
1144
+ this.logger.log("mounted");
1145
+ if (this.mountedElement instanceof HTMLElement) {
1146
+ this.mountedElement.appendChild(this.videoContainerElement);
1147
+ requestAnimationFrame(() => {
1148
+ var _a;
1149
+ const { width, height } = this.videoContainerElement.getBoundingClientRect();
1150
+ this.calculateSize(width, height);
1151
+ const remoteController = this.createRemoteController();
1152
+ const webRtcSDKInstance = new WebRTCWrapper({
1153
+ connectConfig: {
1154
+ ...this.connectConfig,
1155
+ isGroup: this.isGroup
1156
+ },
1157
+ enabledDebug: this.enabledDebug
1158
+ });
1159
+ webRtcSDKInstance.startConnection();
1160
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.RECEIVE_MEDIA_STREAM_TRACK, (track) => {
1161
+ remoteController.startPlay(track);
1162
+ });
1163
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.RECEIVE_ARRAY_BUFFER, (buffer) => {
1164
+ remoteController.startDecode(buffer);
1165
+ });
1166
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.DIRECTION_CHANGE, (value) => {
1167
+ this.setStreamAngle(value);
1168
+ });
1169
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.RESIZE, (screen) => {
1170
+ this.setCloudDeviceSize({
1171
+ width: screen.screenWidth,
1172
+ height: screen.screenHeight
1173
+ });
1174
+ });
1175
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.CONNECTED, () => {
1176
+ this.emit(_UniSDK.EVENTS.CONNECTED);
1177
+ });
1178
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.STOP_CONNECT, () => {
1179
+ var _a2;
1180
+ (_a2 = this.remoteController) == null ? void 0 : _a2.stopPlay();
1181
+ });
1182
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.STATISTIC_INFO, (info) => {
1183
+ this.emit(_UniSDK.EVENTS.STATISTIC_INFO, info);
1184
+ });
1185
+ webRtcSDKInstance.addListener(WebRTCWrapper.EVENTS.CLARITY_LEVEL_CHANGE, (level) => {
1186
+ this.emit(_UniSDK.EVENTS.CLARITY_LEVEL_CHANGE, level);
1187
+ });
1188
+ this.webRtcSDKInstance = webRtcSDKInstance;
1189
+ const keyboardControl = this.createKeyboardControl();
1190
+ (_a = keyboardControl.keyboardContainerElement) == null ? void 0 : _a.append(remoteController.remoteElement);
1191
+ this.createMouseTouchControl(remoteController.remoteElement);
1192
+ });
1193
+ }
1194
+ }
1195
+ startConnection() {
1196
+ var _a;
1197
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.startConnection();
1198
+ }
1199
+ goBack() {
1200
+ var _a;
1201
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.goBack();
1202
+ }
1203
+ goHome() {
1204
+ var _a;
1205
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.goHome();
1206
+ }
1207
+ goTask() {
1208
+ var _a;
1209
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.goTask();
1210
+ }
1211
+ enableAudio() {
1212
+ var _a;
1213
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.enableAudio();
1214
+ }
1215
+ disableAudio() {
1216
+ var _a;
1217
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.disableAudio();
1218
+ }
1219
+ changeLevel(value) {
1220
+ var _a;
1221
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.changeLevel(value);
1222
+ }
1223
+ sendClipboardData(value) {
1224
+ var _a;
1225
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.sendClipboardData(value);
1226
+ }
1227
+ openIMEKeyboard() {
1228
+ var _a;
1229
+ (_a = this.keyboardControl) == null ? void 0 : _a.openIMEKeyboard();
1230
+ }
1231
+ closeIMEKeyboard() {
1232
+ var _a;
1233
+ (_a = this.keyboardControl) == null ? void 0 : _a.closeIMEKeyboard();
1234
+ }
1235
+ switchToGestureNavigation() {
1236
+ var _a;
1237
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.switchToGestureNavigation();
1238
+ }
1239
+ switchToThreeButtonNavigation() {
1240
+ var _a;
1241
+ (_a = this.webRtcSDKInstance) == null ? void 0 : _a.switchToThreeButtonNavigation();
1242
+ }
1243
+ destroy() {
1244
+ var _a, _b, _c, _d;
1245
+ this.logger.log("destroy");
1246
+ (_a = this.remoteController) == null ? void 0 : _a.destroy();
1247
+ (_b = this.mouseTouchControl) == null ? void 0 : _b.destroy();
1248
+ (_c = this.webRtcSDKInstance) == null ? void 0 : _c.destroy();
1249
+ this.offEvents();
1250
+ (_d = this.videoContainerElement) == null ? void 0 : _d.remove();
1251
+ }
1252
+ };
1253
+ __publicField(_UniSDK, "EVENTS", {
1254
+ ...SDKEvents,
1255
+ ...WebRTCWrapper.EVENTS
1256
+ });
1257
+ __publicField(_UniSDK, "CURSOR_TYPE", CursorType);
1258
+ __publicField(_UniSDK, "CLARITY_LEVEL", ClarityLevel);
1259
+ __publicField(_UniSDK, "CLARITY_LEVEL_LIST", CLARITY_LEVEL_LIST);
1260
+ let UniSDK = _UniSDK;
1261
+ export {
1262
+ UniSDK
1263
+ };