import {AgoraRTMessage} from "$utils/socket/agoraRTM/const/channel";
import {FlatListReload} from "$components/flat-list/const";

export default {

    created(){
        if (this.type === 'audience') {

            this.agoraRTMIM.on(AgoraRTMessage.joinHome,({data})=>{

                if (this.$refs.flat) {
                    if (data.userInfo && data.userInfo.uid && !this.$refs.flat.flat_is_loading()) {
                        this.$refs.flat.flat_push(data.userInfo.uid,data.userInfo);
                    } else {
                        this.$refs.flat.reload(FlatListReload.mustReload);
                    }

                }

            });

            this.agoraRTMIM.on(AgoraRTMessage.leave,(data)=>{
                if (this.$refs.flat) {
                    let uid = parseInt(data);
                    if (uid) {
                        this.$refs.flat.flat_delete(uid);
                    } else {
                        this.$refs.flat.reload(FlatListReload.mustReload);
                    }
                }
            });

        }
    }

}
