/*
* 全局数据管理
* */
import Loger from 'Loger';
import ApeConsts from "apes/ApeConsts";

let loger = Loger.getLoger('GlobalConfig');
import EngineUtils from 'EngineUtils';

class GlobalConfig {
    constructor () {

    }
    _currentStatus=null;

    static getCurrentStatus(){
        if(this._currentStatus==null){
            this._currentStatus=this.statusCode_0;
        }
        return this._currentStatus;
    }
    static setCurrentStatus(_data){
        this._currentStatus=_data;
    }
    static getClassDetail(){
        return  this.classDetail;
    }
    static setClassDetail(_data){
        this.classDetail=_data;
    }
    static getClassInfo (){
            let classInfo={};
            classInfo.siteId= this.siteId;
            classInfo.classId= this.classId;
            classInfo.className=this.className;
            classInfo.h5Module= this.h5Module;
            classInfo.nodeId=this.nodeId;
            classInfo.topNodeID=this.topNodeID;
            classInfo.userRole=this.userRole;
            classInfo.role= this.role;
            classInfo.isHost= this.isHost;
            classInfo.userId= this.userId;
            classInfo.userName= this.userName;
            classInfo.password= this.password;
            classInfo.userType= this.userType;
            classInfo.passwordRequired= this.passwordRequired;
            classInfo.md5=this.md5;
            classInfo.msType= this.msType;
            classInfo.portal= this.portal;
            classInfo.mcuDelay=this.mcuDelay;
            classInfo.MCUServerIP=this.MCUServerIP;
            classInfo.MCUServerPort=this.MCUServerPort;
            classInfo.maxVideoChannels= this.maxVideoChannels;
            classInfo.maxAudioChannels=this.maxAudioChannels;
            classInfo.maxMediaChannels=this.maxMediaChannels;
            classInfo.fps=this.fps;
            classInfo.gop=this.gop;
            classInfo.videoQuality=this.videoQuality;
            classInfo.ssTunnelAppURL = this.ssTunnelAppURL;
            return classInfo;

    }

    //获取当前的课堂状态的信息
    static get classStatusInfo(){
        let classStatusInfo={};

        classStatusInfo.siteId=this.siteId;//站点号

        classStatusInfo.classId=this.classId;
        classStatusInfo.className=this.className;
        classStatusInfo.classType=this.classType;//课堂类型
        classStatusInfo.classStatus=this.classStatus;//课堂的状态
        classStatusInfo.classStartTime=this.classStartTime;//课堂点击开始时间
        classStatusInfo.classStopTime=this.classStopTime;//最后一次停止的时间(点暂停或结束),每次发送数据都获取当前时间戳
        classStatusInfo.classTimestamp=this.classTimestamp;//相对于点开始课堂的时间戳
        classStatusInfo.recordPlaybackMaxTime=this.recordPlaybackMaxTime;//相对于点开始课堂的时间戳

        classStatusInfo.classBeginTime=this.classBeginTime;//课堂创建的时间,这个是Sass返回的
        classStatusInfo.classEndTime=this.classEndTime;//课堂结束的时间,这个是Sass返回的

        classStatusInfo.recordStatus=this.recordStatus;//当前录制状态
        classStatusInfo.recordTimestamp=this.recordTimestamp;//相对于首次开始录制的时间戳
        classStatusInfo.recordFileName=this.recordFileName;//录制的文件名
        classStatusInfo.recordDownloadUrl=this.recordDownloadUrl;//下载地址

        classStatusInfo.serverTimestamp=this.serverTimestamp;//当前的系统时间戳
        classStatusInfo.activeDocId=this.activeDocId;//当前激活的文档ID
        classStatusInfo.activeDocCurPage=this.activeDocCurPage;//当前激活的文档的当前页
        return classStatusInfo;
    }
    //设置当前的课堂状态的信息
    static setClassStatusInfo(_data){
        loger.log("setClassStatusInfo");
        if(_data==null){
            loger.warn("classStatusInfo error,_data:",_data);
            return;
        }
        let data=_data;

        //下列的信息以从Sass获取的最新的为准
        if(!this.siteId){
            this.siteId=data.siteId;//站点号
        }
        if(!this.classId){
            this.classId=data.classId;
        }
        if(!this.className){
            this.className=data.className;
        }

        if(!this.classType){
            this.classType=data.classType;
        }
        if(!this.classBeginTime){
            this.classBeginTime=data.classBeginTime;//课堂创建的时间,这个是Sass返回的
        }
        if(!this.classEndTime){
            this.classEndTime=data.classEndTime;//课堂结束的时间,这个是Sass返回的
        }

        //下面的信息Sass和mcu都会更新
        this.classStatus=data.classStatus||this.classStatus;//课堂的状态
        this.classStartTime=data.classStartTime||this.classStartTime;//课堂点击开始时间
        this.classStopTime=data.classStopTime||this.classStopTime;//最后一次停止的时间(点暂停或结束),每次发送数据都获取当前时间戳
        this.classTimestamp=data.classTimestamp||this.classTimestamp;//相对于点开始课堂的时间戳

        this.recordStatus=data.recordStatus||this.recordStatus;//当前录制状态
        this.recordTimestamp=data.recordTimestamp||this.recordTimestamp;//相对于首次开始录制的时间戳
        this.recordFileName=data.recordFileName||this.recordFileName;//录制的文件名
        this.recordDownloadUrl=data.recordDownloadUrl||this.recordDownloadUrl;//下载地址
    }

    // 判断自己是否主持人角色
     static  get isHost(){
        if(this.userRole ==ApeConsts.host){
            return true;
        }
        return false;
    }

    // 判断自己是否助教角色
     static  get isAssistant()
    {
        if(this.userRole ==ApeConsts.assistant){
            return true;
        }
        return false;
    }

    // 判断自己是否主讲人角色
     static  get isPresenter()
    {
        if(this.userRole ==ApeConsts.presenter){
            return true;
        }
        return false;
    }

    // 判断自己是否普通角色
     static  get isNormal()
    {
        if(this.userRole ==ApeConsts.normal) {
            return true;
        }
        return false;
    }

    // 判断自己是否是隐身用户
     static get isInvisible(){
        if(this.userRole == ApeConsts.invisible){
            return true;
        }
        return false;
    }

    static get serverTimestamp(){
        return EngineUtils.creatTimestamp();
    }
    //储存已经提前上传的文档列表
    static setDocListPrepare(_data){
        if(_data==null) return;
        this.docListPrepare=_data;
    }
    static getDocListPrepare(){
        return this.docListPrepare;
    }
    //储存已经提前上传的媒体共享文件列表
    static setMediaShareList(_data){
        if(_data==null) return;
        this.sharedMediaList=_data;
    }
    static getMediaShareList(){
        return this.sharedMediaList;
    }

    //储存录制列表
    static setRecordList(_data){
        if(_data==null) return;
        this.recordList=_data;
    }
    static getRecordList(){
        return this.recordList;
    }

    //文档服务器列表
    static setDocList(_data){
        if(_data==null) return;
        this.docList=_data;
    }
    static getDocList(){
        return this.docList;
    }
    //ms列表
    static setMsList(_data){
        if(_data==null) return;
        //MSlist列表中的地址需要进行筛选,目前有的站点播流和推流需要分开
        if(GlobalConfig.siteId==GlobalConfig.siteId_letv){
            this.msList=[];
            this.pullRtmpList=[];
            this.hlsList=[];
            let len=_data.length;
            for(let i=0;i<len;i++){
                let item=_data[i];
                if(item&&item.ip){
                    if(item.ip.indexOf('pull.')>=0){
                        this.pullRtmpList.push(item);
                    }else if(item.ip.indexOf('lehls.')>=0){
                        this.hlsList.push(item);
                    }else {
                        this.msList.push(item);
                    }
                }
            }
            loger.log("msListAll->",_data);
            loger.log("msList->",this.msList);
            loger.log("pullList->",this.pullRtmpList);
            loger.log("hlsList->",this.hlsList);
        }else {
            this.msList=_data;
        }
    }
    static getMsList(){
        return this.msList;
    }

    //mcu列表
    static setMcuList(_data){
        if(_data==null) return;
        this.mcuList=_data;
    }
    static getMcuList(){
        return this.mcuList;
    }

    //声音列表
    static setMusicList(_data){
        if(_data==null) return;
        this.musicList=_data;
    }
    static getMusicList(){
        return this.musicList;
    }
    //已经上传的声音列表
    static setMusicListPrepare(_data){
        if(_data==null) return;
        this.musicListPrepare=_data;
    }
    static getMusicListPrepare(){
        return this.musicListPrepare;
    }

    //rs列表
    static setRsList(_data){
        if(_data==null) return;
        this.rsList=_data;
    }
    static getRsList(){
        return this.rsList;
    }

    //CDN加速的 拉流地址 rtmp 和hls(m3u8)
    static setVideoCDNAddr(_data){
        if(_data==null) return;
        //ideoCDNAddr中的地址需要进行筛选,里面包含hls开头和rtmppush开头的地址
        this.videoCDNAddr=_data||'';
        if(this.videoCDNAddr){
            this.videoCDNAddrList=this.videoCDNAddr.split(';');
        }
        loger.log("videoCDNAddrList->",this.videoCDNAddrList);
    }
}

GlobalConfig.statusCode_0={"code":0,message:"SDK 未初始化"};
GlobalConfig.statusCode_1={"code":1,message:"未加入课堂"};
GlobalConfig.statusCode_2={"code":2,message:"已经加入课堂"};
GlobalConfig.statusCode_3={"code":3,message:"已经离开课堂"};
GlobalConfig.statusCode_4={"code":4,message:"未知状态"};

GlobalConfig.screenWidth=1024;
GlobalConfig.screenHeight=768;

GlobalConfig.md5="";
GlobalConfig.msType=1;//目前固定用这个
GlobalConfig.messageDelay=false;//是否启用消息延迟
GlobalConfig.mcuDelay=0;//默认的延迟时间(单位-秒)

GlobalConfig.docDelay=1600;//文档模块加入成功之后延迟发送送成功的消息给主模块(sdk内部使用)
GlobalConfig.portal="112.126.80.182:80";//Sass IP

//GlobalConfig.ip="112.126.80.182";
//GlobalConfig.port="80";

//连接MCU的IP+端口
GlobalConfig.MCUServerIP="";
GlobalConfig.MCUServerPort='';

//推流地址+端口
GlobalConfig.MS_PUBLISH_IP = "";
GlobalConfig.MS_PUBLISH_PORT ="";

//rtmp 拉流地址+端口(rtmp)
GlobalConfig.MS_PLAY_RTMP_IP="";
GlobalConfig.MS_PLAY_RTMP_PORT="";

//HLS 拉流地址+端口 (m3u8)
GlobalConfig.MS_PLAY_HLS_IP="";
GlobalConfig.MS_PLAY_HLS_PORT="";


//录制回放 m3u8播流地址()
GlobalConfig.RS_RECORD_PLAY_IP ="";
GlobalConfig.RS_RECORD_PLAY_PORT ="";

//DOC
GlobalConfig.DOCServerIP ="";
GlobalConfig.DOCServerPort ="";

GlobalConfig.RecordServerIP ="";
GlobalConfig.RecordServerPort ="";

GlobalConfig.maxVideoChannels=0;//最大视频路数
GlobalConfig.maxAudioChannels=0;//最大音频路数
GlobalConfig.maxMediaChannels=0;//最大音视频路数,以音视频路数中的最大值为准

GlobalConfig.hasCamera=false;//摄像头是否可用
GlobalConfig.hasMicrophone=false;//麦克风是否可用

GlobalConfig.deviceType=0; //设备类型  0:电脑  1:安卓  2:ios
GlobalConfig.userIp="";//用户当前IP
GlobalConfig.userId=0;
GlobalConfig.userName="";
GlobalConfig.handUpTime=0;
GlobalConfig.level=0;
GlobalConfig.openCamera=0;
GlobalConfig.openMicrophones=0;
//视频质量相关设置
GlobalConfig.fps=15;//帧频
GlobalConfig.gop=3;//关键帧间隔(秒)
GlobalConfig.videoQuality=2;//画面质量 0-低;1-中;2-高;
GlobalConfig.curVideoQuality=2;//当前分辨率
GlobalConfig.cameras=[];//摄像头列表
GlobalConfig.microphones=[];//麦克风列表

GlobalConfig.curCamera="";//当前选择的摄像头
GlobalConfig.curMicrophone='';//当前选择的麦克风
GlobalConfig.micGain=50;//音量(0-80)
GlobalConfig.speakerVolume=50;//扬声器音量(0-80)
GlobalConfig.micCode=0;//麦克风模式


GlobalConfig.audioRecords=[];
GlobalConfig.videoRecords=[];
GlobalConfig.status=0
GlobalConfig.mobileDirection=0;


GlobalConfig.nodeId=0;//随机生成 mcu中的唯一ID
GlobalConfig.passwordRequired=false;
GlobalConfig.password="";
GlobalConfig.userType=8;//默认是8
GlobalConfig.userRole=ApeConsts.normal;//用户的身份,5种类型:
GlobalConfig.role=ApeConsts.NR_NORMAL;//课堂角色身份

GlobalConfig.h5Module=1;//是否支持H5
GlobalConfig.topNodeID=101;//现在固定值,还不知道是做什么用

GlobalConfig.siteId="";//站点号
GlobalConfig.className= ""; // 课程名称
GlobalConfig.classId=0;//课堂号=classId=meetingNumber  之后统一修改为classId
GlobalConfig.classType=ApeConsts.CLASS_TYPE_1;//课堂类型
GlobalConfig.classStatus=ApeConsts.CLASS_STATUS_WAIT;// 0;//课堂还未开始  1;//直播中  2 //课间休息  3已经停止
GlobalConfig.classStartTime="";//课堂点击开始时间
GlobalConfig.classStopTime="";//最后一次停止的时间(点暂停或结束),每次发送数据都获取当前时间戳
GlobalConfig.classBeginTime="";//课堂创建的时间,这个是Sass返回的
GlobalConfig.classEndTime="";//课堂结束的时间,这个是Sass返回的
GlobalConfig.classTimestamp=0;//从课堂开始到现在的时
GlobalConfig.classJoinSuccess=false;//是否已经加入课堂
GlobalConfig.recordPlaybackMaxTime=0;//录制回放的总时间
GlobalConfig.recordStatus=false;//当前录制状态
GlobalConfig.recordTimestamp=0;//相对于首次开始录制的进行时间
GlobalConfig.recordFileName="";//录制的文件名,如 果为空就创建一个
GlobalConfig.recordDownloadUrl="";//下载地址
GlobalConfig.recordReplaytickValues={}; // 滚动条关键点,用于快进快退

GlobalConfig.isAutoStartClass=0;//是否自动开始上课 0-否 ;1 是

GlobalConfig.updateClassInfoDelay=30;//(秒),每隔30秒同步一次课堂状态的并保存到Sass
GlobalConfig.msDynamicChooseIpDelay=15;//(秒)MS动态选点的间隔
//GlobalConfig.serverTimestamp=0;//当前的系统时间戳 用get  set 获取


GlobalConfig.activeDocId=0;//当前激活的文档ID
GlobalConfig.activeDocCurPage=1;//当前激活的文档的当前页

GlobalConfig.activeMediaId=0;//当前显示的媒体文件的id
GlobalConfig.activeMediaSeek=1;//当前的媒体文件的播放进度seek点


GlobalConfig.classAllParam={};//Sass直接返回的所有课堂信息(最全)
GlobalConfig.classDetail={};//Sass直接返回的当前课堂基本信息

//从Sass获取的
GlobalConfig.sharedMediaList=[]; // 已经提前上传的媒体文件列表,进入课堂后需要自动加载
GlobalConfig.docListPrepare=[]; // 已经提前上传的文档,进入课堂后需要自动加载
GlobalConfig.recordList=[];//录制服务器地址集合
GlobalConfig.docList=[];//文档服务器地址集合
GlobalConfig.mcuList=[];//录制服务器地址集合
GlobalConfig.msList=[];//ms服务器地址集合
GlobalConfig.musicList=[];//music服务器地址集合
GlobalConfig.musicListPrepare=[];//提提前上传的music集合
GlobalConfig.rsList=[];//录制回放中视频点播地址
GlobalConfig.videoCDNAddr='';
GlobalConfig.videoCDNAddrList=[];//从videoCDNAddr转换来的,videoCDNAddr字符串用分号隔开了多个ip

//乐视的推流和播放需要分开
GlobalConfig.pullRtmpList=[];//rtmp播流地址集合(推流和播流地址需要区分的站点使用)
GlobalConfig.hlsList=[];//hls播流地址集合(推流和播流地址需要区分的站点使用)

//根据IP从server获取
GlobalConfig.mcuListFromServer=[];//根据userIP从server获取的mcu列表
GlobalConfig.msListFromServer=[];//根据userIP从server获取的ms列表
GlobalConfig.country ="";//国家
GlobalConfig.city ="";//城市
GlobalConfig.province = "";//服务商
GlobalConfig.isp ="";//服务商


GlobalConfig.mcuListAll=[];//所有MCU集合(sass+server)
GlobalConfig.msListAll=[];//所有MS集合(sass+server)

GlobalConfig.isRecordPlayBack=false;//是否是录制回放,默认是否
GlobalConfig.allowRecordMaxTime=14400;//(秒)允许录制的最长时间,默认是4小时

GlobalConfig.siteId_letv='shchuanbao';//乐视,MS不需要动态选点的站点
GlobalConfig.ssTunnelAppURL='';//屏幕共享插件的地址



export  default GlobalConfig;