import * as _vueuse_core0 from "@vueuse/core"; import * as vue from "vue"; //#region src/use-web-rtc.d.ts /** * WebRTC 配置选项 * 继承自 RTCConfiguration,支持自定义 WebSocket 协议 */ type WebRTCOptions = RTCConfiguration & { /** * WebSocket 子协议列表,用于指定连接时使用的协议 */ protocols?: string[]; }; /** * WebRTC 连接状态 * - pending: 初始状态,等待注册 * - ready: 已注册,可以发起连接 * - connected: 已建立连接 * - closed: 连接已关闭 */ type Status = 'pending' | 'ready' | 'connected' | 'closed'; /** * WebSocket 信令消息类型定义 * 用于 WebRTC 连接建立过程中的信令交换 */ type HandleEvent = { /** * 注册消息:服务器分配唯一标识符 */ 'register': { payload: { /** * 分配给客户端的唯一标识符 */ key: string; }; }; /** * Offer 消息:发起连接请求 */ 'offer': { payload: { /** * 目标客户端标识符 */ key: string; /** * SDP offer 描述 */ desc: RTCSessionDescriptionInit; }; }; /** * Answer 消息:响应连接请求 */ 'answer': { payload: { /** * 发起方客户端标识符 */ key: string; /** * SDP answer 描述 */ desc: RTCSessionDescriptionInit; }; }; /** * Answer-ok 消息:确认 answer 已接收 */ 'answer-ok': { payload: { /** * 目标客户端标识符 */ key: string; }; }; /** * ICE candidate 消息:交换网络候选地址 */ 'ice-candidate': { payload: { /** * ICE 候选者信息 */ candidate: RTCIceCandidate; }; }; }; /** * WebRTC 连接管理 Composable * * 提供完整的 WebRTC 连接管理功能,包括: * - 通过 WebSocket 进行信令交换 * - 支持数据通道和媒体流连接 * - 实时状态监控和事件通知 * - 自动清理和资源释放 * * @param url WebSocket 信令服务器地址 * @param options WebRTC 配置选项,继承 RTCConfiguration * @returns WebRTC 连接管理对象 * * @example * ```ts * const { connect, onConnection, status } = useWebRTC('ws://localhost:8080') * * onConnection((event) => { * const channel = event.channel * channel.onmessage = (e) => console.log('收到消息:', e.data) * }) * * const dataChannel = await connect('remote-peer-id', 'chat-channel') * dataChannel.send('Hello!') * ``` * * @example * ```ts * const { connectStream, onConnectionStream, status } = useWebRTC('ws://localhost:8080') * * const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true }) * await connectStream('remote-peer-id', stream) * * onConnectionStream((event) => { * const remoteStream = event.streams[0] * videoElement.srcObject = remoteStream * }) * ``` * * @example * ```ts * const { connect, status } = useWebRTC('ws://localhost:8080', { * iceServers: [ * { urls: 'stun:stun.l.google.com:19302' }, * { * urls: 'turn:your-turn-server.com:3478', * username: 'username', * credential: 'password' * } * ], * iceTransportPolicy: 'relay' * }) * ``` */ declare function useWebRTC(url: string | URL, options?: WebRTCOptions): { id: vue.Ref; connected: vue.Ref; status: vue.Ref; peer: RTCPeerConnection; signalingState: vue.Ref; connectionState: vue.Ref; connect: (id: string, label?: string) => Promise; connectStream: (id: string, stream: MediaStream) => Promise; onReady: _vueuse_core0.EventHookOn; onConnection: _vueuse_core0.EventHookOn; onConnectionStream: _vueuse_core0.EventHookOn; }; /** * useWebRTC 函数的返回类型 */ type UseWebRTCReturns = ReturnType; //#endregion export { HandleEvent, Status, UseWebRTCReturns, WebRTCOptions, useWebRTC };