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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/lib/components/RemotePlayer/index.vue.d.ts +1 -73
  2. package/lib/composables/useCursorStyle.d.ts +1 -1
  3. package/lib/composables/useKeyboardControl.d.ts +1 -1
  4. package/lib/composables/useMouseTouchControl.d.ts +4 -4
  5. package/lib/composables/useRemoteVideo.d.ts +8 -25
  6. package/lib/composables/useResizeObserver.d.ts +1 -1
  7. package/lib/core/data/WebRtcError.d.ts +1 -2
  8. package/lib/core/data/WebrtcDataType.d.ts +1 -11
  9. package/lib/core/groupctrl/SdkController.d.ts +2 -2
  10. package/lib/core/rtc/WebRTCClient.d.ts +2 -5
  11. package/lib/core/rtc/WebRTCConfig.d.ts +1 -1
  12. package/lib/core/rtc/WebRtcNegotiate.d.ts +2 -2
  13. package/lib/core/signal/SignalingClient.d.ts +1 -1
  14. package/lib/core/util/TurnTestUtil.d.ts +2 -2
  15. package/lib/yjz-web-sdk.js +496 -1236
  16. package/package.json +5 -16
  17. package/lib/components/RemotePlayer/type.d.ts +0 -9
  18. package/lib/core/util/MapCache.d.ts +0 -20
  19. package/lib/render/Canvas2DRenderer.d.ts +0 -10
  20. package/lib/render/WebGLRenderer.d.ts +0 -16
  21. package/lib/render/WebGPURenderer.d.ts +0 -18
  22. package/lib/types/index.d.ts +0 -13
  23. package/lib/util/WasmUtil.d.ts +0 -17
  24. package/lib/worker/worker.d.ts +0 -1
  25. package/src/assets/icon/circle.svg +0 -1
  26. package/src/assets/icon/triangle.svg +0 -1
  27. package/src/assets/wasm/h264-atomic.wasm +0 -0
  28. package/src/assets/wasm/h264-simd.wasm +0 -0
  29. package/src/components/RemotePlayer/index.vue +0 -170
  30. package/src/components/RemotePlayer/type.ts +0 -11
  31. package/src/composables/useCursorStyle.ts +0 -15
  32. package/src/composables/useKeyboardControl.ts +0 -32
  33. package/src/composables/useMouseTouchControl.ts +0 -158
  34. package/src/composables/useRemoteVideo.ts +0 -248
  35. package/src/composables/useResizeObserver.ts +0 -27
  36. package/src/core/WebRTCSdk.ts +0 -561
  37. package/src/core/data/MessageType.ts +0 -70
  38. package/src/core/data/TurnType.ts +0 -25
  39. package/src/core/data/WebRtcError.ts +0 -93
  40. package/src/core/data/WebrtcDataType.ts +0 -354
  41. package/src/core/groupctrl/GroupCtrlSocketManager.ts +0 -94
  42. package/src/core/groupctrl/SdkController.ts +0 -96
  43. package/src/core/rtc/WebRTCClient.ts +0 -862
  44. package/src/core/rtc/WebRTCConfig.ts +0 -86
  45. package/src/core/rtc/WebRtcNegotiate.ts +0 -164
  46. package/src/core/signal/SignalingClient.ts +0 -221
  47. package/src/core/util/FileTypeUtils.ts +0 -75
  48. package/src/core/util/KeyCodeUtil.ts +0 -162
  49. package/src/core/util/Logger.ts +0 -83
  50. package/src/core/util/MapCache.ts +0 -135
  51. package/src/core/util/ScreenControlUtil.ts +0 -174
  52. package/src/core/util/TurnTestUtil.ts +0 -123
  53. package/src/env.d.ts +0 -30
  54. package/src/index.ts +0 -61
  55. package/src/render/Canvas2DRenderer.ts +0 -38
  56. package/src/render/WebGLRenderer.ts +0 -150
  57. package/src/render/WebGPURenderer.ts +0 -194
  58. package/src/types/index.ts +0 -15
  59. package/src/types/webgpu.d.ts +0 -1158
  60. package/src/util/WasmUtil.ts +0 -291
  61. package/src/worker/worker.ts +0 -292
@@ -1,93 +0,0 @@
1
- export enum FailCode {
2
- SOCKET = 10001,
3
- SOCKET_CLOSE = 10002,
4
- CREATE_OFFER = 10003,
5
- HANDLE_OFFER = 10004,
6
- CREATE_ANSWER = 10005,
7
- HANDLE_ANSWER = 10006,
8
- LOCAL_DES = 10007,
9
- REMOTE_DES = 10008,
10
- HANDLE_ICE = 10009,
11
- ICE_STATE = 10010,
12
- CAMERA = 10011,
13
- NOT_AVAILABLE = 10012,
14
- DATACHANNEL_ERR = 10013,
15
- STREAM_STATE = 10014,
16
- AUTH_FAILED = 10015,
17
- KICK_OUT_ERR = 10016,
18
- STATE_ERR = 10017,
19
- OPTION_ERR = 10018,
20
- }
21
-
22
- export const FailInfoMap: Record<FailCode, { type: string, description: string }> = {
23
- [FailCode.SOCKET]: { type: 'socket', description: 'WebSocket连接失败' },
24
- [FailCode.SOCKET_CLOSE]: { type: 'socket_close', description: 'WebSocket已关闭' },
25
- [FailCode.CREATE_OFFER]: { type: 'createOffer', description: '创建offer失败' },
26
- [FailCode.HANDLE_OFFER]: { type: 'handleOffer', description: '处理offer失败' },
27
- [FailCode.CREATE_ANSWER]: { type: 'createAnswer', description: '创建answer失败' },
28
- [FailCode.HANDLE_ANSWER]: { type: 'handleAnswer', description: '处理answer失败' },
29
- [FailCode.LOCAL_DES]: { type: 'setLocalDescription', description: '设置本地描述失败' },
30
- [FailCode.REMOTE_DES]: { type: 'setRemoteDescription', description: '设置远端描述失败' },
31
- [FailCode.HANDLE_ICE]: { type: 'handleICE', description: '处理 ICE 失败' },
32
- [FailCode.ICE_STATE]: { type: 'iceState', description: 'ICE 状态异常' },
33
- [FailCode.CAMERA]: { type: 'camera', description: '摄像头异常' },
34
- [FailCode.NOT_AVAILABLE]: { type: 'notAvailable', description: '网络环境异常' },
35
- [FailCode.DATACHANNEL_ERR]: { type: 'datachannel_err', description: '信令通道错误' },
36
- [FailCode.STREAM_STATE]: { type: 'stream_state', description: 'webrtc统计信息获取失败' },
37
- [FailCode.AUTH_FAILED]: { type: 'auth_failed', description: '鉴权失败' },
38
- [FailCode.KICK_OUT_ERR]: { type: 'kick_out_err', description: '被踢出投屏房间' },
39
- [FailCode.STATE_ERR]: { type: 'state_err', description: '云机无响应,请联系客服' },
40
- [FailCode.OPTION_ERR]: { type: 'option_err', description: '投屏配置异常,请检查配置' },
41
- }
42
-
43
- export interface WebRtcError {
44
- code: FailCode
45
- type: string
46
- message: string
47
- rawError?: any
48
- }
49
-
50
- export enum CameraFailCode {
51
- LOCAL_STREAM_FAIL = 20001,
52
- CAMERA_STREAM_FAIL = 20002,
53
- }
54
-
55
- export function createWebRtcError(code: FailCode, rawError?: any): WebRtcError {
56
- const info = FailInfoMap[code]
57
- return {
58
- code,
59
- type: info.type,
60
- message: info.description,
61
- rawError,
62
- }
63
- }
64
-
65
- export function createCameraError(code: CameraFailCode, message: string): CameraError {
66
- return {
67
- code,
68
- message,
69
- }
70
- }
71
-
72
- export interface CameraError {
73
- code: CameraFailCode
74
- message: string
75
- }
76
-
77
- export enum EmitType {
78
- signalMessage = 'signalMessage',
79
- webrtcError = 'webrtcError',
80
- cameraError = 'cameraError',
81
- sendAnswer = 'sendAnswer',
82
- sendOffer = 'sendOffer',
83
- sendICEMessage = 'sendICEMessage',
84
- streamTrack = 'streamTrack',
85
- iceConnectionState = 'iceConnectionState',
86
- cloudStatusChanged = 'cloudStatusChanged',
87
- statisticInfo = 'statisticInfo',
88
- cloudClipData = 'cloudClipData',
89
- screenshot = 'screenshot',
90
- reconnect = 'reconnect',
91
- groupError = 'groupError',
92
- arrayBuffer = 'arrayBuffer',
93
- }
@@ -1,354 +0,0 @@
1
- export enum ChannelDataType {
2
- ClickData = 'ClickData',
3
- ClipboardData = 'ClipboardData',
4
- ActionCommand = 'ActionCommand',
5
- ActionInput = 'ActionInput',
6
- ActionChinese = 'ActionChinese',
7
- ActionRequestCloudDeviceInfo = 'ActionRequestCloudDeviceInfo',
8
- ActionClarity = 'ActionClarity',
9
- ActionWheel = 'ActionWheel',
10
- CloudClipData = 'CloudClipData',
11
- ActionCommandEvent = 'ActionCommandEvent',
12
- ActionUpdateCloudStatus = 'ActionUpdateCloudStatus',
13
- ActionGesture = 'ActionGesture',
14
- ActionTrack = 'ActionTrack',
15
- RequestKeyFrame = 'RequestKeyFrame',
16
- }
17
-
18
- // 枚举:ActionCommandEventValue
19
- export enum ActionCommandEventValue {
20
- ENABLE = 'ENABLE',
21
- DISABLE = 'DISABLE',
22
- }
23
-
24
- export enum ActionCommandType {
25
- /**
26
- * 执行云机back
27
- */
28
- ActionBack = 'ActionBack',
29
-
30
- /**
31
- * 执行云机Home
32
- */
33
- ActionHome = 'ActionHome',
34
-
35
- /**
36
- * 执行云机Recent
37
- */
38
- ActionRecent = 'ActionRecent',
39
-
40
- /**
41
- * 切换到虚拟按键模式
42
- */
43
- ActionSwitchNavButtons = 'ActionSwitchNavButtons',
44
-
45
- /**
46
- * 切换到手势模式
47
- */
48
- ActionSwitchNavGestural = 'ActionSwitchNavGestural',
49
- }
50
-
51
- export interface ActionCommand {
52
- type: ActionCommandType
53
- }
54
-
55
- export enum ActionCommandEventType {
56
- /** 云机控制拉流端是否推流 Camera 和 MIC 数据到云机侧,或拉流端控制云机是否推流三方播放的音频 */
57
- ACTION_CONTROL_VIDEO_AND_AUDIO = 'ACTION_CONTROL_VIDEO_AND_AUDIO',
58
-
59
- /** 控制是否推送视频 */
60
- ACTION_CONTROL_VIDEO = 'ACTION_CONTROL_VIDEO',
61
-
62
- /** 控制是否推送音频 */
63
- ACTION_CONTROL_AUDIO = 'ACTION_CONTROL_AUDIO',
64
- }
65
-
66
- // 4. ActionType:手势动作类型(对应 adb 的 action 数值)
67
- export const ActionType = {
68
- ACTION_DOWN: 0,
69
- ACTION_MOVE: 2,
70
- ACTION_UP: 1,
71
- } as const
72
-
73
- export type ActionType = typeof ActionType[keyof typeof ActionType]
74
-
75
- // 5. StreamRotation:流旋转角度
76
- export const StreamRotation = {
77
- ROTATION_0: 0,
78
- ROTATION_90: 1,
79
- ROTATION_180: 2,
80
- ROTATION_270: 3,
81
- } as const
82
-
83
- export type StreamRotation = typeof StreamRotation[keyof typeof StreamRotation]
84
-
85
- // 6. ContainerDirection:容器方向
86
- export const ContainerDirection = {
87
- Vertical: 0,
88
- Horizontal: 1,
89
- } as const
90
-
91
- export type ContainerDirection = typeof ContainerDirection[keyof typeof ContainerDirection]
92
-
93
- // 类定义
94
-
95
- /**
96
- * TouchData - 触摸数据类,包含动作类型、指针索引、坐标、偏移时间以及触摸类型
97
- */
98
- export class TouchData {
99
- action: ActionType
100
- p: number
101
- x: number
102
- y: number
103
- offsetTime: number
104
- type: string
105
- index: number
106
- groupIndex: number
107
-
108
- constructor(action: ActionType, p: number, x: number, y: number, offsetTime: number, type: string = 'adb', index: number = -1, groupIndex: number =-1) {
109
- this.action = action
110
- this.p = p
111
- this.x = x
112
- this.y = y
113
- this.offsetTime = offsetTime
114
- this.type = type
115
- this.index = index
116
- this.groupIndex = groupIndex
117
- }
118
- }
119
-
120
- /**
121
- * InputData - 文本输入数据类
122
- */
123
- export class InputData {
124
- text: string
125
-
126
- constructor(text: string) {
127
- this.text = text
128
- }
129
- }
130
-
131
- /**
132
- * WheelData - 鼠标滚动事件
133
- */
134
- export class WheelData {
135
- axis: number
136
-
137
- constructor(axis: number) {
138
- this.axis = axis
139
- }
140
- }
141
-
142
- export class TrackEventData {
143
- visible: boolean
144
-
145
- constructor(visible: boolean) {
146
- this.visible = visible
147
- }
148
- }
149
-
150
- /**
151
- * KeyEventData - 键盘事件数据类,包含键码及修饰状态
152
- */
153
- export class KeyEventData {
154
- keyCode: number
155
- meta: number
156
-
157
- constructor(keyCode: number, meta: number) {
158
- this.keyCode = keyCode
159
- this.meta = meta
160
- }
161
- }
162
-
163
- /**
164
- * GestureData - 导航模式
165
- */
166
- export class GestureData {
167
- mode: number
168
-
169
- constructor(mode: number) {
170
- this.mode = mode
171
- }
172
- }
173
-
174
- export class ClarityData {
175
- level: number
176
- constructor(level: number) {
177
- this.level = level
178
- }
179
- }
180
-
181
- export class ChannelData {
182
- type: ChannelDataType
183
- data: string | null
184
- myId: string | null
185
-
186
- constructor(type: ChannelDataType, data: string | null = null, myId: string | null = null) {
187
- this.type = type
188
- this.data = data
189
- this.myId = myId
190
- }
191
-
192
- toString(): string {
193
- return JSON.stringify({ type: this.type, data: this.data, myId: this.myId })
194
- }
195
-
196
- /**
197
- * 格式化数据
198
- * 如果数据已经是字符串,则直接返回;否则使用 JSON.stringify() 转换为字符串
199
- * @param data 待转换数据
200
- * @returns 格式化后的字符串
201
- */
202
- private static formatData(data: any): string {
203
- return typeof data === 'string' ? data : JSON.stringify(data)
204
- }
205
-
206
- /**
207
- * 生成点击数据
208
- * @param touchData 触摸数据,可以是任意类型
209
- */
210
- static click(touchData: any): ChannelData {
211
- return new ChannelData(ChannelDataType.ClickData, this.formatData(touchData), '')
212
- }
213
-
214
- static action(actionData: any): ChannelData {
215
- return new ChannelData(ChannelDataType.ActionCommand, this.formatData(actionData), '')
216
- }
217
-
218
- /**
219
- * 生成剪贴板数据
220
- * @param data 剪贴板数据,可以是字符串或其他类型
221
- */
222
- static clipboard(data: any): ChannelData {
223
- console.log(`剪贴板数据,可以是字符串或其他类型 ${data}`)
224
- return new ChannelData(ChannelDataType.ClipboardData, this.formatData(data), '')
225
- }
226
-
227
- /**
228
- * 生成输入数据
229
- * @param data 输入数据对象
230
- */
231
- static input(data: any, myId: string): ChannelData {
232
- return new ChannelData(ChannelDataType.ActionInput, this.formatData(data), myId)
233
- }
234
-
235
- /**
236
- * 生成鼠标滚动数据
237
- * @param data 输入数据对象
238
- */
239
- static wheel(data: any): ChannelData {
240
- return new ChannelData(ChannelDataType.ActionWheel, this.formatData(data))
241
- }
242
-
243
- /**
244
- * 切换手势模式数据
245
- * @param data 输入数据对象
246
- */
247
- static gesture(data: any): ChannelData {
248
- return new ChannelData(ChannelDataType.ActionGesture, this.formatData(data))
249
- }
250
-
251
- /**
252
- * 生成中文输入数据
253
- * @param data 中文输入数据
254
- */
255
- static chinese(data: any): ChannelData {
256
- return new ChannelData(ChannelDataType.ActionChinese, this.formatData(data))
257
- }
258
-
259
- /**
260
- * 生成请求云设备信息数据
261
- */
262
- static requestCloudDeviceInfo(): ChannelData {
263
- return new ChannelData(ChannelDataType.ActionRequestCloudDeviceInfo, '')
264
- }
265
-
266
- /**
267
- * 生成清晰度数据(clarity)
268
- * @param data 清晰度数据
269
- */
270
- static clarity(data: any): ChannelData {
271
- return new ChannelData(ChannelDataType.ActionClarity, this.formatData(data))
272
- }
273
-
274
- static switchAudio(data: any): ChannelData {
275
- return new ChannelData(ChannelDataType.ActionCommandEvent, this.formatData(data))
276
- }
277
-
278
- static changeSender(data: any): ChannelData {
279
- return new ChannelData(ChannelDataType.ActionTrack, this.formatData(data))
280
- }
281
-
282
- static requestKeyFrame(data: any): ChannelData {
283
- return new ChannelData(ChannelDataType.RequestKeyFrame, this.formatData(data))
284
- }
285
- }
286
-
287
- export interface RTCStatsReportExtended extends RTCStatsReport {
288
- get(id: string): RTCStats | undefined
289
- }
290
-
291
- export interface ScreenStats {
292
- connectionType: string
293
- framesPerSecond: number
294
- currentRoundTripTime: number
295
- lostRate: number
296
- bitrate: string
297
- pliCount: number
298
- averageDecodeTime: number
299
- framesDecoded: number
300
- framesReceived: number
301
- }
302
-
303
- export interface CloudStatusPayload {
304
- direction: number
305
- screenWidth: number
306
- screenHeight: number
307
- gestureMode: number
308
- clarityLevel: number
309
- isClarity: boolean
310
- }
311
-
312
- export interface CloudPointer {
313
- rect: DOMRect
314
- x: number
315
- y: number
316
- action: ActionType
317
- offsetTime: number
318
- }
319
-
320
- export interface ScreenShotData {
321
- roomId: string
322
- base64: string
323
- }
324
-
325
- export class BitReader {
326
- private data: Uint8Array;
327
- private byteOffset = 0;
328
- private bitOffset = 0;
329
-
330
- constructor(data: Uint8Array) {
331
- this.data = data;
332
- }
333
-
334
- readBits(count: number): number {
335
- let result = 0;
336
- for (let i = 0; i < count; i++) {
337
- if (this.byteOffset >= this.data.length) break;
338
- const bit = (this.data[this.byteOffset] >> (7 - this.bitOffset)) & 1;
339
- result = (result << 1) | bit;
340
- this.bitOffset++;
341
- if (this.bitOffset === 8) {
342
- this.bitOffset = 0;
343
- this.byteOffset++;
344
- }
345
- }
346
- return result;
347
- }
348
-
349
- readUEG(): number {
350
- let zeros = 0;
351
- while (this.readBits(1) === 0) zeros++;
352
- return (1 << zeros) - 1 + this.readBits(zeros);
353
- }
354
- }
@@ -1,94 +0,0 @@
1
- import type { WebRTCConfigOptions } from '../rtc/WebRTCConfig'
2
- import { SdkController } from './SdkController'
3
- import type { WebRTCSdk } from '../WebRTCSdk'
4
- import { ChannelDataType, KeyEventData } from '../data/WebrtcDataType'
5
- import {enableLog, setLogLevel} from "../util/Logger";
6
-
7
- export class GroupCtrlSocketManager {
8
- private config?: WebRTCConfigOptions | undefined
9
- private websocketModeSdkController?: SdkController | undefined
10
- private isSynchronous = true
11
-
12
- constructor(config: WebRTCConfigOptions) {
13
- this.config = config
14
- enableLog(!!this.config.enableLogger);
15
- if(this.config.enableLogger !== undefined && this.config.enableLogger){
16
- if(this.config.loggerLevel !== undefined) {
17
- setLogLevel(this.config.loggerLevel);
18
- }
19
- }
20
- this.websocketModeSdkController = new SdkController(config)
21
- }
22
-
23
- public getRTCSdk(): WebRTCSdk | undefined {
24
- return this.websocketModeSdkController?.getRTCSdk()
25
- }
26
-
27
- public startGroupControl() {
28
- if (this.config?.groupId) {
29
- this.websocketModeSdkController?.start()
30
- }
31
- else {
32
- throw new Error('必须生成一个groupId')
33
- }
34
- }
35
-
36
- public stopControl(): void {
37
- this.websocketModeSdkController?.stop()
38
- }
39
-
40
- public sendData(type: ChannelDataType, data: any): void {
41
- this.getRTCSdk()?.sendChannelData(type, data)
42
- if (this.isSynchronous) {
43
- this.websocketModeSdkController?.groupSendAction(type, data)
44
- }
45
- }
46
-
47
- public sendControlEvent(key: number): void {
48
- const keyEvent = new KeyEventData(key, 0)
49
- this.getRTCSdk()?.sendChannelData(ChannelDataType.ActionInput, keyEvent)
50
- if (this.isSynchronous) {
51
- this.websocketModeSdkController?.groupSendAction(ChannelDataType.ActionInput, keyEvent)
52
- }
53
- }
54
-
55
- public switchToMainWebsocketMode(roomId: string) {
56
- if (this.config) {
57
- if (roomId === this.config.mainRoomIdOfGroup) {
58
- console.error(`切换主控必须为从控, 期望主控房间号:${roomId}, 当前主控房间号:${this.config.mainRoomIdOfGroup}`)
59
- }
60
- else {
61
- this.updateConfig(roomId)
62
- this.websocketModeSdkController?.updateConfig(this.config)
63
- this.websocketModeSdkController?.switchControlToMainMessage(roomId)
64
- }
65
- }
66
- }
67
-
68
- public synchronousOperation(isSynchronous: boolean): void {
69
- this.isSynchronous = isSynchronous
70
- }
71
-
72
- public setGroupAcceptControl(roomIds: string[], acceptControl: boolean): void {
73
- this.websocketModeSdkController?.setGroupAcceptControl(roomIds, acceptControl)
74
- }
75
-
76
- private updateConfig(newMainRoomId: string): void {
77
- if (this.config) {
78
- if (this.config.subRoomIdsOfGroup) {
79
- const index = this.config.subRoomIdsOfGroup.indexOf(newMainRoomId)
80
- if (index !== -1) {
81
- this.config.subRoomIdsOfGroup.splice(index, 1)
82
- }
83
- }
84
- if (this.config.mainRoomIdOfGroup) {
85
- if (!this.config.subRoomIdsOfGroup) {
86
- this.config.subRoomIdsOfGroup = []
87
- }
88
- this.config.subRoomIdsOfGroup.push(this.config.mainRoomIdOfGroup)
89
- }
90
- this.config.mainRoomIdOfGroup = newMainRoomId
91
- this.config.roomId = newMainRoomId
92
- }
93
- }
94
- }
@@ -1,96 +0,0 @@
1
- import { EventEmitter } from 'eventemitter3'
2
- import type { WebRTCConfigOptions } from '../rtc/WebRTCConfig'
3
- import { WebRTCSdk } from '../WebRTCSdk'
4
- import { EmitType } from '../data/WebRtcError'
5
- import type { ChannelDataType } from '../data/WebrtcDataType'
6
- import type { ConnectorType } from '../data/MessageType'
7
-
8
- // SDK 控制器,将 SDK 与事件分发解耦
9
- export class SdkController extends EventEmitter {
10
- private readonly sdk: WebRTCSdk
11
- private readonly config: WebRTCConfigOptions
12
-
13
- constructor(config: WebRTCConfigOptions) {
14
- super()
15
- this.config = config
16
- this.sdk = new WebRTCSdk(this.config)
17
- this.initSdk()
18
- }
19
-
20
- private initSdk(): void {
21
- const id = this.config.roomId
22
-
23
- // 清除之前所有监听,防止重复绑定
24
- this.sdk.removeAllListeners()
25
- this.sdk.on(EmitType.streamTrack, (track) => {
26
- const isVideo = track.kind === 'video'
27
- this.emit(EmitType.streamTrack, isVideo, track)
28
- })
29
- this.sdk.on(EmitType.arrayBuffer, (arrayBuffer: ArrayBuffer) => {
30
- this.emit(EmitType.arrayBuffer, arrayBuffer)
31
- })
32
- this.sdk.on(EmitType.cloudStatusChanged, (status) => {
33
- this.emit(EmitType.cloudStatusChanged, status)
34
- })
35
-
36
- this.sdk.on(EmitType.iceConnectionState, state => this.emit(EmitType.iceConnectionState, id, state))
37
- this.sdk.on(EmitType.webrtcError, (err) => {
38
- this.emit(EmitType.webrtcError, id, err)
39
- this.stop()
40
- })
41
- }
42
-
43
- start(): void { this.sdk.startConnection() }
44
- stop(): void {
45
- this.sdk.stop()
46
- this.sdk.removeAllListeners()
47
- }
48
-
49
- sendData(type: ChannelDataType, data: any): void {
50
- if ((this.config.canOperate) && this.config.connectStatus === 1) {
51
- this.sdk.sendChannelData(type, data)
52
- }
53
- }
54
-
55
- sendControlData(key: number): void {
56
- if ((this.config.canOperate) && this.config.connectStatus === 1) {
57
- this.sdk.sendControlEvent(key)
58
- }
59
- }
60
-
61
- groupSendAction(type: ChannelDataType, data: any) {
62
- this.sdk.groupSendAction(type, data)
63
- }
64
-
65
- /**
66
- * rtc群控环境下切换主从, 群控中每个被控者都是一个独立连接(websocket + webrtc)
67
- * 因此切换主从时每个连接向自己对应的信令服务发送此信令, 信令收到后将switchControl透传给目标roomId的云机.
68
- *
69
- * @param roomId 切换目标房间号
70
- * @param connectorType 切换目标类型
71
- */
72
- switchControl(roomId: string, connectorType: ConnectorType): void {
73
- this.sdk.switchControl(roomId, connectorType)
74
- }
75
-
76
- updateConfig(options: WebRTCConfigOptions) {
77
- this.sdk.updateConfig(options)
78
- }
79
-
80
- /**
81
- * 内网转发群控环境下切换主从, 群控中主控和所有从控处于同一连接(websocket)
82
- * 因此切换主从时只需要发送一次此信令, 告诉信令要将哪个房间切换为主控. 信令服务会判断主从关系变化, 然后将switchControl分别发送给本次切换对应的2台云机.
83
- * @param roomId
84
- */
85
- switchControlToMainMessage(roomId: string): void {
86
- this.sdk.switchControlToMain(roomId)
87
- }
88
-
89
- public setGroupAcceptControl(roomIds: string[], acceptControl: boolean) {
90
- this.sdk.sendGroupAcceptControl(roomIds, acceptControl)
91
- }
92
-
93
- public getRTCSdk(): WebRTCSdk {
94
- return this.sdk
95
- }
96
- }