import { useRtcStore } from '/@/store/modules/rtc'; import type { ChatContentType, UserInfoType } from '/@/store/modules/rtc'; import Dialog from '/@/components/basic/dialog'; import { getApp, useApp } from '/@/hooks/userApp'; import consola from 'consola'; import { useSocket } from '/@/hooks/userSocket'; import { useRoom } from '/@/hooks/useRoom'; interface ActionDataType { type: string; data: any; members?: UserInfoType[]; open?: boolean; user?: UserInfoType; userId?: string; words?: boolean; muted?: boolean; } export function handleActions({ data, type, members, open, user, userId, words, muted, }: ActionDataType) { switch (type) { case 'user-init': handleUserInit(); break; case 'danmumsg': handleDanMumSg(data); break; case 'changeScene': handleChangeScene(data); break; case 'user-join': handleUserJoin(members, user); break; case 'user-leave': break; case 'users-muted': handleUserMuted(userId, muted, members); break; case 'users-words': handleUserSetWords(userId, words, members); break; case 'leader-dismiss': handleUserLeave(user, members); break; case 'user-paint': handleUserPaint(open); break; case 'tagclick': break; case 'tagclose': break; case 'tag-image-index': handleTagImageIndex(data); break; case 'ask-currentscene': handleAskCurrentscene(data); break; case 'error': Dialog.toast({ content: `房间未找到`, type: 'error' }); default: break; } if (members?.length) { console.log('发烧的', members); } } //被动处理初始化 async function handleUserInit() { const rtcStore = useRtcStore(); if (rtcStore.role === 'leader') { const app = await useApp(); app.Connect.follow.sync(); // setTimeout(() => { // socket.value.emit("action", { // type: "leader-avatar", // data: { avatar: leaderAvatar.value }, // }); // if (tagclick.value && tagclick.value.type == "goodlist") { // socket.value.emit("action", { // type: "tagclick", // data: { // sid: tagclick.value.data.sid, // }, // }); // if (tagImageIndex.value != null) { // setTimeout(() => { // socket.value.emit("action", { // type: "tag-image-index", // data: { // index: tagImageIndex.value, // }, // }); // }, 200); // } // } // }, 200); } } // 被动处理弹幕 function handleDanMumSg(data: ChatContentType) { const rtcStore = useRtcStore(); if (data.role == 'leader') { data.Nickname = '主持人'; } rtcStore.addToChatList(data); } // 其他用户进入 function handleUserJoin(members?: UserInfoType[], user?: UserInfoType) { consola.info({ tag: 'socket', message: '有人进来了', }); const rtcStore = useRtcStore(); members && rtcStore.setMemberList(members); if (user) { let name = user.Nickname; if (user.Role === 'leader') { const { socket } = useSocket(); name = '主持人'; Dialog.toast({ content: `主持人进入房间` }); socket.emit('action', { type: 'user-init' }); } const data: ChatContentType = { role: user?.Role, mode: rtcStore.mode, Nickname: name, UserId: user?.UserId, text: '进入房间', }; if (rtcStore.isLeader) { rtcStore.addToChatList(data); } } } // 其他用户开起画笔通知 async function handleUserPaint(open: boolean | undefined) { const app = await useApp(); const rtcStore = useRtcStore(); if (!rtcStore.isLeader) { if (open) { console.log(open); app.Connect.paint.show({ role: rtcStore.role, paint: false, }); Dialog.toast({ content: `主持人开启画笔` }); } else { Dialog.toast({ content: `主持人关闭画笔` }); app.Connect.paint.hide(); } } } const handleChangeScene = (data) => { const { changeScene } = useRoom(); // debugger changeScene(data); }; // const handleAskCurrentscene = (data) => {}; const handleTagImageIndex = (data) => {}; const handleUserSetWords = (UserId?: string, words?: boolean, members?: UserInfoType[]) => { const rtcStore = useRtcStore(); console.log('handleUserSetWords', UserId, words); UserId && rtcStore.updateMemberDatabyId(UserId, { IsWords: words, }); if (UserId == rtcStore.userId) { Dialog.toast({ content: !words ? `主持人设置了禁言` : `主持人已解除禁言`, }); } }; const handleUserMuted = (UserId?: string, muted?: boolean, members?: UserInfoType[]) => { const rtcStore = useRtcStore(); console.log('handleUserSetWords', UserId, muted); UserId && rtcStore.updateMemberDatabyId(UserId, { IsMuted: muted, }); if (UserId == rtcStore.userId) { rtcStore.setMute(!!muted); } }; //被动处理用离开 const handleUserLeave = (user, members) => {};