// ***************************************************************************** // 文 件 名: jocxctrl.js // 作 者: wsj // 版 本: 1.0.0.0 // 日 期: 2014-07-15 // 文件描述: // 基于websocket的电话条控件 // 说 明: // 基于websocket的的电话条控件 // 修改说明: // ***************************************************************************** ///////////////////////////////////////////////////////////////////////////// var emInitNull = -1; //没有初始化 var emInitParamError = emInitNull+1; var emInitSuccess = emInitNull+2; var emInitSIPError = emInitNull+3; var emInitMaccardError = emInitNull+4; var emInitCTIError = emInitNull+5; var emInitMonitorError = emInitNull+6; var emCmdLogout = emInitNull+7; //座席主动挂断 var emCTIDisconneted = emInitNull+8; //CTI连接断开 var emMonitorDisconneted = emInitNull+9; //CTI连接断开 var emSipDisconneted = emInitNull+10; //sip注销 var emServerDisconnected = emInitNull+11; //AGENT断开连接 var emClientDisconnected = emInitNull+12; //VCCBAR断开连接 var emExChangeAgentDisconnected = emInitNull+13; //切换座席 var emBtnWrapUp = 0; //后续态 0 不可见:-1 var emBtnSetBusy = emBtnWrapUp+ 1; //工作 1 不可见:-1 var emBtnSetIdle = emBtnWrapUp+ 2; //空闲 2 不可见:-1 var emBtnMakeCall = emBtnWrapUp+ 3; //呼出 3 不可见:-1 var emBtnHold = emBtnWrapUp+ 4; //保持 4 不可见:-1 var emBtnRetrieve = emBtnWrapUp+ 5; //接回 5 不可见:-1 var emBtnEndCall = emBtnWrapUp+ 6; //挂断 6 不可见:-1 var emBtnTransfer = emBtnWrapUp+ 7; //转移 7 不可见:-1 var emBtnConference = emBtnWrapUp+ 8; //会议 8 不可见:-1 var emBtnPickUp = emBtnWrapUp+ 9; //应答 9 不可见:-1 var emBtnTransferOut = emBtnWrapUp+10; //转出 10 不可见:-1 var emBtnConsult = emBtnWrapUp+11; //咨询 11 不可见:-1 var emBtnSendDtmf = emBtnWrapUp+12; //二次拨号 12 不可见:-1 var emBtnBridge = emBtnWrapUp+13; //桥接 13 不可见:-1 var emBtnAlterNate = emBtnWrapUp+14; //切换 14 不可见:- var emBtnConfig = emBtnWrapUp+15; //设置 15 不可见:-1 var emBtnForceReset = emBtnWrapUp+16; //强制复位 16 不可见:-1 var emBtnRecord = emBtnWrapUp+17; //录音 17 不可见:-1 var emBtnStopRecord = emBtnWrapUp+18; //停止录音 18 不可见:-1 var emBtnListen = emBtnWrapUp+19; //监听 19 不可见:-1 var emBtnInsert = emBtnWrapUp+20; //强插 20 不可见:-1 var emBtnIntercept = emBtnWrapUp+21; //拦截、代答 21 不可见:-1 var emBtnForceRelease = emBtnWrapUp+22; //强拆 22 不可见:-1 var emBtnBeginPlay = emBtnWrapUp+23; //开始放音 23 不可见:-1 var emBtnStopPlay = emBtnWrapUp+24; //结束放音 24 不可见:-1 var emBtnLock = emBtnWrapUp+25; //加锁 25 不可见:-1 var emBtnUnLock = emBtnWrapUp+26; //解锁 26 不可见:-1 var emBtnMute = emBtnWrapUp+27; //静音/取消静音 27 不可见:-1 var emBtnCallBack = emBtnWrapUp+28; //重拨 28 不可见:-1 var emBtnReCall = emBtnWrapUp+29; //返回 29 不可见:-1 var emBtnHelp = emBtnWrapUp+30; //辅助 30 不可见:-1 // service direction var CD_IVR_CALLIN = 0; //0或空:正常呼叫 var CD_SERVRE_EXACT_CALLOUT = 1; //1:精确式外呼 (先呼座席、再呼用户) var CD_PREVIEW_CALLOUT = 2; //2:预览式外呼 var CD_AGENT_OUTSIDE_CALLOUT = 3; //3:人工外呼 (CallOutside) var CD_IVR_CALLOUT = 4; //4:IVR外呼 var CD_AGENT_INSIDE_CALLOUT = 5; //5:内部呼叫 (CallInside) var CD_CONSULT_CALLOUT = 6; //6:咨询 var CD_SINGLE_CALLOUT = 6; //7:单步转移 var CD_BRIDGE_CALLOUT = 8; //8:桥接 var CD_MONITOR_CALLIN = 9; //9:监听 var CD_INTERCEPT_CALLIN = 10; //10:拦截 var CD_INSERT_CALLIN = 11; //11:强插 var CD_STEPBYSTEP_CALLOUT = 12; //12:渐进式外呼 (先呼用户、再呼座席) var CD_FORECAST_CALLOUT = 13; //13:预测式外呼 (先呼用户、再呼座席) var CD_HELP_CALLIN = 19; //19:辅助 var PORT_COUNT = 5 var barStatus_Null = 0; //都没有连接 var barStatus_GuardConnecting = 1; //正在连接guard var barStatus_GuardConnected = 2; //连接guard成功 var barStatus_GuardDisconnecting = 3; //正在挂断guard var barStatus_GuardDisconnected = 4; //挂断guard成功 var barStatus_AgentConnecting = 5; //正在连接agent var barStatus_AgentConnected = 6; //连接agent成功 var barStatus_AgentDisconnecting = 7; //正在挂断agent var barStatus_AgentDisconnected = 8; //agent function JHTML5Ctrl() { this.oAgentInfo = null; //agentInfo this.oApspWS = null; //websocket this.eventCallBack = null; this.responseCallBack = null; this.oGuardCtrl = null; this._connectCount = 0; //连接次数 this._arrBtnStatus = new Array(); //-------------------------------------------------------------------------------------------------- // 辅助函数 //-------------------------------------------------------------------------------------------------- this._load = function _load(){ this.oAgentInfo = new JAgentInfo(); this.oAgentInfo.loadFromLocal(); this.oApspWS = new JAPSPWebSocket("MacCard"); this.oApspWS.SetMsgCallBack(this.apspCallback); this.oApspWS.oParent = this; this.oGuardCtrl = new JGuardCtrl(this); for(var i=0;i< emBtnHelp + 1;i++){ this._arrBtnStatus.push(0); } this._arrBtnStatus[emBtnWrapUp] = 1; this._arrBtnStatus[emBtnConfig] = 1; } this._ResetBtn = function (){ for(var i=0;i< emBtnHelp + 1;i++){ this._arrBtnStatus[i] = 0; } } this._invokeEvent = function(cmdIndex,param){ if(this.eventCallBack != null){ DisplayLog(VccBar_Log_Info,"JHTML5Ctrl:_invokeEvent(cmdIndex="+cmdIndex+" param="+param+")"); this.eventCallBack(cmdIndex,param); if(cmdIndex == eventOnInitalSuccess) { this._InvokeMethod(APSP_GetConfiguration_CONF,""); } } } this._getPartenerNum = function(strParam){ var strDN = ""; var oParam = strParam.split("|"); switch (parseInt(oParam[5])) { case CD_IVR_CALLIN: // 0或空:正常呼叫 case CD_SERVRE_EXACT_CALLOUT: //1:精确式外呼 case CD_SINGLE_CALLOUT: //7:单步转移 case CD_STEPBYSTEP_CALLOUT: //12:渐进式外呼 case CD_FORECAST_CALLOUT: //13:预测式外呼 case CD_CONSULT_CALLOUT: //6:咨询 originalDevice存放用户号码 strDN = oParam[0]; //主叫 //协议中的origCallingDevice break; case CD_PREVIEW_CALLOUT: //2:预览式外呼 case CD_AGENT_OUTSIDE_CALLOUT: //3:人工外呼 (CallOutside) case CD_AGENT_INSIDE_CALLOUT: //5:内部呼叫 (CallInside) case CD_MONITOR_CALLIN: //9:监听 case CD_INTERCEPT_CALLIN: //10:拦截 case CD_INSERT_CALLIN: //11:强插 strDN = oParam[2]; //原始被叫 //协议中的callingDevice break; case CD_HELP_CALLIN: //19:辅助 strDN = oParam[2]; //原始被叫 //协议中的callingDevice break; case CD_IVR_CALLOUT: //4:IVR外呼 case CD_BRIDGE_CALLOUT: //8:桥接 strDN = oParam[0]; break; } return strDN; } this.connectToService = function connectToService(server,localport) { this.oApspWS.WSConnect(server,localport); var lg = getLocalLanguage(); if(this.oAgentInfo._ctrlStatus == barStatus_GuardConnecting) { this._invokeEvent(eventOnWebsocketSocket,(lg == lg_zhcn)?websocket_guard_connecting+"|正在连接电话条卫士【"+server+":"+localport+"】...第【"+this._connectCount+"】次":websocket_guard_connecting+"|connecting to CINGurad ("+server+":"+localport+")...time:("+this._connectCount+")"); } else { this._invokeEvent(eventOnWebsocketSocket,(lg == lg_zhcn )?websocket_connecting+"|正在连接电话条服务【"+server+":"+localport+"】...第【"+this._connectCount+"】次":websocket_connecting+"|connect to Maccard("+server+":"+localport+")...time:("+this._connectCount+")"); } this._connectCount = this._connectCount + 1; } this._InvokeMethod = function _InvokeMethod(cmdIndex,param){ var cmdName = this.oApspWS.GetCmdName(cmdIndex); if( cmdName == "") return -1; if( cmdIndex == APSP_GetLocalPort_CONF){ param = this.oAgentInfo._localPort+"|"+this.oAgentInfo._killMaccard;//""; } else if( cmdIndex == APSP_Initial_CONF){ param = this.oAgentInfo.getInitialParam(); } DisplayLog(VccBar_Log_Info,"JHTML5Ctrl:_InvokeMethod(cmdName="+cmdName+",param="+param+")"); return this.oApspWS.WSSendMsg(buildApspMsg(cmdName,param)); } this.IsInitial = function(){ DisplayLog(VccBar_Log_Info,"JHTML5Ctrl:IsInitial("+this.oAgentInfo._isInitial+")"); return this.oAgentInfo._isInitial; } this.IsMethodUserFull = function(btnIndex,btnName){ if(this._arrBtnStatus[btnIndex] == 1) return true; this._gfOnPrompt(4311,"命令["+btnName+"]不可用,无法执行!") return false; } this.ResetThisCtrl = function() { this.oAgentInfo._isConnected = false; this.oAgentInfo._isInitial = false; this.oAgentInfo._ctrlStatus = barStatus_Null; this.oAgentInfo._localPort = 4520; this.oAgentInfo._localGuardPort = 4510; this._connectCount = 0; } this.GetBtnStatuIDs = function(){ var strResult = ""; for (var i = 0;i14) strOpAgentID = oParam[14]; var callData = GetGBKFromBase64(oParam[3]); destParam = oParam[0] + "|" + oParam[1] + "|" + oParam[2] + "|" + callData + "|" + oParam[4] + "|" + oParam[5] + "|" + oParam[6] + "|" + oParam[7] + "|" + oParam[8]; destParam = destParam + "|" + strUserDn + "|" + this.oAgentInfo._dn + "|" + oParam[9] + "|" + oParam[11] + "|" + oParam[12] + "|" + oParam[13]+ "|" + strOpAgentID; } break; case APSP_AnswerCall_EVENT: cmdIndex = eventOnAnswerCall; break; case APSP_OnCallEnd_EVENT: cmdIndex = eventOnCallEnd; this.oAgentInfo._retrieveCall = 0; break; case APSP_OnPrompt_EVENT: { cmdIndex = eventOnPrompt; var code = parseInt(oParam[0]); destParam = code + "|" ;//+ this.oBarControl.GetErrorItemDes(code); switch (code) { case 4011: case 4005: this.SetLogoutStatus(); break; case 4009://心跳检测到CTI中座席已经退出! case 4305: //别人替换:OnSignOuted case 4404: //OnForceOut { break; } } // } break; case APSP_OnReportBtnStatus_EVENT: { cmdIndex = eventOnReportBtnStatus; this._ResetBtn(); var strBtn = ""; for (var i = 0; i < oParam.length; i++) { var id = oParam[i]; var index = parseInt(id); if (index >= 100) { this.oAgentInfo._agentStatus = index - 100; id = "0"; } else { this._arrBtnStatus[index] = 1; } if (strBtn == "") strBtn = id; else strBtn = strBtn + "|" + id; } destParam = strBtn; } break; case APSP_OnInitalSuccess_EVENT: { cmdIndex = eventOnInitalSuccess; if (param.lastIndexOf("@") > 0) { var op = param.split("@"); if (op.length == 2) { this.oAgentInfo.phoneType = parseInt(op[1]); param = op[0]; } else if (op.length == 3) { this.oAgentInfo.phoneType = parseInt(op[1]); param = op[0]; this.oAgentInfo._strExitCause = op[2]; } } this.oAgentInfo._strBusySubStatus = param; this.oAgentInfo._isInitial = true; } break; case APSP_OnInitalFailure_EVENT: { cmdIndex = eventOnInitalFailure; if (parseInt(oParam[0]) == emCmdLogout) { this.oAgentInfo._isInitial = false; } } break; case APSP_OnEventPrompt_EVENT: cmdIndex = eventOnEventPrompt; if (parseInt(oParam[0]) == 108) {//eventidOnStopCollectSuccess this._invokeEvent(eventOnCallDataChanged, oParam[1]); } break; case APSP_OnAgentWorkReport_EVENT: cmdIndex = eventOnAgentWorkReport; if (parseInt(oParam[0]) == 14) {//emPhoneHold if (this.oAgentInfo._retrieveCall == 1) { this.RetrieveHold(); this.oAgentInfo._retrieveCall = 0; } } else if (parseInt(oParam[0]) == -1) { // this.oAgentInfo._ctrlStatus = barStatus_AgentDisconnecting; // this.oApspWS.WSDisconnect(); } break; case APSP_OnBarExit_EVENT: this.oAgentInfo._isInitial = false; cmdIndex = eventOnBarExit; break; case APSP_OnSystemBusy_EVENT: break; case APSP_OnCallQueueQuery_EVENT: cmdIndex = eventOnCallQueueQuery; break; case APSP_OnQueueReport_EVENT: cmdIndex = eventOnQueueReport; break; case APSP_OnSystemMessage_EVENT: { oParam = param.split(","); if (oParam.length == 2) { var ntype = parseInt(oParam[0]); switch (ntype) { case 1: //1、随路数据发生改变时,向座席触发 cmdIndex = eventOnCallDataChanged; destParam = GetGBKFromBase64(oParam[1]); break; case 2: cmdIndex = eventOnSystemMessage; destParam = "2|" + oParam[1]; break; case 22: //1、异步查询指定组的座席情况 sysMessage@formatMessage cmdIndex = eventOnQueryGroupAgentStatus; destParam = oParam[1]; break; } } } break; case APSP_OnRecvWeiboMsg_EVENT: cmdIndex = eventOnRecvWeiboMsg; break; case APSP_OnIMNoticsMsg_EVENT: cmdIndex = eventOnIMMessage; destParam = "0|" + destParam; break; case APSP_OnIMTextMsg_EVENT: cmdIndex = eventOnIMMessage; destParam = "1|" + destParam; break; case APSP_OnAction_EVENT: cmdIndex = eventOnPrompt; this.oAgentInfo._allTimeRecord = parseInt(oParam[1]); //接通并录音 接通并不录音 return; case APSP_OnSetDlgStatusText_EVENT: //cmdIndex = eventOnPrompt; break; case APSP_OnChangeBtnSerial_EVENT: //cmdIndex = eventOnPrompt; break; case APSP_OnTaskReport_EVENT: cmdIndex = eventOnTaskReport; break; case APSP_CallReportInfo_EVENT: cmdIndex = eventCallReportInfo; break; case APSP_QueryMonitorSumReport_EVENT: cmdIndex = eventQueryMonitorSumReport; break; case APSP_OutboundReport_EVENT: cmdIndex = eventOutboundReport; break; case APSP_OnAgentReport_EVENT: cmdIndex = eventOnAgentReport; break; case APSP_OnIvrReport_EVENT: cmdIndex = eventOnIvrReport; break; case APSP_OnTelReport_EVENT: cmdIndex = eventOnTelReport; break; case APSP_OnServiceReport_EVENT: cmdIndex = eventOnServiceReport; break; case APSP_OnWallServiceReport_EVENT: cmdIndex = eventOnWallServiceReport; break; case APSP_OnWallQueueReport_EVENT: cmdIndex = eventOnWallQueueReport; break; case APSP_OnStaticInfoReport_EVENT: cmdIndex = eventOnWorkStaticInfoReport; break; case APSP_OnServiceStaticReport_EVENT: cmdIndex = eventOnServiceStaticReport; break; case APSP_OnAgentStaticReport_EVENT: cmdIndex = eventOnAgentStaticReport; break; case APSP_OnRecvWeChatMsg_EVENT: { destParam = oParam[0] + "|" + oParam[1] + "|" + oParam[2] + "|" + oParam[3] + "|" + oParam[4] + "|" + oParam[5] + "|" + GetGBKFromBase64(oParam[6]) + "|" + oParam[7] + "|" + oParam[8]; destParam = destParam + "|" + oParam[9] + "|" + oParam[10] + "|" + GetGBKFromBase64(oParam[11]) + "|" + GetGBKFromBase64(oParam[12]) + "|" + oParam[13]; } cmdIndex = eventOnRecvWeChatMessage; break; case APSP_OnUploadFileToMMSReport_EVENT: cmdIndex = eventOnUploadFileToMMSReport; break; case APSP_OnDownloadFileToMMSReport_EVENT: cmdIndex = eventOnDownloadFileToMMSReport; break; case APSP_OnSendWeChatMsgReport_EVENT: cmdIndex = eventOnSendWeChatMsgReport; break; case APSP_OnAQueryCTIInfo_EVENT: { var cType = getSubString(param,"","|"); if(cType == "8"||cType == "9"||cType == "10"){ cmdIndex = eventOnAQueryCTIInfoReport; } else return ; } break; default: break; } this._invokeEvent(cmdIndex, destParam); } this._load(); } //-------------------------------------------------------------------------------------------------- // 座席属性信息保存 //-------------------------------------------------------------------------------------------------- function JAgentInfo(){ this._agentID = ""; this._passWord="111111"; //4-8 this._agentType=0; this._agentName=""; this._mainIP=""; this._backIP=""; this._mainPortID=14800; this._backPortID=14800; this._dn = ""; //4-12 this._vccId=""; //集团号 this._version = "20.141204"; //版本号(web版本号+电话条版本号) this._passWdCryptType = 0; //0:明码 1:MD5加密 this._isConnected = false; this._isInitial = false; this._isSignIn = false; this._idleStatus = 0; // 0表示人工,1表示自动 this._autoAnswer = 0; // this._autoSelectAgent = false; //20080331 this._callIn = 0; //内呼 this._warn = 0; //告警 this._sipAlert = 1; //SIP是否振铃 this._registInterVal = 1800; //SIP注册时间间隔 this._ecDelaySize = 0; //回声消除延时包数(不用) this._fAudioGain = 1; //增益系数(不用) this._popAlert = 0; //来电是否弹窗提示 this._setBusySupport0 = 0; this._vedioWnd = 0; this._bandWidth = 192; this._frameRate=30; this._vedioFormat=2; this._capType = 0; //0 :camra 1: windows this._defaultIP = ""; this._recordType; this._phoneType = 1; //0:内置座席卡 1:内置Sip电话 2:外置其他终端;3:远程sip电话;4:软交换前传号码; 5:yealink话机 6:agora this._allTimeRecord = 0; //0:服务器不录1:服务器全程录音2:客户端不录3:客户端全程录音 this._ftpIp=""; this._ftpPort=0; this._ftpUser=""; this._ftpPassWord=""; this._ftpDirectory=""; this._localDirectory=""; this._sipDn=""; //默认为空,使用DN向SIP服务器注册 this._sipIp=""; this._sipServerPort = 5060; this._sipProtocol="udp"; this._sipPassWord="111111"; this._sipDomain=""; this._sipAuthType=1; // 0-NO 1-DEGEST this._sipPassWdCryptType = 0; //0 sipdn不加密 1 Des加密 this._sipBackIp=""; this._sipBackServerPort=5060; this._sipBackProtocol="udp"; this._sipBackPassWord="111111"; this._sipBackDomain=""; this._sipBackAuthType=1; // 0-NO 1-DEGEST this._selfPrompt; //1:控件自己提示:0:外部提示 this._monitorIp=""; this._monitorPor =4502; this._monitorBackIp=""; this._monitorBackPort=4502; this._msgFlag=""; //老版本,组号 this._appType=0; //应用类型;Agent 0 Monitor 1 agent+minitor 2 this._minotorVersion=""; //监控版本号:MinotorVersion this._taskID=""; this._autoUpdateUrl=""; this._barStyle=""; this._barPath=""; this._weChatServerIp=""; this._configDialogFlag=""; this._isSipRegisted=false; this._minMediaPort = 20000; this._maxMediaPort = 40000; this._recvAgc = 1; this._recvNs = 0; this._sendAgc = 1; this._sendEc = 1; this._sendNs = 0; this._updating = false; this._btnIDS = "0,1,2,3,4,5,6,7,8,9,10,11,12,13,15,16"; this._btnMaskIDS = ""; //辅助变量 this._localserver = "127.0.0.1"; this._localPort = 4520; this._localGuardPort = 4510; this._ctrlStatus = barStatus_Null; // this._agentStatus = 0; //0:未登录 1:忙碌 2:空闲 3:通话中 4:后续态 this._agentBusySubStatus = 0; //子状态 this._agentBusySubStatus_old = 0; //子状态 this._strBusySubStatus = ""; //子状态内容 this._strExitCause = ""; this._barExitCode = "0"; this._retrieveCall = 0; this._realMethodName = ""; this._killMaccard = 0; this._arrUserBtn = this._btnIDS.split(","); this.InitSerialBtn = function(btnIDS,hiddenIDS){ this._btnIDS = btnIDS; this._btnMaskIDS = hiddenIDS; this._arrUserBtn = this._btnIDS.split(","); } this.getInitialParam = function(){ var arr = new Array(38); // 1-2 phoneType|appType 2 arr[0] = this._phoneType; arr[1] = this._appType; //3.ctiip|ctiport|ctibkip|ctibkport|ctiagentID|ctivccID|ctipassword 7 arr[2] = this._mainIP; arr[3] = this._mainPortID; arr[4] = this._backIP; arr[5] = this._mainPortID; arr[6] = this._agentID; arr[7] = this._vccId; arr[8] = this._passWord; //10.monitorip|monitorport|monitorbkip|monitorbkport 4 arr[9] = this._monitorIp; arr[10] = this._monitorPor; arr[11] = this._monitorBackIp; arr[12] = this._monitorBackPort; //14.sipip|sipport|sipprotocol|sipdn|sipdomain|sippassword|sipauthtype 7 arr[13] = this._sipIp; arr[14] = this._sipServerPort; arr[15] = this._sipProtocol; arr[16] = this._dn; arr[17] = this._sipDomain; arr[18] = this._sipPassWord; arr[19] = this._sipAuthType; //21.sipbackip|sipbackport|sipbackprotocol|sipbackdomain|sipbackpassword|sipbackauthtype 6 arr[20] = this._sipBackIp; arr[21] = this._sipBackServerPort; arr[22] = this._sipBackProtocol; arr[23] = this._sipBackDomain; arr[24] = this._sipBackPassWord; arr[25] = this._sipBackAuthType; //27.btnIDS|SendHandle|RecvHandle|TaskID 4 arr[26] = this._btnIDS; arr[27] = 0; arr[28] = 0; arr[29] = this._taskID; //31.ftpip|ftpport|ftpuser|ftppwd|ftpDir|sipDn|wecharServer|sippasswdcrypttype|passwdcrypttype 7+2 arr[30] = this._ftpIp; arr[31] = this._ftpPort; arr[32] = this._ftpUser; arr[33] = this._ftpPassWord; arr[34] = this._ftpDirectory; arr[35] = this._sipDn; arr[36] = this._weChatServerIp; arr[37] = this._sipPassWdCryptType; arr[38] = this._passWdCryptType; return arr.join("|"); } this.getIntCookieValue = function(strName,defaultValue){ var strValue = getCookie(strName); if(strValue == "") return defaultValue; return parseInt(strValue); } this.loadFromLocal = function(){ this._autoAnswer = this.getIntCookieValue("AutoAnswer",0); this._idleStatus = this.getIntCookieValue("AutoIdle",0); this._callIn = this.getIntCookieValue("CallIn",0); this._warn = this.getIntCookieValue("Warn",0); this._sipAlert = this.getIntCookieValue("SipAlert",1); this._registInterVal = this.getIntCookieValue("RegistInterval",1800); this._vedioWnd = this.getIntCookieValue("VedioWnd",0); this._bandWidth = this.getIntCookieValue("BandWidth",192); this._frameRate = this.getIntCookieValue("FrameRate",30); this._vedioFormat = this.getIntCookieValue("VedioFormat",2); this._capType = this.getIntCookieValue("CapType",0); this._defaultIP = getCookie("DefaultIP"); this._minMediaPort = this.getIntCookieValue("MinMediaPort",20000); this._maxMediaPort = this.getIntCookieValue("MaxMediaPort",40000); this._ecDelaySize = this.getIntCookieValue("EchoCancelDelay",0); this._fAudioGain = this.getIntCookieValue("AudioGain",1); this._popAlert = this.getIntCookieValue("PopAlert",0); this._setBusySupport0 = this.getIntCookieValue("SetBusySupport0",0); this._recvAgc = this.getIntCookieValue("RecvAgc",1); this._recvNs = this.getIntCookieValue("RecvNs",0); this._sendAgc = this.getIntCookieValue("SendAgc",1); this._sendEc = this.getIntCookieValue("SendEc",1); this._sendNs = this.getIntCookieValue("SendNs",0); } this.saveToLocal = function(){ setCookie("AutoAnswer",this._autoAnswer,365); setCookie("AutoIdle",this._idleStatus,365); setCookie("CallIn",this._callIn,365); setCookie("Warn",this._warn,365); setCookie("SipAlert",this._sipAlert,365); setCookie("RegistInterval",this._registInterVal,365); setCookie("VedioWnd",this._vedioWnd,365); setCookie("BandWidth",this._bandWidth,365); setCookie("FrameRate",this._frameRate,365); setCookie("VedioFormat",this._vedioFormat,365); setCookie("CapType",this._capType,365); setCookie("DefaultIP",this._defaultIP,365); setCookie("MinMediaPort",this._minMediaPort,365); setCookie("MaxMediaPort",this._maxMediaPort,365); setCookie("EchoCancelDelay",this._ecDelaySize,365); setCookie("AudioGain",this._fAudioGain,365); setCookie("PopAlert",this._popAlert,365); setCookie("SetBusySupport0",this._setBusySupport0,365); setCookie("RecvAgc",this._recvAgc,365); setCookie("RecvNs",this._recvNs,365); setCookie("SendAgc",this._sendAgc,365); setCookie("SendEc",this._sendEc,365); setCookie("SendNs",this._sendNs,365); } this.getConfigParam = function(){ var arr = new Array(21); //AutoAnswer|IdleStatus|bCallIn|bWarn|bSipAlert 5 arr[0] = this._autoAnswer; arr[1] = this._idleStatus; arr[2] = this._callIn; arr[3] = this._warn; arr[4] = this._sipAlert; //nRegistInterVal|bVedioWnd|bandWidth|frameRate|vedioFormat 5 arr[5] = this._registInterVal; arr[6] = this._vedioWnd; arr[7] = this._bandWidth; arr[8] = this._frameRate; arr[9] = this._vedioFormat; //capType|m_strDefaultIP|minMediaPort|maxMediaPort|ecDelaySize|fAudioGain 6 arr[10] = this._capType; arr[11] = this._defaultIP; arr[12] = this._minMediaPort; arr[13] = this._maxMediaPort; arr[14] = this._ecDelaySize; arr[15] = this._fAudioGain; //recvAgc|recvNs|sendAgc|sendEc|sendNs 5 arr[16] = this._recvAgc; arr[17] = this._recvNs; arr[18] = this._sendAgc; arr[19] = this._sendEc; arr[20] = this._sendNs; return arr.join("|"); } this.getConfiguration = function(){ var arr = new Array(12); //AutoAnswer|IdleStatus|bCallIn|bWarn|bSipAlert 5 arr[0] = this._autoAnswer; arr[1] = this._idleStatus; arr[2] = this._callIn; arr[3] = this._warn; arr[4] = this._sipAlert; //nRegistInterVal|bVedioWnd|bandWidth|frameRate|vedioFormat 5 arr[5] = this._registInterVal; arr[6] = this._vedioWnd; arr[7] = this._bandWidth; arr[8] = this._frameRate; arr[9] = this._vedioFormat; //capType|m_strDefaultIP 2 arr[10] = this._capType; arr[11] = this._defaultIP; return arr.join("|"); } } //-------------------------------------------------------------------------------------------------- // 自动更新 //-------------------------------------------------------------------------------------------------- var cmd_GuardType_Null = -1; var cmd_GuardType_GetLocalPort = 0; var cmd_GuardType_UpdateSetup = 1; function JGuardCtrl(oParent){ this.oGuradWS = null; //websocket this._ctrlStatus = barStatus_Null; this._connectCount = 0; this._oParent = oParent; this._cmdType = cmd_GuardType_Null; this._cmdParam1 = ""; this._cmdParam2 = ""; this._Create = function(){ this.oGuradWS = new JAPSPWebSocket("CINGuard"); this.oGuradWS.SetMsgCallBack(this.apspCallbackGurad); this.oGuradWS.oParent = this; } this.exeGuardCmd = function(cmdType,cmdParam1,cmdParam2){ this._cmdType = cmdType; this._cmdParam1 = cmdParam1; this._cmdParam2 = cmdParam2; if(this._ctrlStatus == barStatus_Null) { this._ctrlStatus = barStatus_GuardConnecting; this.connectToService(this._oParent.oAgentInfo._localserver,this._oParent.oAgentInfo._localGuardPort); } else if(this._ctrlStatus == barStatus_GuardConnected) {//没有获得Maccard的IP; if(this._cmdType == cmd_GuardType_GetLocalPort) { this._InvokeMethod(APSP_GetLocalPort_CONF,this._cmdParam1); } else if(this._cmdType == cmd_GuardType_UpdateSetup) { this._InvokeMethod(APSP_UpdateSetup_CONF,GetApspParam(this._cmdParam1,this._cmdParam2)); } } return 0; } this.connectToService = function (server,localport) { this.oGuradWS.WSConnect(server,localport); if(this._ctrlStatus == barStatus_GuardConnecting) { this._oParent._invokeEvent(eventOnWebsocketSocket,websocket_guard_connecting+"|正在连接电话条卫士【"+server+":"+localport+"】...第【"+this._connectCount+"】次"); } this._connectCount = this._connectCount + 1; } this._InvokeMethod = function _InvokeMethod(cmdIndex,param){ var cmdName = this.oGuradWS.GetCmdName(cmdIndex); if( cmdName == "") return -1; DisplayLog(VccBar_Log_Info,"JGuardCtrl:_InvokeMethod(cmdName="+cmdName+",param="+param+")"); this.oGuradWS.WSSendMsg(buildApspMsg(cmdName,param)); } ////////////////////////////////////////////////////////////////////////// // 事件 ///////////////////////////////////////////////////////////////////////// this.OnGuardWebSocketEvent = function OnGuardWebSocketEvent(cmdIndex,param){ if(cmdIndex == APSP_WebSocket_Event) { //WebSocket 事件处理 var code = parseInt(param); if( code == websocket_connected) { this._ctrlStatus = barStatus_GuardConnected; this._oParent._invokeEvent(eventOnWebsocketSocket,websocket_guard_connected+"|"); if(this._cmdType == cmd_GuardType_GetLocalPort) { this._InvokeMethod(APSP_GetLocalPort_CONF,this._cmdParam1); } else if(this._cmdType == cmd_GuardType_UpdateSetup) { this._InvokeMethod(APSP_UpdateSetup_CONF,GetApspParam(this._cmdParam1,this._cmdParam2)); } } else if( code == websocket_remoteserver_disconnected) { if(this._ctrlStatus == barStatus_GuardConnecting) {//连接没有连上 if(this._connectCount < PORT_COUNT) { //连接guard this._oParent.oAgentInfo._localGuardPort = this._oParent.oAgentInfo._localGuardPort+10; this.connectToService(this._oParent.oAgentInfo._localserver,this._oParent.oAgentInfo._localGuardPort); } else { this._oParent.ResetThisCtrl(); this._oParent._invokeEvent(eventOnWebsocketSocket,websocket_guard_remoteserver_disconnected+"|"); } } } else if(code == websocket_closed) { if(this._ctrlStatus != barStatus_GuardConnecting) this._ctrlStatus = barStatus_Null; } } } this.OnGuardWebSocketActionEvent = function OnGuardWebSocketActionEvent(cmdIndex,param){ if(cmdIndex == APSP_GetLocalPort_CONF) { if(this._ctrlStatus == barStatus_GuardConnected) { this.oGuradWS.WSDisconnect(); this._oParent.oAgentInfo._localPort = parseInt(param); if(this._oParent.oAgentInfo._localPort == -1) { if(getLocalLanguage() == lg_zhcn) alert("MacCard.exe不存在"); else alert("MacCard.exe not exist"); } else if(this._oParent.oAgentInfo._localPort == -2) { if(getLocalLanguage() == lg_zhcn) alert("电话条安装包安装不正确"); else alert("CINVccBar package setup failure"); } } } else if(cmdIndex == APSP_UpdateSetup_CONF) { if(param == "-1"){ if(getLocalLanguage() == lg_zhcn) alert("自动更新程序不存在!"); else alert("Ccupdate not exist!"); } else if(param == "-2"){ if(getLocalLanguage() == lg_zhcn) alert("电话条安装包安装不正确!"); else alert("CINVccBar package setup failure!"); } else if(param == "-3"){ if(getLocalLanguage() == lg_zhcn) alert("更新参数不正确!"); else alert("Bad ccupdate parameter!"); } else if(param == "1") { var rt; if(getLocalLanguage() == lg_zhcn) rt = confirm("检测到服务器上有新的版本,确认你是否要更新?"); else rt = confirm("There are a new version,would you like to update?"); if(rt == true) { this._cmdParam2 = "update"; this._InvokeMethod(APSP_UpdateSetup_CONF,GetApspParam(this._cmdParam1,this._cmdParam2)); } } else if(param == "0"){ if(getLocalLanguage() == lg_zhcn) alert("没有新的版本需要更新!"); else alert("There are no new version!"); } this.oGuradWS.WSDisconnect(); } this._ctrlStatus == barStatus_GuardDisconnecting; this._cmdType = cmd_GuardType_Null; this._cmdParam1 = ""; this._cmdParam2 = ""; this._connectCount = 0; } this.apspCallbackGurad = function apspCallbackGurad(cmdType,cmdIndex,param){ if(cmdType == APSP_Type_Prompt){ this.oParent.OnGuardWebSocketEvent(cmdIndex,param); } else if(cmdType == APSP_Type_Action) { this.oParent.OnGuardWebSocketActionEvent(cmdIndex,param); } } this._Create(); return this; }