实现 WebRTC 数据通道管理器的 P2P 和 WS 中继模式支持,添加中继服务以处理 P2P 失败时的降级方案,更新相关接口和状态管理,增强错误处理和消息转发功能。

This commit is contained in:
MatrixSeven
2026-03-02 21:43:11 +08:00
parent 1a6a7369b9
commit ea73a9444f
9 changed files with 843 additions and 97 deletions

View File

@@ -1,5 +1,8 @@
import { create } from 'zustand';
// 传输模式
export type TransportMode = 'p2p' | 'relay';
export interface WebRTCState {
isConnected: boolean;
isConnecting: boolean;
@@ -8,6 +11,8 @@ export interface WebRTCState {
error: string | null;
canRetry: boolean;
currentRoom: { code: string; role: 'sender' | 'receiver' } | null;
// 传输模式p2p 直连 | relay 服务器中继
transportMode: TransportMode;
}
/**
@@ -37,6 +42,7 @@ const initialState: WebRTCState = {
error: null,
canRetry: false,
currentRoom: null,
transportMode: 'p2p',
};
export const useWebRTCStore = create<WebRTCStore>((set) => ({