/**
 * Created by zzsun on 15-2-6.
 */


var TA_APP = {
    //空
    "TA_APP_NONE": 'none',
    //TA主程序
    "TA_APP_MAIN": 'main',
    //iFlyBook
    "TA_APP_IB": 'ib',
    //托盘
    "TA_APP_TRAY": 'tray',
    //课件制作工具
    "TA_APP_ICW": 'icw',
    //所有
    "TA_APP_ALL": 'all'
};

var TAMSG = {
    "TAMSG_TYPEKEY": "type",
    "TAMSG_ACTIONKEY": "action",
    "TAMSG_FROMKEY": "from",
    "TAMSG_TOKEY": "to",
    "TAMSG_IDKEY": 'id',
    "TAMSG_DATAKEY": "data",
    "TAMSG_RETURNKEY": "return"
}

var TYPE = {
    'CONN': 'conn',
    'LOGIC': 'logic'
};

var CMD = {
    //register
    TAMSG_REGISTER: 'register',
    //quit
    TAMSG_QUIT: 'quit',
    //login
    "TAMSG_LOGIN": 'login',
    //logout
    "TAMSG_LOGOUT": 'logout',
    //畅言云有消息
    "TAMSG_HASMSG": 'msg',
    //打开面板
    'TAMSG_OPENPANEL': 'main',
    //打开反馈和客服
    "TAMSG_OPENFEEDBACK": 'feedback',
    //打开消息中心
    "TAMSG_OPENMSGCENTER": 'msgcenter',
    //通知退出
    "TAMSG_NOTIFYEXIT": 'exit',
    //下载回调
    "TAMSG_DOWNLOAD_GETRES": 'download_getres',
    //高拍仪回调
    "TAMSG_CameraInfo" : 'cameraInfo',
    // 快照回调
    "TAMSG_SCREENSHOT" : 'screenshotInfo',
    "TAMSG_AUDIOTOOL" : 'audioInfo',
    //浮动工具栏消息
    "TAMSG_FLOATTOOLBAR_IB_MIN":'floattoolbar_ib_min',
    "TAMSG_FLOATTOOLBAR_IB_MAX":'floattoolbar_ib_max'


};

function icwWSLogic(receive){
    if(receive){
        var _type = receive.type,
            _action = receive.action,
            _from = receive.from,
            _to = receive.to,
            _data = receive.data,
            _return = receive.return;
        if(_to == TA_APP.TA_APP_ICW || _to == TA_APP.TA_APP_ALL){
            console.log("收到新消息");
            //连接相关
            if(_type=='conn'){
                switch (_action){
                    case CMD.TAMSG_REGISTER:
                        //客户端注册收到的消息
                        if(_return.code ==0 ){
                            console.log("注册成功");
                        }
                        break;
                    case CMD.TAMSG_QUIT:
                        //客户端注册收到的消息
                        if(_return.code ==0 ){
                            console.log("socket客户端退出");
                        }
                        break;
                }
            }
            //业务相关
            if(_type=='logic'){
                switch (_action){
					//这里接收到通知退出的消息
                    case CMD.TAMSG_NOTIFYEXIT:
                        if(!window.commands){
                            //模板界面
                            window.require('nw.gui').Window.get().close();
                        }
                        if(window.commands){
                            //编辑界面
                            window.commands.closeWindow();
                        }
                        break;
                    default :
                        break;
                }
            }
        }
    }
}






