yjz-web-sdk 1.0.7-beta.2 → 1.0.8-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.
- package/lib/core/WebRTCSdk.d.ts +20 -3
- package/lib/core/data/TurnType.d.ts +21 -0
- package/lib/core/data/WebRtcError.d.ts +15 -2
- package/lib/core/data/WebrtcDataType.d.ts +3 -2
- package/lib/core/groupctrl/GroupControllerManager.d.ts +1 -7
- package/lib/core/rtc/WebRTCClient.d.ts +19 -0
- package/lib/core/rtc/WebRTCConfig.d.ts +10 -1
- package/lib/core/rtc/WebRtcNegotiate.d.ts +2 -1
- package/lib/core/signal/SignalingClient.d.ts +3 -0
- package/lib/core/util/FileTypeUtils.d.ts +5 -0
- package/lib/core/util/KeyCodeUtil.d.ts +1 -4
- package/lib/core/util/MapCache.d.ts +18 -0
- package/lib/core/util/TurnTestUtil.d.ts +6 -0
- package/lib/index.d.ts +5 -3
- package/lib/yjz-web-sdk.js +835 -178
- package/lib/yjz-web-sdk.umd.cjs +57 -43
- package/package.json +1 -1
- package/lib/core/groupctrl/LoopManager.d.ts +0 -8
- package/lib/core/groupctrl/VisibilityManager.d.ts +0 -17
package/lib/core/WebRTCSdk.d.ts
CHANGED
|
@@ -5,17 +5,33 @@ import { WebRTCConfig } from "./rtc/WebRTCConfig.ts";
|
|
|
5
5
|
import type { WebRTCConfigOptions } from './rtc/WebRTCConfig';
|
|
6
6
|
import { ChannelDataType } from "./data/WebrtcDataType.ts";
|
|
7
7
|
export declare class WebRTCSdk extends EventEmitter {
|
|
8
|
-
config: WebRTCConfig;
|
|
9
|
-
signalingClient: SignalingClient;
|
|
10
|
-
webRTCClient: WebRTCClient;
|
|
8
|
+
config: WebRTCConfig | null;
|
|
9
|
+
signalingClient: SignalingClient | null;
|
|
10
|
+
webRTCClient: WebRTCClient | null;
|
|
11
|
+
options: WebRTCConfigOptions;
|
|
12
|
+
isConnected: boolean;
|
|
13
|
+
isConnecting: boolean;
|
|
14
|
+
private connectCount;
|
|
15
|
+
private MAX_COUNT;
|
|
16
|
+
private timeout;
|
|
17
|
+
private cache;
|
|
11
18
|
constructor(options: WebRTCConfigOptions);
|
|
19
|
+
initConfig(): Promise<void>;
|
|
12
20
|
/** 开始连接 signal 服务 */
|
|
13
21
|
startConnection(): void;
|
|
22
|
+
private prepareConnection;
|
|
23
|
+
reconnect(): Promise<void>;
|
|
24
|
+
initConnectConfig(): void;
|
|
25
|
+
initSignalingClient(): void;
|
|
14
26
|
switchControl(isControl: boolean): void;
|
|
27
|
+
resetConfig(): void;
|
|
15
28
|
/** 停止连接,并发送退出信令 */
|
|
16
29
|
stop(): void;
|
|
17
30
|
/** 开始推流:触发媒体采集与轨道添加 */
|
|
18
31
|
startPush(): Promise<void>;
|
|
32
|
+
startPushLocal(file: File): Promise<void>;
|
|
33
|
+
stopPush(): void;
|
|
34
|
+
stopPushLocal(): void;
|
|
19
35
|
/** 发送信道数据 */
|
|
20
36
|
sendChannelData(type: ChannelDataType, data: any): void;
|
|
21
37
|
sendControlEvent(key: number): void;
|
|
@@ -25,6 +41,7 @@ export declare class WebRTCSdk extends EventEmitter {
|
|
|
25
41
|
* @param message 信令消息
|
|
26
42
|
*/
|
|
27
43
|
private handleSignaling;
|
|
44
|
+
clearTimer: () => void;
|
|
28
45
|
/** 发送 Offer 信令 */
|
|
29
46
|
sendOffer: (offerSdp: string) => void;
|
|
30
47
|
/** 发送 Answer 信令 */
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type TurnServerConfig = {
|
|
2
|
+
urls: string;
|
|
3
|
+
username?: string;
|
|
4
|
+
credential?: string;
|
|
5
|
+
};
|
|
6
|
+
export interface TurnTestResult extends TurnServerConfig {
|
|
7
|
+
rtt: number;
|
|
8
|
+
}
|
|
9
|
+
export type PublicTurnTestResult = {
|
|
10
|
+
urls: string;
|
|
11
|
+
rtt: number;
|
|
12
|
+
};
|
|
13
|
+
export type TurnTestSummary = {
|
|
14
|
+
best?: PublicTurnTestResult;
|
|
15
|
+
all: PublicTurnTestResult[];
|
|
16
|
+
};
|
|
17
|
+
export interface TurnSelectionResult {
|
|
18
|
+
url?: string;
|
|
19
|
+
rtt?: number;
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
@@ -14,7 +14,9 @@ export declare enum FailCode {
|
|
|
14
14
|
DATACHANNEL_ERR = 10013,
|
|
15
15
|
STREAM_STATE = 10014,
|
|
16
16
|
AUTH_FAILED = 10015,
|
|
17
|
-
KICK_OUT_ERR = 10016
|
|
17
|
+
KICK_OUT_ERR = 10016,
|
|
18
|
+
STATE_ERR = 10017,
|
|
19
|
+
OPTION_ERR = 10018
|
|
18
20
|
}
|
|
19
21
|
export declare const FailInfoMap: Record<FailCode, {
|
|
20
22
|
type: string;
|
|
@@ -26,10 +28,20 @@ export interface WebRtcError {
|
|
|
26
28
|
message: string;
|
|
27
29
|
rawError?: any;
|
|
28
30
|
}
|
|
31
|
+
export declare enum CameraFailCode {
|
|
32
|
+
LOCAL_STREAM_FAIL = 20001,
|
|
33
|
+
CAMERA_STREAM_FAIL = 20002
|
|
34
|
+
}
|
|
29
35
|
export declare function createWebRtcError(code: FailCode, rawError?: any): WebRtcError;
|
|
36
|
+
export declare function createCameraError(code: CameraFailCode, message: string): CameraError;
|
|
37
|
+
export interface CameraError {
|
|
38
|
+
code: CameraFailCode;
|
|
39
|
+
message: string;
|
|
40
|
+
}
|
|
30
41
|
export declare enum EmitType {
|
|
31
42
|
signalMessage = "signalMessage",
|
|
32
43
|
webrtcError = "webrtcError",
|
|
44
|
+
cameraError = "cameraError",
|
|
33
45
|
sendAnswer = "sendAnswer",
|
|
34
46
|
sendOffer = "sendOffer",
|
|
35
47
|
sendICEMessage = "sendICEMessage",
|
|
@@ -39,5 +51,6 @@ export declare enum EmitType {
|
|
|
39
51
|
statisticInfo = "statisticInfo",
|
|
40
52
|
cloudClipData = "cloudClipData",
|
|
41
53
|
screenshot = "screenshot",
|
|
42
|
-
groupError = "groupError"
|
|
54
|
+
groupError = "groupError",
|
|
55
|
+
reconnect = "reconnect"
|
|
43
56
|
}
|
|
@@ -120,7 +120,8 @@ export declare class ClarityData {
|
|
|
120
120
|
export declare class ChannelData {
|
|
121
121
|
type: ChannelDataType;
|
|
122
122
|
data: string | null;
|
|
123
|
-
|
|
123
|
+
myId: string | null;
|
|
124
|
+
constructor(type: ChannelDataType, data?: string | null, myId?: string | null);
|
|
124
125
|
toString(): string;
|
|
125
126
|
/**
|
|
126
127
|
* 格式化数据
|
|
@@ -144,7 +145,7 @@ export declare class ChannelData {
|
|
|
144
145
|
* 生成输入数据
|
|
145
146
|
* @param data 输入数据对象
|
|
146
147
|
*/
|
|
147
|
-
static input(data: any): ChannelData;
|
|
148
|
+
static input(data: any, myId: string): ChannelData;
|
|
148
149
|
/**
|
|
149
150
|
* 生成鼠标滚动数据
|
|
150
151
|
* @param data 输入数据对象
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { EventEmitter } from "eventemitter3";
|
|
2
2
|
import type { WebRTCConfigOptions } from "../rtc/WebRTCConfig.ts";
|
|
3
|
-
import { VisibilityManager } from "./VisibilityManager.ts";
|
|
4
3
|
import { SdkController } from "./SdkController.ts";
|
|
5
4
|
import { type ChannelDataType } from "../data/WebrtcDataType.ts";
|
|
6
5
|
export declare class GroupControllerManager extends EventEmitter {
|
|
7
6
|
private configs;
|
|
8
7
|
private controllers;
|
|
9
|
-
|
|
10
|
-
private loopManager;
|
|
11
|
-
constructor(interval?: number, visibility?: VisibilityManager);
|
|
8
|
+
constructor();
|
|
12
9
|
startControl(configMap: Map<string, WebRTCConfigOptions>): void;
|
|
13
10
|
switchToMain(newRoomId: string, oldRoomId: string): void;
|
|
14
11
|
switchControl(roomId: string, isControl: boolean): void;
|
|
@@ -27,9 +24,6 @@ export declare class GroupControllerManager extends EventEmitter {
|
|
|
27
24
|
getController(roomId: string): SdkController | undefined;
|
|
28
25
|
refreshController(roomId: string): void;
|
|
29
26
|
updateProperty<K extends keyof WebRTCConfigOptions>(roomId: string, key: K, value: WebRTCConfigOptions[K]): void;
|
|
30
|
-
setVisibility(viewId: string, visible: boolean): void;
|
|
31
|
-
setViewIds(viewIds: string[], visible: boolean): void;
|
|
32
27
|
sendData(type: ChannelDataType, data: any): void;
|
|
33
28
|
sendControlEvent(key: number): void;
|
|
34
|
-
private handleLoop;
|
|
35
29
|
}
|
|
@@ -5,7 +5,9 @@ export declare class WebRTCClient extends EventEmitter {
|
|
|
5
5
|
private readonly config;
|
|
6
6
|
private peerConnection;
|
|
7
7
|
private localStream;
|
|
8
|
+
private rotatedStream;
|
|
8
9
|
private isPushingStream;
|
|
10
|
+
private isPushingLocalStream;
|
|
9
11
|
private dataChannel;
|
|
10
12
|
private statsTimer;
|
|
11
13
|
private lastReportTime;
|
|
@@ -15,6 +17,13 @@ export declare class WebRTCClient extends EventEmitter {
|
|
|
15
17
|
private lostPacketCount;
|
|
16
18
|
private maxLostRate;
|
|
17
19
|
private lastSecondDecodedCount;
|
|
20
|
+
private fileVideo?;
|
|
21
|
+
private canvas?;
|
|
22
|
+
private canvasStream;
|
|
23
|
+
private rafId;
|
|
24
|
+
private currentMedia;
|
|
25
|
+
private fileImage?;
|
|
26
|
+
private ua;
|
|
18
27
|
constructor(config: WebRTCConfig);
|
|
19
28
|
startPush(): Promise<void>;
|
|
20
29
|
handleOffer(offerSdp: string): void;
|
|
@@ -32,4 +41,14 @@ export declare class WebRTCClient extends EventEmitter {
|
|
|
32
41
|
private checkStats;
|
|
33
42
|
private processStats;
|
|
34
43
|
private getConnectionType;
|
|
44
|
+
/** 获取或创建 video 元素(懒初始化) */
|
|
45
|
+
private getFileVideo;
|
|
46
|
+
/** 获取或创建 canvas 元素(懒初始化) */
|
|
47
|
+
private getCanvas;
|
|
48
|
+
loadMedia(file: File): Promise<void>;
|
|
49
|
+
startPushLocal: (file: File) => Promise<void>;
|
|
50
|
+
startCanvasStream(fps?: number): MediaStream;
|
|
51
|
+
getFileImage(): HTMLImageElement;
|
|
52
|
+
/** 停止推流并释放资源 */
|
|
53
|
+
stopLocal(): void;
|
|
35
54
|
}
|
|
@@ -6,7 +6,7 @@ export interface WebRTCConfigOptions {
|
|
|
6
6
|
stunServerUri?: string;
|
|
7
7
|
stunServerUriAli?: string;
|
|
8
8
|
stunServerUriTel?: string;
|
|
9
|
-
turnServerUri
|
|
9
|
+
turnServerUri?: string;
|
|
10
10
|
turnServerUserName?: string;
|
|
11
11
|
turnServerPassword?: string;
|
|
12
12
|
isControl: boolean;
|
|
@@ -19,6 +19,13 @@ export interface WebRTCConfigOptions {
|
|
|
19
19
|
cloudName?: string;
|
|
20
20
|
token: string;
|
|
21
21
|
isGroup: boolean;
|
|
22
|
+
turnKey?: Array<string>;
|
|
23
|
+
hostTurn?: Array<string>;
|
|
24
|
+
spareTurn?: Array<string>;
|
|
25
|
+
maxRecount?: number;
|
|
26
|
+
isCalculate?: boolean;
|
|
27
|
+
traceId?: string;
|
|
28
|
+
signAgain?: boolean;
|
|
22
29
|
}
|
|
23
30
|
export declare class WebRTCConfig {
|
|
24
31
|
signalServerUrl: string;
|
|
@@ -37,5 +44,7 @@ export declare class WebRTCConfig {
|
|
|
37
44
|
screenshotQuality: number;
|
|
38
45
|
token: string;
|
|
39
46
|
isGroup: boolean;
|
|
47
|
+
turnKey: Array<string>;
|
|
48
|
+
traceId: string;
|
|
40
49
|
constructor(options: WebRTCConfigOptions);
|
|
41
50
|
}
|
|
@@ -4,5 +4,6 @@ export declare const setRemoteDescriptionWithHandleOffer: (peerConnection: RTCPe
|
|
|
4
4
|
export declare const createPeerConnection: (config: WebRTCConfig) => RTCPeerConnection;
|
|
5
5
|
export declare const configPeerConnection: (peerConnection: RTCPeerConnection, onICEMessage: (candidate: string) => void, onTrack?: (track: MediaStreamTrack) => void, onConnectState?: (state: RTCIceConnectionState) => void, onError?: (error: WebRtcError) => void) => void;
|
|
6
6
|
export declare const setRemoteDescriptionWithHandleAnswer: (peerConnection: RTCPeerConnection, sdp: string, onError?: (error: WebRtcError) => void) => void;
|
|
7
|
-
export declare const createOffer: (peerConnection: RTCPeerConnection, sendOfferMessage: (sdp: string) => void
|
|
7
|
+
export declare const createOffer: (peerConnection: RTCPeerConnection, sendOfferMessage: (sdp: string) => void) => Promise<void>;
|
|
8
|
+
export declare const setLocalDescriptionWithCreateOffer: (peerConnection: RTCPeerConnection, offer: RTCSessionDescriptionInit, sendOfferMessage: (sdp: string) => void) => Promise<void>;
|
|
8
9
|
export declare const addIceCandidate: (peerConnection: RTCPeerConnection, candidate: RTCIceCandidateInit, onError?: (error: WebRtcError) => void) => void;
|
|
@@ -3,11 +3,14 @@ import type { WebRTCConfig } from "../rtc/WebRTCConfig.ts";
|
|
|
3
3
|
export declare class SignalingClient extends EventEmitter {
|
|
4
4
|
private config;
|
|
5
5
|
private webSocket;
|
|
6
|
+
private timeout;
|
|
6
7
|
constructor(config: WebRTCConfig);
|
|
7
8
|
/**
|
|
8
9
|
* 启动 WebSocket 连接,并注册各事件处理
|
|
9
10
|
*/
|
|
10
11
|
start(): void;
|
|
12
|
+
timeStart(): void;
|
|
13
|
+
clearTime(): void;
|
|
11
14
|
/**
|
|
12
15
|
* 关闭 WebSocket 连接,并通知外部
|
|
13
16
|
*/
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
+
import { KeyEventData } from "../data/WebrtcDataType.ts";
|
|
1
2
|
/**
|
|
2
3
|
* 根据浏览器 KeyboardEvent 计算 Android 平台的 meta 状态值
|
|
3
4
|
* @param event - 浏览器的 KeyboardEvent
|
|
4
5
|
* @returns 计算后的 meta 状态
|
|
5
6
|
*/
|
|
6
7
|
export declare const computeAndroidMetaState: (event: KeyboardEvent) => number;
|
|
7
|
-
export interface KeyEventData {
|
|
8
|
-
keyCode: number;
|
|
9
|
-
meta: number;
|
|
10
|
-
}
|
|
11
8
|
/**
|
|
12
9
|
* 根据 KeyboardEvent 生成 Android 平台下的按键数据
|
|
13
10
|
* @param event - 浏览器的 KeyboardEvent 对象
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class MapCache {
|
|
2
|
+
private key;
|
|
3
|
+
private maxSize;
|
|
4
|
+
private expire;
|
|
5
|
+
constructor(key: string, maxSize?: number, expireMs?: number);
|
|
6
|
+
/** 读取 Map(自动清理过期) */
|
|
7
|
+
getMap(): Map<string, any>;
|
|
8
|
+
/** 保存 Map(附带时间戳) */
|
|
9
|
+
private saveMap;
|
|
10
|
+
/** 设置值(超出 maxSize 删除最早的) */
|
|
11
|
+
set(key: string, value: any): void;
|
|
12
|
+
/** 获取值(过期自动清空) */
|
|
13
|
+
get(key: string): any;
|
|
14
|
+
/** 删除 */
|
|
15
|
+
delete(key: string): void;
|
|
16
|
+
/** 清空 */
|
|
17
|
+
clear(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TurnSelectionResult, TurnServerConfig, TurnTestResult, TurnTestSummary } from "../data/TurnType.ts";
|
|
2
|
+
import type { WebRTCConfigOptions } from "../rtc/WebRTCConfig.ts";
|
|
3
|
+
export declare const testTurnServer: (turnConfig: TurnServerConfig, timeoutMs?: number) => Promise<TurnTestResult>;
|
|
4
|
+
export declare const testMultipleTurnServers: (servers: string[], timeoutMs?: number) => Promise<TurnTestSummary>;
|
|
5
|
+
export declare const areTurnListsEmpty: (options: WebRTCConfigOptions) => boolean;
|
|
6
|
+
export declare const selectBestTurnServer: (turnList: string[]) => Promise<TurnSelectionResult>;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { WebRTCSdk } from './core/WebRTCSdk';
|
|
2
2
|
import { getKeyEventData } from "./core/util/KeyCodeUtil";
|
|
3
|
+
import { testMultipleTurnServers } from './core/util/TurnTestUtil';
|
|
3
4
|
import { transformCoordinate, valueToPercentage } from "./core/util/ScreenControlUtil";
|
|
4
5
|
import { ActionType, ChannelDataType, ContainerDirection, InputData, KeyEventData, TouchData, WheelData, GestureData, type ActionCommand, ActionCommandType, ActionCommandEventType, ActionCommandEventValue, TrackEventData, ClarityData } from "./core/data/WebrtcDataType";
|
|
6
|
+
import { type TurnServerConfig, type TurnTestResult, type TurnTestSummary } from "./core/data/TurnType";
|
|
5
7
|
import type { WebRTCConfigOptions } from './core/rtc/WebRTCConfig';
|
|
6
|
-
import { GroupControllerManager } from "./core/groupctrl/GroupControllerManager
|
|
7
|
-
import { EmitType } from "./core/data/WebRtcError";
|
|
8
|
+
import { GroupControllerManager } from "./core/groupctrl/GroupControllerManager";
|
|
9
|
+
import { EmitType, type CameraError, type WebRtcError } from "./core/data/WebRtcError";
|
|
8
10
|
import RemotePlayer from './components/RemotePlayer/index.vue';
|
|
9
|
-
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 };
|
|
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 };
|