


import { genTestUserSig } from '@/utils/generateTestUserSig';
export default {
    namespaced: true,
    state() {
        return {
            socket: null,
            showdaogou: false,
            sdkAppId: "1400685498",
            userId: '',
            roomId: '',
            role:'',
            secretKey: '7500f8938c46c5d3c64621ae7826905eec9723bf218fbcf121242e056a4ee14f',
            userSig: 'eJwtzcsOgjAQBdB-6RaDU2jLI3EhsrHRBdGNK2Po0IyvNAWJxvjvEmA5597c*bLj7hD26FnOohDYYrzJ4LOjhkZ*tejPd7wY9EJwnsV8brXmdnGODMu5AEggExBNSUcPHFQpnkopIJkU34784ApECjBvkB1e8MLJfWyLOAis06Wut4b0tVdL77RVTb35dGXby6o6rVfs9wdhLDRy',
            audioDeviceId: '',
            videoDeviceId: '',
            cameraList: [],
            microphoneList: [],
            logs: [],
            isJoined: false,
            isPublished: false,
            isShared: false,
            remoteStreams: [],
            invitedRemoteStreams: [],
            avatar:null,
        }
    },
    getters: {
        avatar: state => {
            if(state.role == 'leader' || window.location.search.indexOf('sync=1')!=-1){
                return state.avatar || localStorage.getItem('leaderAvatar') || ''
            }
            return state.avatar
            
        },
        socket: state => {
            return state.socket
        },
        showdaogou: state => {
            return state.showdaogou
        },
        userSig: state => {
            const { userSig } = genTestUserSig({
                sdkAppId: parseInt(state.sdkAppId, 10),
                userId:state.userId,
                secretKey: state.secretKey,
            });
            return userSig
        },
        sdkAppId: state => state.sdkAppId,
        role: state => state.role,
        userId: state => state.userId,
        roomId: state => state.roomId,
        secretKey: state => state.secretKey,
        audioDeviceId: state => state.audioDeviceId,
        videoDeviceId: state => state.videoDeviceId,
        cameraList: state => state.cameraList,
        microphoneList: state => state.microphoneList,
        logs: state => state.logs,
        isJoined: state => state.isJoined,
        isPublished: state => state.isPublished,
        isShared: state => state.isShared,
        remoteStreams: state => state.remoteStreams,
        invitedRemoteStreams: state => state.invitedRemoteStreams
    },
    mutations: {
        setAvatar(state, payload) {
            state.avatar = payload
            localStorage.setItem('leaderAvatar',payload || '')
        },
        setSocket(state, payload) {
            state.socket = payload
        },
        setShowdaogou(state, payload) {
            state.showdaogou = payload
        },

        setUserId(state, payload) {
            state.userId=payload
        },

        setRoomId(state, payload) {
            state.roomId=payload
        },
        setRole(state, payload) {
            state.role=payload
        },

        setDeviceList(state, payload) {
            state.cameraList=payload.cameraItems
            state.microphoneList=payload.microphoneItems
        },

        setVideoDeviceId(state, payload) {
            state.videoDeviceId=payload
        },

        setAudioDeviceId(state, payload) {
            state.audioDeviceId=payload
        },

        setIsJoined(state, payload){
            state.isJoined = payload
        },
        setIsPublished(state, payload){
            state.isPublished = payload
        },
       
    
        // createShareLink(state, payload) {
        //     const userId = `Guest_${Math.floor(Math.random() * 1000000)}`;
        //     const { userSig } = genTestUserSig({
        //         sdkAppId: parseInt(state.sdkAppId, 10),
        //         userId,
        //         secretKey: state.secretKey,
        //     });
        //     const { origin } = window.location;
        //     const { pathname } = window.location;
        //     return `${origin}${pathname}#/invite?userSig=${userSig}&&SDKAppId=${state.sdkAppId}&&userId=${userId}&&roomId=${state.roomId}`;
        // },
        
    },
    actions: {
      
    },
}
