import { defineStore } from 'pinia' export interface IState { peerId: string | undefined isBusy: boolean isClose: boolean isAccept:boolean callId: string | undefined offer: string | undefined answer: string | undefined candidate: string | undefined users: string | undefined } export const usePeerStore = defineStore({ id: 'peer_store', state(): IState { return { /** * 自己的peerid */ peerId: undefined, /** * 是否已经在通话 */ isBusy: false, /** * 是否接受邀请 */ isAccept: false, /** * 是否收到关闭通话的消息 */ isClose: false, /** * 被呼叫的id */ callId: undefined, /** * offer数据 */ offer:undefined, /** * answer数据 */ answer:undefined, /** * candidate数据 */ candidate:undefined, /** * users数据 通话用户列表[1,2,3,4] */ users:undefined } }, getters: { getIsClose(): boolean { return this.isClose } }, actions: { setPeerId(peerId: string) { this.peerId = peerId }, setIsAccept(isAccept: boolean) { // console.log('setIsAccept',this.isAccept,isAccept); this.isAccept = isAccept }, setCallId(callId: string|undefined) { this.callId = callId }, setOffer(offer: string|undefined) { this.offer = offer }, setAnswer(answer: string|undefined) { this.answer = answer }, setCandidate(candidate: string|undefined) { this.candidate = candidate }, setUsers(users: string|undefined) { this.users = users }, updateBusyStatus(isBusy: boolean) { this.isBusy = isBusy }, updateCloseStatus(isClose: boolean) { if (isClose) { this.isBusy = false; } this.isClose = isClose }, closeAll() { this.updateBusyStatus(false) } } })