yjz-web-sdk 1.0.8-beta.10 → 1.0.8-beta.12

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.
@@ -1,9 +1,10 @@
1
- import { EventEmitter } from "eventemitter3";
2
- import { SignalingClient } from "./signal/SignalingClient.ts";
3
- import { WebRTCClient } from "./rtc/WebRTCClient.ts";
4
- import { WebRTCConfig } from "./rtc/WebRTCConfig.ts";
1
+ import { EventEmitter } from 'eventemitter3';
2
+ import { SignalingClient } from './signal/SignalingClient';
3
+ import { WebRTCClient } from './rtc/WebRTCClient';
5
4
  import type { WebRTCConfigOptions } from './rtc/WebRTCConfig';
6
- import { ChannelDataType } from "./data/WebrtcDataType.ts";
5
+ import { WebRTCConfig } from './rtc/WebRTCConfig';
6
+ import { ConnectorType } from './data/MessageType';
7
+ import { ChannelDataType } from './data/WebrtcDataType';
7
8
  export declare class WebRTCSdk extends EventEmitter {
8
9
  config: WebRTCConfig | null;
9
10
  signalingClient: SignalingClient | null;
@@ -21,9 +22,11 @@ export declare class WebRTCSdk extends EventEmitter {
21
22
  startConnection(): void;
22
23
  private prepareConnection;
23
24
  reconnect(): Promise<void>;
24
- initConnectConfig(): void;
25
+ initConnectConfig(initConfig?: boolean): void;
25
26
  initSignalingClient(): void;
26
- switchControl(isControl: boolean): void;
27
+ switchControl(roomId: string, connectorType: ConnectorType): void;
28
+ updateConfig(options: WebRTCConfigOptions): void;
29
+ switchControlToMain(roomId: string): void;
27
30
  resetConfig(): void;
28
31
  /** 停止连接,并发送退出信令 */
29
32
  stop(): void;
@@ -35,11 +38,11 @@ export declare class WebRTCSdk extends EventEmitter {
35
38
  /** 发送信道数据 */
36
39
  sendChannelData(type: ChannelDataType, data: any): void;
37
40
  sendControlEvent(key: number): void;
38
- sendRequestScreenshot(visible: boolean): void;
41
+ sendGroupAcceptControl(roomIds: string[], acceptControl: boolean): void;
39
42
  /**
40
- * 处理 signal 消息,根据不同消息类型分发到 webRTCClient 或直接触发 SDK 事件
41
- * @param message 信令消息
42
- */
43
+ * 处理 signal 消息,根据不同消息类型分发到 webRTCClient 或直接触发 SDK 事件
44
+ * @param message 信令消息
45
+ */
43
46
  private handleSignaling;
44
47
  clearTimer: () => void;
45
48
  /** 发送 Offer 信令 */
@@ -50,4 +53,5 @@ export declare class WebRTCSdk extends EventEmitter {
50
53
  sendICEMessage: (ice: string) => void;
51
54
  sendPong(): void;
52
55
  sendSignOut(): void;
56
+ groupSendAction(type: ChannelDataType, data: any): void;
53
57
  }
@@ -9,6 +9,7 @@ export declare enum MessageType {
9
9
  Pong = "Pong",
10
10
  SendScreenshot = "SendScreenshot",
11
11
  KickOut = "KickOut",
12
+ GroupPeersMessage = "GroupPeer",
12
13
  Error = "Error"
13
14
  }
14
15
  export declare enum SendType {
@@ -19,8 +20,41 @@ export declare enum SendType {
19
20
  IceCandidates = "IceCandidates",
20
21
  Pong = "Pong",
21
22
  Identity = "Web",
22
- RequestScreenshot = "RequestScreenshot",
23
- SwitchControl = "SwitchControl"
23
+ SwitchControl = "SwitchControl",
24
+ GroupSignIn = "GroupSignIn",
25
+ GroupSignOut = "GroupSignOut",
26
+ GroupSendAction = "GroupSendAction",
27
+ SwitchControlToMain = "SwitchControlToMain",
28
+ GroupAcceptControl = "GroupAcceptControl"
29
+ }
30
+ /**
31
+ * 标识自己以什么类型连接云机
32
+ * 内网转发类型中,主从切换由config中mainRoomIdOfGroup, subRoomIdsOfGroup控制
33
+ * 非内网转发类型中,主从切换由config中connectorType控制
34
+ */
35
+ export declare enum ConnectorType {
36
+ /**
37
+ * 主控类型
38
+ * 页面展示: WebRTC
39
+ * 数据通道: WebRTC dataChannel
40
+ */
41
+ WebRTC = "webrtc",
42
+ /**
43
+ * 内网转发类型
44
+ * 主控
45
+ * 页面展示: WebRTC
46
+ * 数据通道: WebRTC dataChannel
47
+ * 从控
48
+ * 页面展示: Websocket
49
+ * 数据通道: Websocket
50
+ */
51
+ LanForwarding = "lanForwarding",
52
+ /**
53
+ * 混合-从控类型
54
+ * 页面展示: Websocket
55
+ * 数据通道: WebRTC dataChannel
56
+ */
57
+ Hybrid = "hybrid"
24
58
  }
25
59
  export declare enum IceConnectionState {
26
60
  NEW = "new",
@@ -51,6 +51,6 @@ export declare enum EmitType {
51
51
  statisticInfo = "statisticInfo",
52
52
  cloudClipData = "cloudClipData",
53
53
  screenshot = "screenshot",
54
- groupError = "groupError",
55
- reconnect = "reconnect"
54
+ reconnect = "reconnect",
55
+ groupError = "groupError"
56
56
  }
@@ -19,24 +19,24 @@ export declare enum ActionCommandEventValue {
19
19
  }
20
20
  export declare enum ActionCommandType {
21
21
  /**
22
- * 执行云机back
23
- */
22
+ * 执行云机back
23
+ */
24
24
  ActionBack = "ActionBack",
25
25
  /**
26
- * 执行云机Home
27
- */
26
+ * 执行云机Home
27
+ */
28
28
  ActionHome = "ActionHome",
29
29
  /**
30
- * 执行云机Recent
31
- */
30
+ * 执行云机Recent
31
+ */
32
32
  ActionRecent = "ActionRecent",
33
33
  /**
34
- * 切换到虚拟按键模式
35
- */
34
+ * 切换到虚拟按键模式
35
+ */
36
36
  ActionSwitchNavButtons = "ActionSwitchNavButtons",
37
37
  /**
38
- * 切换到手势模式
39
- */
38
+ * 切换到手势模式
39
+ */
40
40
  ActionSwitchNavGestural = "ActionSwitchNavGestural"
41
41
  }
42
42
  export interface ActionCommand {
@@ -124,51 +124,51 @@ export declare class ChannelData {
124
124
  constructor(type: ChannelDataType, data?: string | null, myId?: string | null);
125
125
  toString(): string;
126
126
  /**
127
- * 格式化数据
128
- * 如果数据已经是字符串,则直接返回;否则使用 JSON.stringify() 转换为字符串
129
- * @param data 待转换数据
130
- * @returns 格式化后的字符串
131
- */
127
+ * 格式化数据
128
+ * 如果数据已经是字符串,则直接返回;否则使用 JSON.stringify() 转换为字符串
129
+ * @param data 待转换数据
130
+ * @returns 格式化后的字符串
131
+ */
132
132
  private static formatData;
133
133
  /**
134
- * 生成点击数据
135
- * @param touchData 触摸数据,可以是任意类型
136
- */
134
+ * 生成点击数据
135
+ * @param touchData 触摸数据,可以是任意类型
136
+ */
137
137
  static click(touchData: any): ChannelData;
138
138
  static action(actionData: any): ChannelData;
139
139
  /**
140
- * 生成剪贴板数据
141
- * @param data 剪贴板数据,可以是字符串或其他类型
142
- */
140
+ * 生成剪贴板数据
141
+ * @param data 剪贴板数据,可以是字符串或其他类型
142
+ */
143
143
  static clipboard(data: any): ChannelData;
144
144
  /**
145
- * 生成输入数据
146
- * @param data 输入数据对象
147
- */
145
+ * 生成输入数据
146
+ * @param data 输入数据对象
147
+ */
148
148
  static input(data: any, myId: string): ChannelData;
149
149
  /**
150
- * 生成鼠标滚动数据
151
- * @param data 输入数据对象
152
- */
150
+ * 生成鼠标滚动数据
151
+ * @param data 输入数据对象
152
+ */
153
153
  static wheel(data: any): ChannelData;
154
154
  /**
155
- * 切换手势模式数据
156
- * @param data 输入数据对象
157
- */
155
+ * 切换手势模式数据
156
+ * @param data 输入数据对象
157
+ */
158
158
  static gesture(data: any): ChannelData;
159
159
  /**
160
- * 生成中文输入数据
161
- * @param data 中文输入数据
162
- */
160
+ * 生成中文输入数据
161
+ * @param data 中文输入数据
162
+ */
163
163
  static chinese(data: any): ChannelData;
164
164
  /**
165
- * 生成请求云设备信息数据
166
- */
165
+ * 生成请求云设备信息数据
166
+ */
167
167
  static requestCloudDeviceInfo(): ChannelData;
168
168
  /**
169
- * 生成清晰度数据(clarity)
170
- * @param data 清晰度数据
171
- */
169
+ * 生成清晰度数据(clarity)
170
+ * @param data 清晰度数据
171
+ */
172
172
  static clarity(data: any): ChannelData;
173
173
  static switchAudio(data: any): ChannelData;
174
174
  static changeSender(data: any): ChannelData;
@@ -202,3 +202,7 @@ export interface CloudPointer {
202
202
  action: ActionType;
203
203
  offsetTime: number;
204
204
  }
205
+ export interface ScreenShotData {
206
+ roomId: string;
207
+ base64: string;
208
+ }
@@ -0,0 +1,18 @@
1
+ import type { WebRTCConfigOptions } from '../rtc/WebRTCConfig';
2
+ import type { WebRTCSdk } from '../WebRTCSdk';
3
+ import { ChannelDataType } from '../data/WebrtcDataType';
4
+ export declare class GroupCtrlSocketManager {
5
+ private config?;
6
+ private websocketModeSdkController?;
7
+ private isSynchronous;
8
+ constructor(config: WebRTCConfigOptions);
9
+ getRTCSdk(): WebRTCSdk | undefined;
10
+ startGroupControl(): void;
11
+ stopControl(): void;
12
+ sendData(type: ChannelDataType, data: any): void;
13
+ sendControlEvent(key: number): void;
14
+ switchToMainWebsocketMode(roomId: string): void;
15
+ synchronousOperation(isSynchronous: boolean): void;
16
+ setGroupAcceptControl(roomIds: string[], acceptControl: boolean): void;
17
+ private updateConfig;
18
+ }
@@ -1,16 +1,33 @@
1
- import { EventEmitter } from "eventemitter3";
2
- import type { WebRTCConfigOptions } from "../rtc/WebRTCConfig.ts";
3
- import type { ChannelDataType } from "../data/WebrtcDataType.ts";
1
+ import { EventEmitter } from 'eventemitter3';
2
+ import type { WebRTCConfigOptions } from '../rtc/WebRTCConfig.ts';
3
+ import { WebRTCSdk } from '../WebRTCSdk';
4
+ import type { ChannelDataType } from '../data/WebrtcDataType.ts';
5
+ import type { ConnectorType } from '../data/MessageType';
4
6
  export declare class SdkController extends EventEmitter {
5
- private sdk;
6
- private config;
7
+ private readonly sdk;
8
+ private readonly config;
7
9
  constructor(config: WebRTCConfigOptions);
8
10
  private initSdk;
9
- setIsControl(value: boolean): void;
10
11
  start(): void;
11
12
  stop(): void;
12
- switchControl(isControl: boolean): void;
13
13
  sendData(type: ChannelDataType, data: any): void;
14
14
  sendControlData(key: number): void;
15
- requestScreenshot(visible: boolean): void;
15
+ groupSendAction(type: ChannelDataType, data: any): void;
16
+ /**
17
+ * rtc群控环境下切换主从, 群控中每个被控者都是一个独立连接(websocket + webrtc)
18
+ * 因此切换主从时每个连接向自己对应的信令服务发送此信令, 信令收到后将switchControl透传给目标roomId的云机.
19
+ *
20
+ * @param roomId 切换目标房间号
21
+ * @param connectorType 切换目标类型
22
+ */
23
+ switchControl(roomId: string, connectorType: ConnectorType): void;
24
+ updateConfig(options: WebRTCConfigOptions): void;
25
+ /**
26
+ * 内网转发群控环境下切换主从, 群控中主控和所有从控处于同一连接(websocket)
27
+ * 因此切换主从时只需要发送一次此信令, 告诉信令要将哪个房间切换为主控. 信令服务会判断主从关系变化, 然后将switchControl分别发送给本次切换对应的2台云机.
28
+ * @param roomId
29
+ */
30
+ switchControlToMainMessage(roomId: string): void;
31
+ setGroupAcceptControl(roomIds: string[], acceptControl: boolean): void;
32
+ getRTCSdk(): WebRTCSdk;
16
33
  }
@@ -1,3 +1,5 @@
1
+ import { ConnectorType } from '../data/MessageType';
2
+ import { LogLevel } from "../util/Logger.ts";
1
3
  export interface WebRTCConfigOptions {
2
4
  signalServerUrl: string;
3
5
  myId?: string;
@@ -9,10 +11,6 @@ export interface WebRTCConfigOptions {
9
11
  turnServerUri?: string;
10
12
  turnServerUserName?: string;
11
13
  turnServerPassword?: string;
12
- isControl: boolean;
13
- screenshotWidth?: number;
14
- screenshotHeight?: number;
15
- screenshotQuality?: number;
16
14
  canOperate?: boolean;
17
15
  screenUrl?: string;
18
16
  connectStatus?: number;
@@ -26,6 +24,15 @@ export interface WebRTCConfigOptions {
26
24
  isCalculate?: boolean;
27
25
  traceId?: string;
28
26
  signAgain?: boolean;
27
+ connectorType?: ConnectorType;
28
+ mainRoomIdOfGroup?: string;
29
+ subRoomIdsOfGroup?: string[];
30
+ mainCloudMyId?: string;
31
+ connectorAndRoomId?: Map<string, string>;
32
+ groupId?: string;
33
+ cacheTimeout?: number;
34
+ enableLogger?: boolean;
35
+ loggerLevel?: LogLevel;
29
36
  }
30
37
  export declare class WebRTCConfig {
31
38
  signalServerUrl: string;
@@ -38,13 +45,16 @@ export declare class WebRTCConfig {
38
45
  turnServerUri: string;
39
46
  turnServerUserName: string;
40
47
  turnServerPassword: string;
41
- isControl: boolean;
42
- screenshotWidth: number;
43
- screenshotHeight: number;
44
- screenshotQuality: number;
45
48
  token: string;
49
+ connectorType: ConnectorType;
50
+ mainRoomIdOfGroup?: string;
51
+ subRoomIdsOfGroup?: string[];
52
+ mainCloudMyId?: string;
53
+ connectorAndRoomId?: Map<string, string>;
54
+ groupId?: string;
46
55
  isGroup: boolean;
47
56
  turnKey: Array<string>;
48
57
  traceId: string;
58
+ signAgain: boolean;
49
59
  constructor(options: WebRTCConfigOptions);
50
60
  }
@@ -1,5 +1,6 @@
1
- import { EventEmitter } from "eventemitter3";
2
- import type { WebRTCConfig } from "../rtc/WebRTCConfig.ts";
1
+ import { EventEmitter } from 'eventemitter3';
2
+ import type { WebRTCConfig } from '../rtc/WebRTCConfig.ts';
3
+ import { ConnectorType } from '../data/MessageType';
3
4
  export declare class SignalingClient extends EventEmitter {
4
5
  private config;
5
6
  private webSocket;
@@ -21,10 +22,9 @@ export declare class SignalingClient extends EventEmitter {
21
22
  */
22
23
  sendMessage(message: string): void;
23
24
  sendSignInMessage(): void;
24
- sendSwitchControlMessage(isCtrl: boolean): void;
25
- /**
26
- * 用于从控请求当前截屏
27
- * @param visible 当前从控page控件是否可见
28
- */
29
- sendRequestScreenshot(visible: boolean): void;
25
+ sendSwitchControlMessage(roomId: string, connectorType: ConnectorType): void;
26
+ sendSwitchControlToMainMessage(roomId: string): void;
27
+ sendGroupAcceptControl(roomIds: string[], acceptControl: boolean): void;
28
+ sendGroupAction(action: string): void;
29
+ sendGroupSignInMessage(): void;
30
30
  }
@@ -1,10 +1,13 @@
1
- import { KeyEventData } from "../data/WebrtcDataType.ts";
2
1
  /**
3
2
  * 根据浏览器 KeyboardEvent 计算 Android 平台的 meta 状态值
4
3
  * @param event - 浏览器的 KeyboardEvent
5
4
  * @returns 计算后的 meta 状态
6
5
  */
7
6
  export declare const computeAndroidMetaState: (event: KeyboardEvent) => number;
7
+ export interface KeyEventData {
8
+ keyCode: number;
9
+ meta: number;
10
+ }
8
11
  /**
9
12
  * 根据 KeyboardEvent 生成 Android 平台下的按键数据
10
13
  * @param event - 浏览器的 KeyboardEvent 对象
@@ -0,0 +1,20 @@
1
+ export declare enum LogLevel {
2
+ DEBUG = 10,
3
+ INFO = 20,
4
+ WARN = 30,
5
+ ERROR = 40,
6
+ OFF = 100
7
+ }
8
+ export declare function setLogLevel(level: LogLevel): void;
9
+ export declare function enableLog(enable: boolean): void;
10
+ export declare function setNamespace(ns: string): void;
11
+ declare class LoggerCore {
12
+ private canLog;
13
+ private log;
14
+ debug(...args: any[]): void;
15
+ info(...args: any[]): void;
16
+ warn(...args: any[]): void;
17
+ error(...args: any[]): void;
18
+ }
19
+ export declare const Logger: LoggerCore;
20
+ export {};
@@ -1,16 +1,18 @@
1
1
  export declare class MapCache {
2
2
  private key;
3
3
  private maxSize;
4
- private expire;
4
+ private defaultExpire;
5
5
  constructor(key: string, maxSize?: number, expireMs?: number);
6
- /** 读取 Map(自动清理过期) */
6
+ /** 从 localStorage 读取 Map(自动清理过期的 item) */
7
7
  getMap(): Map<string, any>;
8
- /** 保存 Map(附带时间戳) */
8
+ /** 保存 Map(每个值都有独立的 timestamp/expire) */
9
9
  private saveMap;
10
- /** 设置值(超出 maxSize 删除最早的) */
11
- set(key: string, value: any): void;
12
- /** 获取值(过期自动清空) */
10
+ /** 设置值(支持单项自定义过期时间) */
11
+ set(key: string, value: any, expireMs?: number): void;
12
+ /** 获取值(单项过期会自动清除) */
13
13
  get(key: string): any;
14
+ /** 检查是否存在且未过期 */
15
+ has(key: string): boolean;
14
16
  /** 删除 */
15
17
  delete(key: string): void;
16
18
  /** 清空 */
@@ -1,5 +1,5 @@
1
- import type { TurnSelectionResult, TurnServerConfig, TurnTestResult, TurnTestSummary } from "../data/TurnType.ts";
2
- import type { WebRTCConfigOptions } from "../rtc/WebRTCConfig.ts";
1
+ import type { TurnSelectionResult, TurnServerConfig, TurnTestResult, TurnTestSummary } from '../data/TurnType.ts';
2
+ import type { WebRTCConfigOptions } from '../rtc/WebRTCConfig.ts';
3
3
  export declare const testTurnServer: (turnConfig: TurnServerConfig, timeoutMs?: number) => Promise<TurnTestResult>;
4
4
  export declare const testMultipleTurnServers: (servers: string[], timeoutMs?: number) => Promise<TurnTestSummary>;
5
5
  export declare const areTurnListsEmpty: (options: WebRTCConfigOptions) => boolean;
package/lib/index.d.ts CHANGED
@@ -5,7 +5,8 @@ import { transformCoordinate, valueToPercentage } from "./core/util/ScreenContro
5
5
  import { ActionType, ChannelDataType, ContainerDirection, InputData, KeyEventData, TouchData, WheelData, GestureData, type ActionCommand, ActionCommandType, ActionCommandEventType, ActionCommandEventValue, TrackEventData, ClarityData } from "./core/data/WebrtcDataType";
6
6
  import { type TurnServerConfig, type TurnTestResult, type TurnTestSummary } from "./core/data/TurnType";
7
7
  import type { WebRTCConfigOptions } from './core/rtc/WebRTCConfig';
8
- import { GroupControllerManager } from "./core/groupctrl/GroupControllerManager";
9
8
  import { EmitType, type CameraError, type WebRtcError } from "./core/data/WebRtcError";
10
9
  import RemotePlayer from './components/RemotePlayer/index.vue';
11
- export { WebRTCSdk, getKeyEventData, transformCoordinate, valueToPercentage, ActionType, ChannelDataType, InputData, KeyEventData, TouchData, ContainerDirection, EmitType, WheelData, GestureData, ClarityData, type ActionCommand, ActionCommandType, GroupControllerManager, type WebRTCConfigOptions, ActionCommandEventType, ActionCommandEventValue, RemotePlayer, TrackEventData, type TurnServerConfig, type TurnTestResult, type TurnTestSummary, testMultipleTurnServers, type CameraError, type WebRtcError };
10
+ import { ConnectorType } from './core/data/MessageType';
11
+ import { GroupCtrlSocketManager } from './core/groupctrl/GroupCtrlSocketManager';
12
+ export { WebRTCSdk, getKeyEventData, transformCoordinate, valueToPercentage, ActionType, ChannelDataType, InputData, KeyEventData, TouchData, ContainerDirection, EmitType, WheelData, GestureData, ClarityData, type ActionCommand, ActionCommandType, type WebRTCConfigOptions, ActionCommandEventType, ActionCommandEventValue, RemotePlayer, TrackEventData, type TurnServerConfig, type TurnTestResult, type TurnTestSummary, testMultipleTurnServers, type CameraError, type WebRtcError, ConnectorType, GroupCtrlSocketManager };