import consolaGlobalInstance from "consola";
import { getApp } from "/@/hooks/userApp";
import { useRoom } from "/@/hooks/useRoom";
import { useSocket } from "/@/hooks/userSocket";
import { UserInfoType, useRtcStore } from "/@/store/modules/rtc";
const { enterRoom } = useRoom()

// 自已join的方法
export function handleJoin(data: any) {
    const app = getApp();
    const socket = useSocket()
    enterRoom();
    const rtcStore = useRtcStore();
    rtcStore.setIsJoined(true)
    consolaGlobalInstance.info({
        message: data,
        tag: "socket:enter"
    })
    const members = data?.members as any as UserInfoType[]
    members && rtcStore.setMemberList(members)
    if (!rtcStore.isLeader) {
        setTimeout(() => {
            socket.emit("action", {
                type: "user-init",
            });
        }, 1500);
    }



}