import { defineStore } from "pinia"; import { MSG_TYPE, MESSAGE_TYPE_USER, MESSAGE_TYPE_GROUP, } from "@/common/constant/msgType"; import { useWebSocketStore } from "@/stores/modules/webSocketStore"; import * as Constant from "@/common/constant/Constant"; export const useWebRTCStore = defineStore("webrtc", { state: () => ({ // WebRTC 连接实例 peerConnection: null, // ICE 候选信息 iceCandidates: [], pendingIceCandidates: [], // 缓存未处理的候选 // 连接状态 connectionState: "disconnected", // 媒体流 localStream: null, // 本地媒体流 remoteStream: null, // 远端媒体流 streamType: "audio", //"audio", // 视频元素引用 localVideoElement: null, remoteVideoElement: null, // 媒体控制状态 isVideoEnabled: true, isAudioEnabled: true, // 通话类型 callType: "audio", // 'audio' 或 'video' // 是否是发起方 isCaller: false, // 配置项 config: { iceServers: [ { urls: "stun:stun.l.google.com:19302" }, // 可以添加更多 STUN/TURN 服务器 ], }, imSate: { videoCallModal: false, // 视频通话模态框 callName: "", // 通话对象名称 fromUserUuid: "", // 通话对象 uuid }, }), actions: { // bindRemoteAudio() { // video && audio // 如果已经存在 audio 元素,先移除旧的 const oldAudio = document.getElementById(`remote-audio`); if (oldAudio) { oldAudio.remove(); } // 创建新的