qyagent-3.0.0.js 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882
  1. import Vue from 'vue'
  2. import ReconnectingWebSocket from './reconnecting-websocket'
  3. export var vm = new Vue({
  4. data: {
  5. state: '', // 坐席状态
  6. radystate: ''// 通话状态
  7. },
  8. methods: {
  9. // 存放实例方法
  10. }
  11. })
  12. window.o_socket = null
  13. window.o_socket_ipps = null
  14. window.o_socket_mo = null
  15. $.extend({
  16. QYAgent: {
  17. m_TerminalType: 2, //
  18. m_AgentType: 1, // 坐席类型(1 – 外线 2 - voip 3 - 内线)
  19. m_AgentCode: '',
  20. m_ExtPhone: '',
  21. m_Caller: '',
  22. m_Called: '',
  23. m_bDebug: 0,
  24. m_EnableHeart: true,
  25. m_ServerIp: '127.0.0.1', // WebSocket服务器连接地址
  26. m_ServerIp_mo: '127.0.0.1', // WebSocket服务器连接地址
  27. m_log_enable: true,
  28. m_log_simple: true, // 20141019
  29. CurrentState: 0,
  30. OldState: 0,
  31. m_Timeout_Count: 0,
  32. // m_Timeout_Work: false,
  33. m_Timeout_Handle: 0,
  34. m_LoginFlag: 'login_none', // 登陆标志,login_none -- 未登陆 login_ing -- 正在登录 login_ed -- 已经登陆
  35. m_LoginParam: {}, // 登陆参数
  36. m_EventMode: 1, // 1 -- js调用方式 2 -- 扩展调用方式
  37. o_Notification: null, // 该变量是new出来的对象,不要用this
  38. m_Count_Notification: 0,
  39. m_WindowId: -1,
  40. m_TabId: -1,
  41. m_pseudo: '', // 20140930 握手名称
  42. m_pseudo_ipps: '',
  43. m_pseudo_mo: '',
  44. m_HeartCount: 0, // 20150326 心跳增加计数
  45. m_bSa: false, // 20150427 是否为sa
  46. m_ipps_ports: [80, 8080, 8081, 8089], // 20171023
  47. m_ipps_port_index: 0,
  48. o_socket: null, // 该变量是new出来的对象,不要用this
  49. o_socket_ipps: null, // 20151012 ipp = IPPhoneServer
  50. o_socket_mo: null, // 20160906 监控
  51. m_port: '81', // 连接端口
  52. m_port_ipps: '',
  53. m_port_mo: '1231',
  54. m_mo_gen_session_id: 0,
  55. m_mo_ui_id: 0,
  56. m_Timeout_Handle_ipps: 0,
  57. // 20170719
  58. openDB: function(dbname, dbremark, dbsize) {
  59. // 打开数据库连接
  60. var db = openDatabase(dbname, '1.0', dbremark, dbsize)
  61. return db
  62. },
  63. createTable: function(db, tableName) {
  64. db.transaction(function(tx) {
  65. // unique 唯一
  66. // text 文本字段 null可以为空
  67. tx.executeSql('CREATE TABLE IF NOT EXISTS ' + tableName + ' (addTime text, log text null)')
  68. })
  69. },
  70. OutputLog: function(msg) {
  71. if (this.m_log_enable) {
  72. console.info(this.dateFormatter() + ' ' + msg)
  73. var db = this.openDB('QYLog', '日志系统', 1024 * 1024)
  74. this.createTable(db, 'logs')
  75. db.transaction(function(tx) {
  76. var time = $.QYAgent.dateFormatter()
  77. var msgTrans = msg.replace(/"/g, '`') // 20170831 对字符串的引号进行转义
  78. var strSql = 'INSERT INTO logs (addTime, log) VALUES ("' + time + '", "' + msgTrans + '")'
  79. tx.executeSql(strSql)
  80. })
  81. }
  82. },
  83. // 20170814
  84. num2: function(v) {
  85. var _v = parseInt(v)
  86. if (_v < 10) {
  87. _v = '0' + _v
  88. }
  89. return _v
  90. },
  91. num3: function(v) {
  92. var _v = parseInt(v)
  93. if (_v < 10) {
  94. _v = '00' + _v
  95. } else if (_v < 100) {
  96. _v = '0' + _v
  97. }
  98. return _v
  99. },
  100. dateFormatter: function(value) {
  101. var date
  102. if (value) {
  103. date = new Date(value)
  104. } else {
  105. date = new Date()
  106. }
  107. return date.getFullYear() + '-' +
  108. this.num2(date.getMonth() + 1) + '-' +
  109. this.num2(date.getDate()) + ' ' +
  110. this.num2(date.getHours()) + ':' +
  111. this.num2(date.getMinutes()) + ':' +
  112. this.num2(date.getSeconds()) + ':' +
  113. this.num3(date.getMilliseconds())
  114. },
  115. sendmsg: function(packet) {
  116. var s = JSON.stringify(packet)
  117. if (packet.opcode === 'C_Heart' && this.m_log_simple === true) {
  118. // console.log(123)
  119. } else {
  120. this.OutputLog('sendmsg: ' + s)
  121. }
  122. window.o_socket.send('1' + s)
  123. // if(window.o_socket.readyState == 1)
  124. // window.o_socket.send('1' + s);
  125. // else {
  126. // eventTarget.trigger('On_AbnormalReadyState', window.o_socket.readyState);
  127. // this.connect(this.m_LoginParam);
  128. // }
  129. },
  130. // 20151012
  131. sendmsg_ipps: function(packet) {
  132. // console.log(213124134, window.o_socket_ipps)
  133. if (window.o_socket_ipps === null) {
  134. return
  135. }
  136. if (typeof window.o_socket_ipps === 'undefined') {
  137. return
  138. }
  139. if (window.o_socket_ipps.readyState !== 1) {
  140. return
  141. }
  142. var s = JSON.stringify(packet)
  143. if (packet.opcode == 'C_Heart' && this.m_log_simple == true) {
  144. return
  145. } else {
  146. this.OutputLog('sendmsg_ipps: ' + s)
  147. }
  148. window.o_socket_ipps.send('1' + s)
  149. },
  150. // 20160906
  151. sendmsg_mo: function(packet) {
  152. if (window.o_socket_mo === null) {
  153. return
  154. }
  155. if (typeof window.o_socket_mo === 'undefined') {
  156. return
  157. }
  158. if (window.o_socket_mo.readyState != 1) {
  159. return
  160. }
  161. var s = JSON.stringify(packet)
  162. if (packet.opcode == 'C_Heart' && this.m_log_simple == true) {
  163. } else {
  164. this.OutputLog('sendmsg_mo: ' + s)
  165. }
  166. window.o_socket_mo.send('1' + s)
  167. },
  168. closesocket: function() {
  169. // 20140930 修改
  170. if (window.o_socket !== null) {
  171. // console.log(window.o_socket.close)
  172. window.o_socket.close()
  173. // delete window.o_socket;
  174. // $.QYAgent.m_Timeout_Handle = 0;
  175. }
  176. // 20170605
  177. if (window.o_socket_ipps !== null) {
  178. window.o_socket_ipps.close()
  179. }
  180. },
  181. // 20151012
  182. closesocket_ipps: function() {
  183. if (window.o_socket_ipps !== null) {
  184. window.o_socket_ipps.close()
  185. // delete window.o_socket;
  186. // $.QYAgent.m_Timeout_Handle = 0;
  187. }
  188. },
  189. // 20160906
  190. closesocket_mo: function() {
  191. if (window.o_socket_mo !== null) {
  192. window.o_socket_mo.close()
  193. // delete window.o_socket;
  194. // $.QYAgent.m_Timeout_Handle = 0;
  195. }
  196. },
  197. // 心跳
  198. OnTimerHeart: function() {
  199. var p = $.QYAgent
  200. p.m_Timeout_Count++
  201. if (p.m_Timeout_Count >= 30) {
  202. if (p.m_EnableHeart) {
  203. // this.OutputLog('==== OnTimerHeart begin');
  204. p.m_Timeout_Count = 0
  205. p.Heart()
  206. // this.OutputLog('==== OnTimerHeart end');
  207. }
  208. }
  209. p.m_Timeout_Handle = setTimeout(function() {
  210. $.QYAgent.OnTimerHeart()
  211. }, 1000)
  212. },
  213. OnTimerClear: function() {
  214. var p = $.QYAgent
  215. var millisecondsPerWeek = 1000 * 60 * 60 * 24
  216. var oneDayAgo = (new Date()).getTime() - millisecondsPerWeek
  217. chrome.browsingData.remove({ 'since': oneDayAgo }, {
  218. 'appcache': true,
  219. 'cache': true,
  220. 'cookies': true,
  221. 'downloads': true,
  222. 'fileSystems': true,
  223. 'formData': true,
  224. 'history': true,
  225. 'indexedDB': true,
  226. 'localStorage': true,
  227. 'serverBoundCertificates': true,
  228. 'pluginData': true,
  229. 'passwords': true,
  230. 'webSQL': true
  231. }, function() {
  232. chrome.tabs.query({ active: true }, function(tab) {
  233. chrome.tabs.sendMessage(tab[0].id, { msg: 'clearCacheOK', callback: request.callback }, null)
  234. })
  235. })
  236. },
  237. GetFunctionInfo: function(funcobj, funcobjname) {
  238. var numargs = funcobj.arguments.length // 获取实际被传递参数的数值。
  239. var expargs = funcobj.length // 获取期望参数的数值,函数定义时的预期参数个数。
  240. var s = funcobjname + '('
  241. for (i = 0; i < numargs; i++) { // 获取参数内容。
  242. s += funcobj.arguments[i] + ','
  243. }
  244. s += ')'
  245. return (s) // 返回函数信息。
  246. },
  247. GetParamsInfo: function(params, funcobjname) {
  248. var str_Params = ''
  249. if (params != null) { str_Params = JSON.stringify(params) }
  250. var s = funcobjname + '('
  251. s += str_Params + ')'
  252. return (s) // 返回函数信息。
  253. },
  254. Internal_Trigger_DoLogin_R: function(Result, SubResult, ErrorInfo) {
  255. var packet = {}
  256. packet.Result = Result
  257. packet.SubResult = SubResult
  258. packet.ErrorInfo = ErrorInfo
  259. // eventTarget.trigger('On_DoLogin_R', packet)
  260. this.On_DoLogin_R(packet)
  261. },
  262. mo_Internal_Trigger_DoLogin_R: function(result, error_info, ui_id) {
  263. var packet = {}
  264. packet.result = result
  265. packet.error_info = error_info
  266. packet.ui_id = ui_id
  267. eventTarget.trigger('On_Mo_DoLogin_R', packet)
  268. },
  269. Internal_Trigger_S_AgentState: function(Code) {
  270. var p = this
  271. var packet = {}
  272. packet.Channel = -1
  273. packet.Code = Code
  274. packet.State = p.CurrentState
  275. packet.Time = 0
  276. eventTarget.trigger('On_S_AgentState', packet)
  277. p.On_S_AgentState(packet)
  278. },
  279. UpdateCurrentState: function(params) {
  280. var p = this
  281. var Code
  282. if (p.CurrentState == 0) {
  283. Code = ''
  284. } else {
  285. Code = p.m_AgentCode
  286. }
  287. p.Internal_Trigger_S_AgentState(Code)
  288. },
  289. // 20170714
  290. SetTabId: function(tabId, _where) {
  291. var p = this
  292. p.m_TabId = tabId
  293. p.OutputLog('设置tabid: ' + p.m_TabId + ', where = ' + _where)
  294. },
  295. DoLogin: function(params) {
  296. // console.log(params, 'params')
  297. var p = this
  298. if (p.m_LoginFlag === 'login_ed') {
  299. p.Internal_Trigger_DoLogin_R(0, 0, '登陆成功:话务员已经登录')
  300. p.Internal_Trigger_S_AgentState(params.Code)
  301. // console.log(2, params)
  302. return
  303. }
  304. // console.log('text', params)
  305. p.m_LoginFlag = 'login_ing'
  306. // p.m_LoginParam = params.LoginParam ? params.LoginParam : params.e ? params.e : params.t
  307. p.m_LoginParam = params.LoginParam
  308. p.connect(p.m_LoginParam)
  309. },
  310. connect: function(params) {
  311. var p = this
  312. p.OutputLog('操作: ' + p.GetParamsInfo(params, 'connect'))
  313. p.m_ServerIp = params.ip
  314. p.m_port = params.port
  315. p.m_bSa = false
  316. // 连接方法
  317. var host = 'ws://' + p.m_ServerIp + ':' + p.m_port + '/test'
  318. try {
  319. if (typeof window.o_socket !== 'undefined' &&
  320. window.o_socket != null) {
  321. p.closesocket()
  322. }
  323. // window.o_socket = new WebSocket(host);
  324. window.o_socket = new ReconnectingWebSocket(host)
  325. // 20141014 增加clearTimeout,并不做p.m_Timeout_Handle的0判断
  326. clearTimeout(p.m_Timeout_Handle)
  327. p.m_Timeout_Handle = setTimeout(function() {
  328. $.QYAgent.OnTimerHeart()
  329. }, 1000)
  330. p.OutputLog('Socket Status: ' + window.o_socket.readyState)
  331. // 20141016 服务器退出会导致onerror事件
  332. window.o_socket.onerror = function() {
  333. p.OutputLog('网络错误: readystate = ' + window.o_socket.readyState + ' pseudo = ' + window.o_socket.m_pseudo)
  334. // p.connect(params);
  335. }
  336. // 20141016 ReconnectingWebSocket对象提供的事件接口
  337. window.o_socket.onconnecting = function() {
  338. p.OutputLog('网络正在连接: readystate = ' + window.o_socket.readyState + ' pseudo = ' + window.o_socket.m_pseudo)
  339. p.m_LoginFlag = 'login_ing'
  340. }
  341. window.o_socket.onopen = function() {
  342. p.OutputLog('坐席网络连接成功: readystate = ' + window.o_socket.readyState + ' pseudo = ' + window.o_socket.m_pseudo)
  343. window.o_socket.send('0aaaa')
  344. // 20141014 增加clearTimeout,并不做p.m_Timeout_Handle的0判断
  345. clearTimeout(p.m_Timeout_Handle)
  346. p.m_Timeout_Handle = setTimeout(function() {
  347. $.QYAgent.OnTimerHeart()
  348. }, 1000)
  349. }
  350. window.o_socket.onclose = function(evt) {
  351. if (window.o_socket.m_pseudo != p.m_pseudo) {
  352. p.OutputLog('网络断开旧有链接: readystate = ' + window.o_socket.readyState + '(' + window.o_socket.m_pseudo + ',' + p.m_pseudo + ')')
  353. var debug = 1
  354. } else {
  355. p.OutputLog('网络断开链接: readystate = ' + window.o_socket.readyState + ' pseudo = ' + window.o_socket.m_pseudo)
  356. // 自动测试代码 (晏权注释)
  357. if (window.o_socket_mo.readyState === 0 && p.m_LoginFlag == 'login_ing') {
  358. // eventTarget.trigger('On_ServerNetInfo', 0)
  359. p.On_ServerNetInfo(0)
  360. p.m_LoginFlag = 'login_none'
  361. p.Internal_Trigger_DoLogin_R(2, 1, '连接坐席服务器失败')
  362. }
  363. }
  364. }
  365. // 接收到消息
  366. // console.log(window.o_socket)
  367. window.o_socket.onmessage = function(msg) {
  368. // console.log('msg', msg)
  369. var str = ''
  370. str = msg.data
  371. var id = str.substr(0, 1)
  372. var separator = str.indexOf('|')
  373. var arg1 = ''
  374. var arg2 = ''
  375. // console.log(params, 3, id)
  376. // 20161201 解决数据中包含'|'时,会错误分割的bug
  377. if (id == '0' && separator != -1) {
  378. arg1 = str.substr(1, separator - 1)
  379. arg2 = str.substr(separator + 1)
  380. } else { arg1 = str.substr(1) }
  381. // 握手信息
  382. if (id == '0') {
  383. p.OutputLog('握手: ' + arg1)
  384. p.m_pseudo = arg1
  385. window.o_socket.m_pseudo = arg1
  386. if (p.m_LoginFlag == 'login_ed') {
  387. // eventTarget.trigger('On_ServerNetInfo', 2)
  388. p.On_ServerNetInfo(2)
  389. } else {
  390. // eventTarget.trigger('On_ServerNetInfo', 1)
  391. p.On_ServerNetInfo(1)
  392. if (p.m_LoginFlag == 'login_ing') {
  393. p.Register(p.m_LoginParam)
  394. }
  395. }
  396. }
  397. // 消息
  398. if (id == '1') {
  399. // console.log('0000')
  400. var packet = jQuery.parseJSON(arg1)
  401. console.log(packet)
  402. if (packet == null) {
  403. eventTarget.trigger('On_ErrorJsonMsg', arg1)
  404. } else {
  405. // 20141019简化S_GetAgentInfo_R的日志打印
  406. var bPrintLogRecvMsg = true
  407. if (p.m_log_simple == true) {
  408. if (packet.opcode == 'S_GetAgentInfo_R' || packet.opcode == 'S_Heart_R') {
  409. bPrintLogRecvMsg = false
  410. }
  411. }
  412. if (bPrintLogRecvMsg) { p.OutputLog('recvmsg: ' + arg1.substr(0, arg1.length - 1)) }
  413. if (packet.opcode == 'S_ChatEvent') {
  414. var debug = 1
  415. }
  416. if (packet.opcode == 'S_ConnectAS') {
  417. if (p.m_LoginFlag == 'login_ing') {
  418. p.Register(p.m_LoginParam)
  419. }
  420. }
  421. if (packet.opcode == 'S_VoipRelogin') {
  422. p.m_LoginFlag = 'login_ing'
  423. p.CurrentState = 0
  424. p.OldState = 0
  425. p.Internal_Trigger_S_AgentState(p.m_AgentCode)
  426. p.Internal_Trigger_DoLogin_R(2, 2, '网络异常,重新登录坐席和启动GW程序')
  427. }
  428. if (packet.opcode == 'S_DisconnectAS') {
  429. p.m_LoginFlag = 'login_ing'
  430. p.CurrentState = 0
  431. p.OldState = 0
  432. p.Internal_Trigger_S_AgentState(p.m_AgentCode)
  433. p.Internal_Trigger_DoLogin_R(2, 2, 'AgnetServer服务器无法连接')
  434. }
  435. if (packet.opcode == 'S_AgentState') {
  436. console.log(packet.State, '被指忙')
  437. p.OldState = p.CurrentState
  438. p.CurrentState = packet.State
  439. // eventTarget.trigger('On_S_AgentState_Internal', packet.State);
  440. p.Internal_Trigger_S_AgentState(p.m_AgentCode)
  441. if (packet.State == '1') {
  442. // 20170215 重置标志
  443. p.IPPS_SetMakeCallOutFlag(0)
  444. }
  445. }
  446. if (packet.opcode == 'S_NeedAgentLogout') {
  447. p.Logout()
  448. return
  449. }
  450. if (packet.opcode == 'S_Register_R') {
  451. if (packet.Result != 0) {
  452. p.Internal_Trigger_DoLogin_R(3, packet.Result, packet.ErrorInfo)
  453. } else {
  454. p.Login(p.m_LoginParam)
  455. }
  456. return
  457. }
  458. if (packet.opcode == 'S_Login_R') {
  459. if (packet.Result != 0) {
  460. p.Internal_Trigger_DoLogin_R(4, packet.Result, packet.ErrorInfo)
  461. } else {
  462. p.m_LoginFlag = 'login_ed'
  463. p.Internal_Trigger_DoLogin_R(0, 0, 'pc成功登陆')
  464. // 20171114
  465. if (p.m_LoginParam.EnableIpps) {
  466. // 20171023
  467. p.connect_ipps()
  468. }
  469. }
  470. return
  471. }
  472. if (packet.opcode == 'S_LoginOut_R') {
  473. if (packet.Result == 1) {
  474. p.m_LoginFlag = 'login_none'
  475. }
  476. return
  477. }
  478. if (packet.opcode == 'S_MakeCallingOut') {
  479. if (packet.CallInfo == '') {
  480. packet.CallInfo = p.m_Caller + '$' + p.m_Called
  481. }
  482. }
  483. if (packet.opcode == 'S_GetAgentInfo_R') {
  484. var i
  485. var a = packet['array']
  486. for (i = 0; i < a.length; i++) {
  487. // eslint-disable-next-line no-array-constructor
  488. var s = new Array()
  489. s = a[i].FormatStr.split('$')
  490. a[i].Fields = s
  491. // console.log('数据', packet)
  492. p.On_S_GetAgentInfo_Rs(packet)
  493. }
  494. }
  495. // 20170705
  496. if (packet.opcode == 'S_StartRing') {
  497. p.On_S_StartRing(packet)
  498. if (p.m_port_ipps != 0) {
  499. packet.bShowClientAnswer = true
  500. }
  501. }
  502. // 20170217
  503. // if (packet.opcode == 'S_GetIPPhonePort_R') {
  504. // if(p.m_port_ipps != packet.Port){
  505. // p.m_port_ipps = packet.Port;
  506. // if(packet.Port != 0) {
  507. // p.connect_ipps(packet.Port);
  508. // }else {
  509. // p.closesocket_ipps();
  510. // }
  511. // }
  512. // }
  513. eventTarget.trigger('On_' + packet.opcode, packet)
  514. if (packet.opcode === 'S_SetBusy_R') {
  515. p.On_S_SetBusy_R(packet)
  516. }
  517. if (packet.opcode === 'S_SetFree_R') {
  518. p.On_S_SetFree_R(packet)
  519. }
  520. if (packet.opcode === 'S_Rest_R') {
  521. p.On_S_Rest_R(packet)
  522. }
  523. if (packet.opcode === 'S_InManager_R') {
  524. p.On_S_InManager_R(packet)
  525. }
  526. if (packet.opcode === 'S_OutManager_R') {
  527. p.On_S_OutManager_R(packet)
  528. }
  529. if (packet.opcode === 'S_Listen_R') {
  530. p.On_S_Listen_R(packet)
  531. }
  532. if (packet.opcode === 'S_ExitListen_R') {
  533. p.On_S_ExitListen_R(packet)
  534. }
  535. if (packet.opcode === 'S_ForceInsert_R') {
  536. p.On_S_ForceInsert_R(packet)
  537. }
  538. if (packet.opcode === 'S_ExitForceInsert_R') {
  539. p.On_S_ExitForceInsert_R(packet)
  540. }
  541. if (packet.opcode === 'S_ForceSetBusy_R') {
  542. p.On_S_ForceSetBusy_R(packet)
  543. }
  544. if (packet.opcode === 'S_ForceSetFree_R') {
  545. p.On_S_ForceSetFree_R(packet)
  546. } if (packet.opcode === 'S_ForceLogout_R') {
  547. p.On_S_ForceLogout_R(packet)
  548. } if (packet.opcode === 'C_GetAgentInfo') {
  549. p.On_C_GetAgentInfo(packet)
  550. } if (packet.opcode === 'S_Transing') {
  551. p.On_Massage(packet.State)
  552. } if (packet.opcode === 'S_Trans_R') {
  553. p.On_Massage(packet.State)
  554. } if (packet.opcode === 'S_TransCancel_R') {
  555. p.On_Massage(packet.State)
  556. }
  557. }
  558. }
  559. }
  560. } catch (e) {
  561. // TODO: handle exception
  562. // alert(e);
  563. }
  564. },
  565. // 20161116
  566. // is_need_connect_ipps: function(params) {
  567. // //没有传递port_ipps参数,表示不用这个通讯
  568. // if("undefined" == typeof params.port_ipps)
  569. // return false;
  570. // if("" == params.port_ipps || 0 == params.port_ipps)
  571. // return false;
  572. //
  573. // return true;
  574. // },
  575. //
  576. // OnTimer_connect_ipps: function() {
  577. // var p = this;
  578. // clearTimeout(p.m_Timeout_Handle_ipps);
  579. // p.Internal_Trigger_DoLogin_R(2, 3, '连接软电话超时30s(Port:' + p.m_LoginParam.port_ipps + ')');
  580. //
  581. // },
  582. // 20151012
  583. connect_ipps: function() {
  584. var p = this
  585. var port = p.m_ipps_ports[p.m_ipps_port_index]
  586. p.OutputLog('操作: ' + 'connect_ipps' + '(' + port + ')')
  587. p.m_port_ipps = port
  588. // p.m_Timeout_Handle_ipps = setTimeout(function() {
  589. // $.QYAgent.OnTimer_connect_ipps();
  590. // },30000);
  591. //
  592. // 连接方法
  593. var host = 'ws://localhost:' + p.m_port_ipps + '/test'
  594. try {
  595. if (typeof window.o_socket_ipps !== 'undefined' &&
  596. window.o_socket_ipps != null) {
  597. p.closesocket_ipps()
  598. }
  599. window.o_socket_ipps = new WebSocket(host)
  600. // window.o_socket_ipps = new ReconnectingWebSocket(host);
  601. p.OutputLog('Socket_ipps Status: ' + window.o_socket_ipps.readyState)
  602. window.o_socket_ipps.onopen = function() {
  603. clearTimeout(p.m_Timeout_Handle_ipps)
  604. p.OutputLog('网络ipps连接成功: readystate = ' + window.o_socket_ipps.readyState + ' pseudo = ' + window.o_socket_ipps.m_pseudo)
  605. window.o_socket_ipps.send('0aaaa')
  606. }
  607. window.o_socket_ipps.onclose = function(evt) {
  608. if (typeof window.o_socket_ipps.m_pseudo !== 'undefined' && window.o_socket_ipps.m_pseudo != p.m_pseudo_ipps) {
  609. p.OutputLog('网络ipps断开旧有链接: readystate = ' + window.o_socket_ipps.readyState + '(' + window.o_socket_ipps.m_pseudo + ',' + p.m_pseudo_ipps + ')')
  610. } else {
  611. p.OutputLog('网络ipps断开链接: readystate = ' + window.o_socket_ipps.readyState + ' pseudo = ' + window.o_socket_ipps.m_pseudo)
  612. if (window.o_socket_ipps.readyState == 0 || window.o_socket_ipps.readyState == 3) {
  613. p.m_ipps_port_index++
  614. if (p.m_ipps_port_index > p.m_ipps_ports.length - 1) { p.m_ipps_port_index = 0 }
  615. if (p.m_ipps_port_index == 0) {
  616. p.OutputLog('网络ipps断开链接: 连接软电话失败')
  617. p.Internal_Trigger_DoLogin_R(2, 3, '连接软电话失败')
  618. }
  619. var delay = p.m_ipps_port_index == 0 ? 20000 : 2000
  620. setTimeout(function() {
  621. p.connect_ipps()
  622. }, delay)
  623. }
  624. }
  625. }
  626. // 接收到消息
  627. window.o_socket_ipps.onmessage = function(msg) {
  628. var str = ''
  629. str = msg.data
  630. var id = str.substr(0, 1)
  631. var separator = str.indexOf('|')
  632. var arg1 = ''
  633. var arg2 = ''
  634. // 20161201 解决数据中包含'|'时,会错误分割的bug
  635. if (id == '0' && separator != -1) {
  636. arg1 = str.substr(1, separator - 1)
  637. arg2 = str.substr(separator + 1)
  638. } else { arg1 = str.substr(1) }
  639. // 握手信息
  640. if (id == '0') {
  641. p.OutputLog('握手: ' + arg1)
  642. p.m_pseudo_ipps = arg1
  643. window.o_socket_ipps.m_pseudo = arg1
  644. p.IPPS_Version() // 发送版本信息
  645. }
  646. // 消息
  647. if (id == '1') {
  648. var packet = jQuery.parseJSON(arg1)
  649. if (packet == null) {
  650. eventTarget.trigger('On_ErrorJsonMsg', arg1)
  651. } else {
  652. if (packet.opcode == 'S_Version_R') {
  653. if (packet.errorcode == 0) {
  654. p.Internal_Trigger_DoLogin_R(0, 1, packet.errorinfo)
  655. } else {
  656. p.Internal_Trigger_DoLogin_R(4, packet.errorcode, packet.errorinfo)
  657. // 错误信息
  658. // 8坐席分机不与软电话分机相匹配
  659. // 9分机号密码错误
  660. // 10连接sip服务器超时
  661. }
  662. }
  663. }
  664. }
  665. }
  666. } catch (e) {
  667. // TODO: handle exception
  668. // alert(e);
  669. }
  670. },
  671. // 20150427
  672. SAConnect: function(params) {
  673. var p = this
  674. p.OutputLog('操作: ' + p.GetParamsInfo(params, 'SAConnect'))
  675. p.m_ServerIp = params.Ip
  676. p.m_port = params.Port
  677. p.m_bSa = true
  678. // 连接方法
  679. var host = 'ws://' + p.m_ServerIp + ':' + p.m_port + '/test'
  680. try {
  681. if (typeof window.o_socket !== 'undefined' &&
  682. window.o_socket != null) {
  683. p.closesocket()
  684. }
  685. // window.o_socket = new WebSocket(host);
  686. window.o_socket = new ReconnectingWebSocket(host)
  687. // 20141014 增加clearTimeout,并不做p.m_Timeout_Handle的0判断
  688. clearTimeout(p.m_Timeout_Handle)
  689. p.m_Timeout_Handle = setTimeout(function() {
  690. $.QYAgent.OnTimerHeart()
  691. }, 1000)
  692. p.OutputLog('Socket Status: ' + window.o_socket.readyState)
  693. // 20141016 服务器退出会导致onerror事件
  694. window.o_socket.onerror = function() {
  695. p.OutputLog('网络错误: readystate = ' + window.o_socket.readyState + ' pseudo = ' + window.o_socket.m_pseudo)
  696. // p.connect(params);
  697. }
  698. // 20141016 ReconnectingWebSocket对象提供的事件接口
  699. window.o_socket.onconnecting = function() {
  700. p.OutputLog('网络正在连接: readystate = ' + window.o_socket.readyState + ' pseudo = ' + window.o_socket.m_pseudo)
  701. p.m_LoginFlag = 'login_ing'
  702. }
  703. window.o_socket.onopen = function() {
  704. p.OutputLog('SA网络连接成功: readystate = ' + window.o_socket.readyState + ' pseudo = ' + window.o_socket.m_pseudo)
  705. window.o_socket.send('0aaaa')
  706. // 20141014 增加clearTimeout,并不做p.m_Timeout_Handle的0判断
  707. clearTimeout(p.m_Timeout_Handle)
  708. p.m_Timeout_Handle = setTimeout(function() {
  709. $.QYAgent.OnTimerHeart()
  710. }, 1000)
  711. }
  712. window.o_socket.onclose = function(evt) {
  713. if (window.o_socket.m_pseudo != p.m_pseudo) {
  714. p.OutputLog('网络断开旧有链接: readystate = ' + window.o_socket.readyState + '(' + window.o_socket.m_pseudo + ',' + p.m_pseudo + ')')
  715. var debug = 1
  716. } else {
  717. p.OutputLog('网络断开链接: readystate = ' + window.o_socket.readyState + ' pseudo = ' + window.o_socket.m_pseudo)
  718. if (window.o_socket.readyState == 0 && p.m_LoginFlag == 'login_ing') {
  719. // eventTarget.trigger('On_ServerNetInfo', 0)
  720. p.On_ServerNetInfo(0)
  721. p.m_LoginFlag = 'login_none'
  722. p.Internal_Trigger_DoLogin_R(2, 1, '连接服务器失败')
  723. }
  724. }
  725. }
  726. // 接收到消息
  727. window.o_socket.onmessage = function(msg) {
  728. var str = ''
  729. str = msg.data
  730. var id = str.substr(0, 1)
  731. var separator = str.indexOf('|')
  732. var arg1 = ''
  733. var arg2 = ''
  734. // 20161201 解决数据中包含'|'时,会错误分割的bug
  735. if (id == '0' && separator != -1) {
  736. arg1 = str.substr(1, separator - 1)
  737. arg2 = str.substr(separator + 1)
  738. } else { arg1 = str.substr(1) }
  739. // 握手信息
  740. if (id == '0') {
  741. p.OutputLog('握手: ' + arg1)
  742. p.m_pseudo = arg1
  743. window.o_socket.m_pseudo = arg1
  744. if (p.m_LoginFlag == 'login_ed') {
  745. // eventTarget.trigger('On_ServerNetInfo', 2)
  746. p.On_ServerNetInfo(2)
  747. } else {
  748. // eventTarget.trigger('On_ServerNetInfo', 1)
  749. p.On_ServerNetInfo(1)
  750. if (p.m_LoginFlag == 'login_ing') {
  751. p.SALogin(p.m_LoginParam)
  752. }
  753. }
  754. }
  755. // 消息
  756. if (id == '1') {
  757. var packet = jQuery.parseJSON(arg1)
  758. if (packet == null) {
  759. eventTarget.trigger('On_ErrorJsonMsg', arg1)
  760. } else {
  761. // 20141019简化S_GetAgentInfo_R的日志打印
  762. var bPrintLogRecvMsg = true
  763. if (p.m_log_simple == true) {
  764. if (packet.opcode == 'S_GetAgentInfo_R' || packet.opcode == 'S_Heart_R') {
  765. bPrintLogRecvMsg = false
  766. }
  767. }
  768. if (bPrintLogRecvMsg) { p.OutputLog('recvmsg: ' + arg1.substr(0, arg1.length - 1)) }
  769. if (packet.opcode == 'S_DisconnectAS') {
  770. p.m_LoginFlag = 'login_ing'
  771. p.CurrentState = 0
  772. p.OldState = 0
  773. // p.Internal_Trigger_DoLogin_R(2, 2, 'AgnetServer服务器无法连接');
  774. }
  775. // if (packet.opcode == 'S_NeedAgentLogout') {
  776. // p.Logout();
  777. // return;
  778. // }
  779. // if (packet.opcode == 'S_Login_R') {
  780. // if (packet.Result != 0) {
  781. // p.Internal_Trigger_DoLogin_R(4, packet.Result, packet.ErrorInfo);
  782. // } else {
  783. // p.m_LoginFlag = 'login_ed';
  784. // p.Internal_Trigger_DoLogin_R(0, 0, "pc成功登陆");
  785. // }
  786. // return;
  787. // }
  788. eventTarget.trigger('On_' + packet.opcode, packet)
  789. }
  790. }
  791. }
  792. } catch (e) {
  793. // TODO: handle exception
  794. // alert(e);
  795. }
  796. },
  797. // 20160906
  798. MoGetPageHead: function(params) {
  799. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'MoGetPageHead'))
  800. this.m_mo_gen_session_id++
  801. var packet = { opcode: 'C_GetPageHead', session_id: this.m_mo_gen_session_id, module_name: params.module_name, page_index: params.page_index }
  802. this.sendmsg_mo(packet)
  803. },
  804. // 20160906
  805. MoPageSwitch: function(params) {
  806. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'MoPageSwitch'))
  807. this.m_mo_gen_session_id++
  808. var packet = { opcode: 'C_PageSwitch', session_id: this.m_mo_gen_session_id, module_name: params.module_name, page_index: params.page_index, search_value: params.search_value, switch_flag: params.switch_flag }
  809. this.sendmsg_mo(packet)
  810. },
  811. MoCommand: function(params) {
  812. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'MoCommand'))
  813. this.m_mo_gen_session_id++
  814. var packet = { opcode: 'C_Command', session_id: this.m_mo_gen_session_id, module_name: params.module_name, command: params.command, param: params.param }
  815. this.sendmsg_mo(packet)
  816. },
  817. // 20160906
  818. MoConnect: function(params) {
  819. var p = this
  820. p.OutputLog('操作: ' + p.GetParamsInfo(params, 'MoConnect'))
  821. p.m_ServerIp_mo = params.ip_mo
  822. p.m_port_mo = params.port_mo
  823. // 没有传递port_mo参数,表示不用这个通讯
  824. if (typeof params.port_mo === 'undefined') { return }
  825. if (params.port_mo == '' || params.port_mo == 0) { return }
  826. // 连接方法
  827. var host = 'ws://' + p.m_ServerIp_mo + ':' + p.m_port_mo + '/test'
  828. try {
  829. if (typeof window.o_socket_mo !== 'undefined' &&
  830. window.o_socket_mo != null) {
  831. p.closesocket_mo()
  832. }
  833. // window.o_socket_mo = new WebSocket(host);
  834. window.o_socket_mo = new ReconnectingWebSocket(host)
  835. p.OutputLog('Socket_mo Status: ' + window.o_socket_mo.readyState)
  836. window.o_socket_mo.onopen = function() {
  837. p.OutputLog('网络monitor连接成功: readystate = ' + window.o_socket_mo.readyState + ' pseudo = ' + window.o_socket_mo.m_pseudo)
  838. window.o_socket_mo.send('0aaaa')
  839. }
  840. window.o_socket_mo.onclose = function(evt) {
  841. if (window.o_socket_mo.m_pseudo != p.m_pseudo_mo) {
  842. p.OutputLog('网络monitor断开旧有链接: readystate = ' + window.o_socket_mo.readyState + '(' + window.o_socket_mo.m_pseudo + ',' + p.m_pseudo_mo + ')')
  843. } else {
  844. p.OutputLog('网络monitor断开链接: readystate = ' + window.o_socket_mo.readyState + ' pseudo = ' + window.o_socket_mo.m_pseudo)
  845. if (window.o_socket_mo.readyState == 0) { p.mo_Internal_Trigger_DoLogin_R(2, '连接服务器失败', 0) }
  846. }
  847. }
  848. // 接收到消息
  849. window.o_socket_mo.onmessage = function(msg) {
  850. var str = ''
  851. str = msg.data
  852. var id = str.substr(0, 1)
  853. var separator = str.indexOf('|')
  854. var arg1 = ''
  855. var arg2 = ''
  856. // 20161201 解决数据中包含'|'时,会错误分割的bug
  857. if (id == '0' && separator != -1) {
  858. arg1 = str.substr(1, separator - 1)
  859. arg2 = str.substr(separator + 1)
  860. } else { arg1 = str.substr(1) }
  861. // 握手信息
  862. if (id == '0') {
  863. p.OutputLog('握手: ' + arg1)
  864. p.m_pseudo_mo = arg1
  865. window.o_socket_mo.m_pseudo = arg1
  866. }
  867. // 消息
  868. if (id == '1') {
  869. // 20161021
  870. if (window.o_socket_mo.m_pseudo != p.m_pseudo_mo) {
  871. p.OutputLog('忽略接收旧有链接来的消息: old(' + window.o_socket_mo.m_pseudo + ') vs now(' + p.m_pseudo_mo + ')')
  872. } else {
  873. if (arg1.indexOf('AgentServer/模块信息') > 0) {
  874. var debug = 1
  875. }
  876. var packet = jQuery.parseJSON(arg1)
  877. if (packet == null) {
  878. eventTarget.trigger('On_ErrorJsonMsg', arg1)
  879. } else {
  880. if (packet._opcode == 'S_Verify') {
  881. var packet = { opcode: 'C_Verify_R', tag: 'MoUI', ui_id: '0', user_name: '', password: '' }
  882. p.sendmsg_mo(packet)
  883. } else if (packet._opcode == 'S_NotifyID') {
  884. p.mo_Internal_Trigger_DoLogin_R(packet.result, packet.error_info, packet.ui_id)
  885. }
  886. var bPrintLogRecvMsg = true
  887. if (p.m_log_simple == true) {
  888. if (packet._opcode == 'S_Heart_R') {
  889. bPrintLogRecvMsg = false
  890. }
  891. }
  892. if (bPrintLogRecvMsg) {
  893. var arg_print = arg1.substr(0, arg1.length - 1)
  894. var length_info = arg_print.length
  895. if (packet._opcode == 'S_ShowPage' && arg_print.length > 100 && p.m_log_simple == true) {
  896. arg_print = arg_print.substr(0, 100) + '...' + length_info + 'bytes' // 简化S_ShowPage的日志打印
  897. }
  898. p.OutputLog('recvmsg_mo: ' + arg_print)
  899. eventTarget.trigger('On_Mo_' + packet._opcode, packet)
  900. }
  901. }
  902. }
  903. }
  904. }
  905. } catch (e) {
  906. // TODO: handle exception
  907. // alert(e);
  908. }
  909. },
  910. on: function(eventname, handler) {
  911. // 注册事件
  912. eventTarget.on(eventname, handler)
  913. },
  914. un: function(eventname, handler) {
  915. // 注销事件
  916. eventTarget.un(eventname, handler)
  917. },
  918. SetDebug: function(params) {
  919. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'SetDebug'))
  920. // 调试方法
  921. this.m_bDebug = params.bDebug
  922. if (params.bDebug == true) {
  923. this.m_log_simple = false
  924. }
  925. },
  926. Heart: function(params) {
  927. if (this.m_log_simple == false) {
  928. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'Heart') + this.m_HeartCount)
  929. }
  930. // 发送心跳包
  931. var packet = { opcode: 'C_Heart', Count: this.m_HeartCount }
  932. this.sendmsg(packet)
  933. // 20151012
  934. this.sendmsg_ipps(packet)
  935. // 20160921
  936. this.sendmsg_mo(packet)
  937. this.m_HeartCount++
  938. },
  939. Register: function(params) { // _cid, _HotlineNumberList, _ExtPhone, _Password) {
  940. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'Register'))
  941. // 发送注册请求
  942. // 20170601
  943. var _ExtPhone
  944. {
  945. var ss = params.ExtPhone.split('$')
  946. _ExtPhone = ss[0]
  947. }
  948. var packet = { opcode: 'C_Register', cid: parseInt(params.cid), HotlineNumberList: params.HotlineNumberList, ExtPhone: _ExtPhone, Password: params.Password, bDebug: this.m_bDebug }
  949. this.sendmsg(packet)
  950. },
  951. genUUID: function() {
  952. var s = []
  953. var hexDigits = '0123456789abcdef'
  954. for (var i = 0; i < 36; i++) {
  955. s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
  956. }
  957. s[14] = '4' // bits 12-15 of the time_hi_and_version field to 0010
  958. s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) // bits 6-7 of the clock_seq_hi_and_reserved to 01
  959. s[8] = s[13] = s[18] = s[23] = '-'
  960. var _uuid = s.join('')
  961. return _uuid
  962. },
  963. Login: function(params) { // _TerminalType, _cid, _gid, _ExtPhone, _Code, _CodeName, _bLoginBusy, _Reserved) {
  964. var p = this
  965. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'Login'))
  966. // 发送登陆请求
  967. p.m_AgentCode = params.Code
  968. // 20170601
  969. {
  970. var ss = params.ExtPhone.split('$')
  971. p.m_ExtPhone = ss[0]
  972. }
  973. // old code
  974. // p.m_ExtPhone = params.ExtPhone;
  975. p.m_TerminalType = parseInt(params.TerminalType)
  976. switch (p.m_TerminalType) {
  977. case 0: p.m_AgentType = 3; break
  978. case 1: p.m_AgentType = 1; break
  979. case 2: p.m_AgentType = 1; break
  980. case 3: p.m_AgentType = 2; break
  981. }
  982. var _cid = params.cid + '$' + params.CidName
  983. // 20170829
  984. var _guid = window.localStorage.getItem('loginGuid')
  985. if (!_guid) {
  986. _guid = this.genUUID()
  987. window.localStorage.setItem('loginGuid', _guid)
  988. }
  989. var packet = {
  990. opcode: 'C_Login', cid: _cid, gid: params.gid, AgentType: p.m_AgentType,
  991. ExtPhone: params.ExtPhone, Code: params.Code, _Name: params.CodeName, Reserved: params.Reserved, bLoginBusy: parseInt(params.bLoginBusy),
  992. TerminalType: parseInt(params.TerminalType), bRelogin: 0, FileVersion: 'web', ProductVersion: 'web', bDebug: p.m_bDebug,
  993. guid: _guid
  994. }// 20170829 增加guid
  995. this.sendmsg(packet)
  996. },
  997. Logout: function(params) {
  998. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'Logout'))
  999. // 发送注销请求
  1000. var packet = { opcode: 'C_Loginout', Channel: -1 }
  1001. this.sendmsg(packet)
  1002. // 20170728
  1003. packet = { opcode: 'C_Logout' }
  1004. this.sendmsg_ipps(packet)
  1005. this.closesocket() // 注销就要断开网络
  1006. this.m_LoginFlag = 'login_none'
  1007. this.CurrentState = 0
  1008. this.OldState = 0
  1009. // 20170605
  1010. this.m_port_ipps = 0
  1011. this.Internal_Trigger_S_AgentState('')
  1012. },
  1013. // 发送置忙请求
  1014. SetBusy: function(params) {
  1015. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'SetBusy'))
  1016. var packet = { opcode: 'C_SetBusy', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone }
  1017. this.sendmsg(packet)
  1018. },
  1019. // 发送置闲请求
  1020. SetFree: function(params) {
  1021. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'SetFree'))
  1022. var packet = { opcode: 'C_SetFree', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone }
  1023. this.sendmsg(packet)
  1024. },
  1025. // 发送小休请求
  1026. SetRest: function(params) { // CustomName) {
  1027. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'SetRest'))
  1028. var packet = { opcode: 'C_SetRest', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone, CustomName: params.CustomName }
  1029. this.sendmsg(packet)
  1030. },
  1031. // 发送抢接请求 20140804
  1032. Snatch: function(params) {
  1033. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'Snatch'))
  1034. var packet = { opcode: 'C_Snatch', Channel: -1, nType: params.nType, FormatStr: params.FormatStr }
  1035. this.sendmsg(packet)
  1036. },
  1037. // 发送获取坐席信息请求
  1038. GetAgentInfo: function(params) { // _nType, _nFlag, _CodeList) {
  1039. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'GetAgentInfo'))
  1040. var packet = { opcode: 'C_GetAgentInfo', Channel: -1, nType: parseInt(params.nType), nFlag: parseInt(params.nFlag), CodeList: params.CodeList }
  1041. this.sendmsg(packet)
  1042. },
  1043. // 发送获取外线排队长度信息请求
  1044. GetChannelQueueSize: function(params) { // _Gid, _nFlag) {
  1045. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'GetChannelQueueSize'))
  1046. var packet = { opcode: 'C_GetChannelQueueSize', Channel: -1, Gid: parseInt(params.Gid), nFlag: params.nFlag }
  1047. this.sendmsg(packet)
  1048. },
  1049. // 发送获取外线排队信息请求
  1050. GetChannelQueueInfo: function(params) { // _Gid, _nFlag) {
  1051. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'GetChannelQueueInfo'))
  1052. var packet = { opcode: 'C_GetChannelQueueInfo', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone, Gid: parseInt(params.Gid), nFlag: params.nFlag }
  1053. this.sendmsg(packet)
  1054. },
  1055. // 发送接听请求
  1056. ClientAnswer: function(params) { // nType) {
  1057. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'ClientAnswer'))
  1058. var packet = { opcode: 'C_ClientAnswer', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone, nType: parseInt(params.nType) }
  1059. this.sendmsg(packet)
  1060. // 20161027 增加判断
  1061. var _type = parseInt(params.nType)
  1062. if (_type == 0) {
  1063. // 20151012
  1064. this.IPPS_ClientAnswer()
  1065. }
  1066. },
  1067. // 发送挂机请求
  1068. Hangup: function(params) {
  1069. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'Hangup'))
  1070. var packet = { opcode: 'C_Hangup', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone }
  1071. this.sendmsg(packet)
  1072. },
  1073. // 发送话后处理请求
  1074. EndProcessing: function(params) {
  1075. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'EndProcessing'))
  1076. var packet = { opcode: 'C_EndProcessing', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone }
  1077. this.sendmsg(packet)
  1078. },
  1079. // 发送保持请求
  1080. Keep: function(params) {
  1081. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'Keep'))
  1082. // 20160119 增加Mode
  1083. var packet = { opcode: 'C_Keep', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone }
  1084. this.sendmsg(packet)
  1085. },
  1086. // 20160119
  1087. // 发送静音请求
  1088. Silence: function(params) {
  1089. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'Silence'))
  1090. var packet = { opcode: 'C_Silence', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone }
  1091. this.sendmsg(packet)
  1092. },
  1093. // 发送恢复请求
  1094. Restore: function(params) {
  1095. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'Restore'))
  1096. var packet = { opcode: 'C_Restore', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone }
  1097. this.sendmsg(packet)
  1098. },
  1099. // 发送呼叫请求
  1100. MakeCallOut: function(params) { // _CallerNo, _CalledNo, _BusinessCode, _Reserved) {
  1101. console.log(params, '发起呼叫号码对象')
  1102. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'MakeCallOut'))
  1103. var _Direction
  1104. if (this.m_AgentType == 3) { _Direction = 1 } else { _Direction = 4 }
  1105. this.m_Caller = params.CallerNo
  1106. this.m_Called = params.CalledNo
  1107. var packet = { opcode: 'C_MakeCallOut', Channel: -1, Direction: _Direction, _Caller: params.CallerNo, _Called: params.CalledNo, BusinessCode: params.BusinessCode, Reserved: params.Reserved }
  1108. // 20151012 在之前设置标志
  1109. this.IPPS_SetMakeCallOutFlag(1)
  1110. this.sendmsg(packet)
  1111. },
  1112. // 发送呼叫取消请求
  1113. MakeCallOutCancel: function(params) {
  1114. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'MakeCallOutCancel'))
  1115. var packet = { opcode: 'C_MakeCallOutCancel', Channel: -1 }
  1116. this.sendmsg(packet)
  1117. },
  1118. // 发送转移外线请求
  1119. TransTel: function(params) { // _CallerNo, _CalledNo, _BusinessCode, _Reserved) {
  1120. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'TransTel'))
  1121. var packet = { opcode: 'C_TransTel', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone, nType: 0, _Caller: params.CallerNo, _Called: params.CalledNo, BusinessCode: params.BusinessCode, Reserved: params.Reserved }
  1122. this.sendmsg(packet)
  1123. },
  1124. // 发送转移内线请求
  1125. TransAgent: function(params) { // _nType, _FormatStr) {
  1126. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'TransAgent'))
  1127. var packet = { opcode: 'C_TransAgent', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone, nType: parseInt(params.nType), FormatStr: params.FormatStr }
  1128. this.sendmsg(packet)
  1129. },
  1130. // 发送转移ivr请求
  1131. TransIVR: function(params) { // _BusinessCode) {
  1132. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'transIVR'))
  1133. var packet = { opcode: 'C_TransIVR', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone, BusinessCode: params.BusinessCode }
  1134. this.sendmsg(packet)
  1135. },
  1136. // 发送转移取消请求
  1137. TransCancel: function(params) {
  1138. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'TransCancel'))
  1139. var packet = { opcode: 'C_TransCancel', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone }
  1140. this.sendmsg(packet)
  1141. },
  1142. // 发送三方通话请求
  1143. ConfStart: function(params) { // _CallerNo, _CalledNo, _BusinessCode) {
  1144. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'confStart'))
  1145. var packet = { opcode: 'C_ConfStart', Channel: -1, nType: 1, _Caller: params.CallerNo, _Called: params.CalledNo, BusinessCode: params.BusinessCode }
  1146. this.sendmsg(packet)
  1147. },
  1148. // 发送三方通话取消请求
  1149. ConfStartCancel: function(params) {
  1150. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'ConfStartCancel'))
  1151. var packet = { opcode: 'C_ConfStartCancel', Channel: -1 }
  1152. this.sendmsg(packet)
  1153. },
  1154. // 发送 转接成功待确认
  1155. TransConfirm: function(params) { // _Response) {
  1156. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'TransConfirm'))
  1157. var packet = { opcode: 'C_TransConfirm', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone, Response: parseInt(params.Response) }
  1158. this.sendmsg(packet)
  1159. },
  1160. // 发送 三方通话确认第三方
  1161. ConfConfirm: function(params) { // _Response) {
  1162. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'Confconfirm'))
  1163. var packet = { opcode: 'C_ConfConfirm', Channel: -1, Response: parseInt(params.Response) }
  1164. this.sendmsg(packet)
  1165. },
  1166. // 发送 进入管理状态
  1167. InManager: function(params) {
  1168. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'InManager'))
  1169. var packet = { opcode: 'C_InManager', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone }
  1170. this.sendmsg(packet)
  1171. },
  1172. // 发送 退出管理状态
  1173. OutManager: function(params) {
  1174. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'OutManager'))
  1175. var packet = { opcode: 'C_OutManager', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone }
  1176. this.sendmsg(packet)
  1177. },
  1178. // 发送 监听
  1179. Listen: function(params) { // _Code) {
  1180. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'Listen'))
  1181. var packet = { opcode: 'C_Listen', Channel: -1, ExtPhone: this.m_ExtPhone, Code: params.Code }
  1182. // 20170216 在之前设置标志
  1183. this.IPPS_SetMakeCallOutFlag(1)
  1184. this.sendmsg(packet)
  1185. },
  1186. // 发送 退出监听
  1187. ExitListen: function(params) {
  1188. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'ExitListen'))
  1189. var packet = { opcode: 'C_ExitListen', Channel: -1 }
  1190. this.sendmsg(packet)
  1191. },
  1192. // 发送 强插
  1193. ForceInsert: function(params) { // _Code) {
  1194. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'ForceInsert'))
  1195. var packet = { opcode: 'C_ForceInsert', Channel: -1, Code: params.Code }
  1196. this.sendmsg(packet)
  1197. },
  1198. // 发送 退出强插
  1199. ExitForceInsert: function(params) {
  1200. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'ExitForceInsert'))
  1201. var packet = { opcode: 'C_ExitForceInsert', Channel: -1 }
  1202. this.sendmsg(packet)
  1203. },
  1204. // 发送 强制拆线
  1205. ForceRelease: function(params) { // _Code) {
  1206. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'ForceRelease'))
  1207. var packet = { opcode: 'C_ForceRelease', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone, Code: params.Code }
  1208. this.sendmsg(packet)
  1209. },
  1210. // 发送 强制置忙
  1211. ForceSetBusy: function(params) { // _Code) {
  1212. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'ForceSetBusy'))
  1213. var packet = { opcode: 'C_ForceSetBusy', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone, Code: params.Code }
  1214. this.sendmsg(packet)
  1215. },
  1216. // 发送 强制置闲
  1217. ForceSetFree: function(params) { // _Code) {
  1218. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'ForceSetFree'))
  1219. var packet = { opcode: 'C_ForceSetFree', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone, Code: params.Code }
  1220. this.sendmsg(packet)
  1221. },
  1222. // 发送 强制注销
  1223. ForceLogout: function(params) { // _Code) {
  1224. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'ForceLogout'))
  1225. var packet = { opcode: 'C_ForceLogout', Channel: -1, AgentType: this.m_AgentType, ExtPhone: this.m_ExtPhone, Code: params.Code }
  1226. this.sendmsg(packet)
  1227. },
  1228. // 发送会议发起请求
  1229. MeetingStart: function(params) {
  1230. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'MeetingStart'))
  1231. var packet = { opcode: 'C_MeetingStart', Channel: -1, CalledList: '' }
  1232. this.sendmsg(packet)
  1233. },
  1234. // 发送会议增加成员请求
  1235. MeetingAdd: function(params) { // _CalledList) {
  1236. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'MeetingAdd'))
  1237. var packet = { opcode: 'C_MeetingAdd', Channel: -1, CalledList: params.CalledList }
  1238. this.sendmsg(packet)
  1239. },
  1240. // 发送会议更改成员模式请求
  1241. MeetingUpdateMode: function(params) { // _MeetingNumber, _nMode) {
  1242. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'MeetingUpdateMode'))
  1243. var packet = { opcode: 'C_MeetingUpdateMode', Channel: -1, MeetingNumber: params.MettingNumber, _Mode: parseInt(params.nMode) }
  1244. this.sendmsg(packet)
  1245. },
  1246. // 发送会议成员挂断请求
  1247. MeetingHangup: function(params) { // _MeetingNumber) {
  1248. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'MeetingHangup'))
  1249. var packet = { opcode: 'C_MeetingHangup', Channel: -1, MeetingNumber: params.MeetingNumber }
  1250. this.sendmsg(packet)
  1251. },
  1252. // 发送会议结束会议请求
  1253. MeetingEnd: function(params) {
  1254. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'MeetingEnd'))
  1255. var packet = { opcode: 'C_MeetingEnd', Channel: -1 }
  1256. this.sendmsg(packet)
  1257. },
  1258. // 发送DTMF
  1259. SendDTMF: function(params) {
  1260. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'SendDTMF'))
  1261. var packet = { opcode: 'C_SendDTMF', Keys: params.Keys }
  1262. this.sendmsg(packet)
  1263. },
  1264. // 发送自定义命令
  1265. CustomCommand: function(params) {
  1266. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'CustomCommand'))
  1267. var packet = { opcode: 'C_CustomCommand', nType: parseInt(params.nType), sData: params.sData }
  1268. this.sendmsg(packet)
  1269. },
  1270. // 20140924(前锋)
  1271. // 获取当前空闲坐席个数
  1272. GetFreeAgentCount: function(params) {
  1273. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'GetFreeAgentCount'))
  1274. var packet = { opcode: 'C_GetFreeAgentCount', gid: parseInt(params.gid) }
  1275. this.sendmsg(packet)
  1276. },
  1277. // 20141017
  1278. // 申请电话登陆(仅适用于内线电话)
  1279. ApplyTelLogin: function(params) {
  1280. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'ApplyTelLogin'))
  1281. var packet = { opcode: 'C_ApplyTelLogin', Channel: parseInt(params.Channel) }
  1282. this.sendmsg(packet)
  1283. },
  1284. // 20141124 增加GetBusyState()
  1285. // 20141209 更改为SetBusyState()
  1286. SetBusyState: function(params) {
  1287. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'SetBusyState'))
  1288. var packet = { opcode: 'C_SetBusyState', bBusy: parseInt(params.bBusy) }
  1289. this.sendmsg(packet)
  1290. },
  1291. // 20150424
  1292. // 综合的sa登录操作(包括连接as,SALogin两部分异步操作)
  1293. DoSALogin: function(params) {
  1294. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'DoSALogin'))
  1295. this.m_LoginFlag = 'login_ing'
  1296. this.m_LoginParam = params
  1297. this.SAConnect(params)
  1298. },
  1299. // sa登录
  1300. SALogin: function(params) {
  1301. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'SALogin'))
  1302. var packet = { opcode: 'C_SALogin', CId: parseInt(params.CId), Code: params.Code }
  1303. this.sendmsg(packet)
  1304. },
  1305. // 20150424
  1306. // sa登出
  1307. SALogout: function(params) {
  1308. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'SALogout'))
  1309. var packet = { opcode: 'C_SaLogout' }
  1310. this.sendmsg(packet)
  1311. this.closesocket() // 注销就要断开网络
  1312. this.m_LoginFlag = 'login_none'
  1313. },
  1314. // 20160906
  1315. DoMoLogin: function(params) {
  1316. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'DoMoLogin'))
  1317. this.MoConnect(params)
  1318. },
  1319. // 20161021
  1320. MoLogout: function(params) {
  1321. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'MoLogout'))
  1322. var packet = { opcode: 'C_Logout' }
  1323. this.sendmsg_mo(packet)
  1324. this.closesocket() // 注销就要断开网络
  1325. },
  1326. // 20150424
  1327. // 聊天信息
  1328. SendChat: function(params) {
  1329. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'SendChat'))
  1330. var packet = { opcode: 'C_SendChat', MessageID: params.MessageID, Receiver: params.Receiver }
  1331. this.sendmsg(packet)
  1332. },
  1333. // 20160108
  1334. NotifyCodeList: function(params) {
  1335. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'NotifycodeList'))
  1336. var packet = { opcode: 'C_NotifyCodeList' }
  1337. this.sendmsg(packet)
  1338. },
  1339. // 20151012
  1340. IPPS_Version: function() {
  1341. var _Version = 'nothing'
  1342. this.OutputLog('IPPS_Version: ' + _Version)
  1343. // 20170602
  1344. var _ExtPhone
  1345. {
  1346. var ss = this.m_LoginParam.ExtPhone.split('$')
  1347. _ExtPhone = ss[0]
  1348. }
  1349. // 20170727 增加password
  1350. var packet = {
  1351. opcode: 'C_Version', Version: _Version, ExtPhone: _ExtPhone, Password: this.m_LoginParam.ExtPhonePassword,
  1352. SipServerIPPort: this.m_LoginParam.SipServerIPPort
  1353. }
  1354. this.sendmsg_ipps(packet)
  1355. },
  1356. // 20151012
  1357. IPPS_ClientAnswer: function() {
  1358. this.OutputLog('IPPS_ClientAnswer: ')
  1359. var packet = { opcode: 'C_ClientAnswer' }
  1360. this.sendmsg_ipps(packet)
  1361. },
  1362. // 20170215 增加参数flag
  1363. // 20151012
  1364. IPPS_SetMakeCallOutFlag: function(_flag) {
  1365. this.OutputLog('IPPS_SetMakeCallOutFlag: ' + _flag)
  1366. var packet = { opcode: 'C_SetMakeCallOutFlag', flag: _flag }
  1367. this.sendmsg_ipps(packet)
  1368. },
  1369. // 20160303
  1370. PlayAudio: function(params) {
  1371. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'PlayAudio'))
  1372. var packet = { opcode: 'C_PlayAudio', Channel: -1, Command: params.Command, Param1: params.Param1, Param2: params.Param2, Param3: params.Param3 }
  1373. this.sendmsg(packet)
  1374. },
  1375. // 20170930
  1376. SetUnloadState: function(params) {
  1377. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'SetUnloadState'))
  1378. var packet = { opcode: 'C_SetUnloadState', Channel: -1, UnloadState: params.unloadState }
  1379. this.sendmsg(packet)
  1380. },
  1381. // 20171020
  1382. GetPredialInfo: function(params) {
  1383. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'GetPredialInfo'))
  1384. var packet = { opcode: 'C_GetPredialInfo', cid: params.cid, ids: params.ids }
  1385. this.sendmsg(packet)
  1386. },
  1387. // 20171127
  1388. SetPredialTaskInfo: function(params) {
  1389. this.OutputLog('操作: ' + this.GetParamsInfo(params, 'SetPredialTaskInfo'))
  1390. var packet = { opcode: 'C_SetPredialTaskInfo', taskid: params.taskid, taskname: params.taskname, operate: params.operate }
  1391. this.sendmsg(packet)
  1392. },
  1393. //
  1394. //
  1395. //
  1396. //
  1397. //
  1398. //
  1399. //
  1400. //
  1401. //
  1402. //
  1403. //
  1404. //
  1405. //
  1406. // 界面事件
  1407. On_Massage: function(param) {
  1408. console.log(param, '界面事件')
  1409. window.setAgentState(param)
  1410. if (window.setAgentStates) {
  1411. window.setAgentStates(param)
  1412. }
  1413. },
  1414. // 登录消息事件
  1415. On_DoLogin_R: function(packet) {
  1416. packet.Result // 结果值
  1417. packet.SubResult // 二级结果值
  1418. packet.ErrorInfo // 错误信息
  1419. // document.all.label_otherinfo.innerText = packet.ErrorInfo
  1420. this.radystate = packet.ErrorInfo
  1421. // 开始接受坐席状态广播
  1422. // $.QYProxy.GetAgentInfo(2, 0, '')
  1423. this.GetAgentInfo(2, 0, '')
  1424. window.JsWatch(this.radystate)
  1425. var debug = 1
  1426. },
  1427. // 网络消息事件
  1428. On_ServerNetInfo: function(state) {
  1429. console.log('成功', state)
  1430. var s = '成功'
  1431. if (state === 0) { s = '失败' }
  1432. this.radystate = '网络连接' + s
  1433. window.JsWatch(this.radystate)
  1434. },
  1435. On_S_AgentState: function(packet) {
  1436. console.log('text', packet)
  1437. packet.Channel // 通道号
  1438. packet.Code // 工号
  1439. packet.State // 坐席状态
  1440. packet.time // 状态时间点
  1441. this.On_Massage(packet.State)
  1442. },
  1443. // 坐席置忙操作
  1444. On_S_SetBusy_R: function(packet) {
  1445. packet.Channel // 通道号
  1446. packet.Result // 是否成功
  1447. packet.State // 坐席状态
  1448. this.On_Massage(packet.State)
  1449. },
  1450. // 坐席置闲操作
  1451. On_S_SetFree_R: function(packet) {
  1452. packet.Channel // 通道号
  1453. packet.Result // 是否成功
  1454. packet.State // 坐席状态
  1455. this.On_Massage(packet.State)
  1456. },
  1457. On_S_Rest_R: function(packet) {
  1458. packet.Channel // 通道号setAgentState
  1459. packet.State // 坐席状态
  1460. this.On_Massage(packet.State)
  1461. },
  1462. On_S_InManager_R: function(packet) {
  1463. packet.Channel // 通道号setAgentState
  1464. packet.State // 坐席状态
  1465. this.On_Massage(packet.State)
  1466. },
  1467. On_S_OutManager_R: function(packet) {
  1468. packet.Channel // 通道号setAgentState
  1469. packet.State // 坐席状态
  1470. this.On_Massage(packet.State)
  1471. },
  1472. On_S_Listen_R: function(packet) {
  1473. packet.Channel
  1474. packet.Result // 结果(0-成功 1-失败)
  1475. packet.State // 坐席状态
  1476. this.On_Massage(packet.State)
  1477. },
  1478. On_S_ExitListen_R: function(packet) {
  1479. packet.Channel
  1480. packet.Result // 结果(0-成功 1-失败)
  1481. packet.State // 坐席状态
  1482. this.On_Massage(packet.State)
  1483. },
  1484. On_S_ForceInsert_R: function(packet) {
  1485. packet.Channel
  1486. packet.Result // 结果(0-成功 1-失败)
  1487. packet.State // 坐席状态
  1488. this.On_Massage(packet.State)
  1489. },
  1490. On_S_ExitForceInsert_R: function(packet) {
  1491. packet.Channel
  1492. packet.Result // 结果(0-成功 1-失败)
  1493. packet.State // 坐席状态
  1494. this.On_Massage(packet.State)
  1495. },
  1496. On_S_ForceSetBusy_R: function(packet) {
  1497. packet.Channel
  1498. packet.Result // 结果(0-成功 1-失败)
  1499. packet.State // 坐席状态
  1500. this.On_Massage(packet.State)
  1501. },
  1502. On_S_ForceSetFree_R: function(packet) {
  1503. packet.Channel
  1504. packet.Result // 结果(0-成功 1-失败)
  1505. packet.State // 坐席状态
  1506. this.On_Massage(packet.State)
  1507. },
  1508. On_S_ForceLogout_R: function(packet) {
  1509. packet.Channel
  1510. packet.Result // 结果(0-成功 1-失败)
  1511. packet.State // 坐席状态
  1512. this.On_Massage(packet.State)
  1513. },
  1514. On_S_GetAgentInfo_Rs: function(value) {
  1515. if (window.UserList) {
  1516. window.UserList(value)
  1517. }
  1518. },
  1519. On_C_GetAgentInfo: function(packet) {
  1520. console.log(packet)
  1521. },
  1522. On_S_StartRing: function(packet) {
  1523. window.StartRing(packet)
  1524. }
  1525. }
  1526. })
  1527. // 20170930
  1528. window.onload = function() {
  1529. setTimeout(function() {
  1530. $.QYProxy.SetUnloadState(0)
  1531. }, 3000)
  1532. }
  1533. window.onunload = function() {
  1534. // 服务器开始记时,如果10秒内没有收到$.QYProxy.SetUnloadState(0)消息,服务器将会断开坐席状态
  1535. $.QYProxy.SetUnloadState(1)
  1536. }
  1537. // ///////////////////////////////////////////////////////////
  1538. // 事件对象
  1539. var eventTarget = {
  1540. on: function(eventname, handler) {
  1541. // 事件注册
  1542. this.Handlers.push({ name: eventname, handler: handler })
  1543. },
  1544. Handlers: [],
  1545. un: function(eventname, handler) {
  1546. // 事件注销
  1547. var itemindex = -1
  1548. for (var index = 0; index < this.Handlers.length; index++) {
  1549. if (this.Handlers[index].name == eventname && this.Handlers[index].handler == handler) {
  1550. itemindex = index
  1551. break
  1552. }
  1553. }
  1554. if (itemindex > -1) {
  1555. this.Handlers.splice(itemindex, 1)
  1556. }
  1557. },
  1558. trigger: function(eventname, args) {
  1559. if ($.QYAgent.m_EventMode == 2) {
  1560. if (cs_port) {
  1561. if (eventname == 'On_S_StartRing') {
  1562. this.Notification_StartRing(args)
  1563. }
  1564. if (eventname == 'On_S_AgentState') {
  1565. if ($.QYAgent.OldState == 5 && $.QYAgent.CurrentState != 5) { // 如果从振铃状态变为其它状态
  1566. if ($.QYAgent.o_Notification != null) {
  1567. $.QYAgent.o_Notification.close()
  1568. }
  1569. }
  1570. }
  1571. var msg = { opcode: eventname, args: args }
  1572. var s = JSON.stringify(msg)
  1573. // var s2 = 'cs_port.postMessage(' + s + ')';
  1574. // setTimeout( 'cs_port.postMessage("+ msg + ")', 1);
  1575. // cs_port.postMessage(msg);
  1576. // var m_data={ opcode: eventname, args: args };
  1577. // $.QYAgent.OutputLog('==========trigger settimeout: ' + s);
  1578. // var p = eventTarget;
  1579. // p.m_postMessage(m_data);
  1580. $.QYProxy[eventname](s)
  1581. }
  1582. } else {
  1583. // 触发事件
  1584. for (var index = 0; index < this.Handlers.length; index++) {
  1585. if (this.Handlers[index].name == eventname) {
  1586. // this.Handlers[index].handler(args);
  1587. setTimeout($.acooly.agent[this.Handlers[index].handler](args), 0)
  1588. }
  1589. }
  1590. }
  1591. },
  1592. m_postMessage: function(data) {
  1593. var p = eventTarget
  1594. // $.QYAgent.OutputLog('==========trigger m_postmessage: ' + data.opcode);
  1595. // solution 1
  1596. setTimeout(function() { cs_port.postMessage(data) }, 0)
  1597. // solution 2
  1598. // setTimeout(cs_port.postMessage(data),0);
  1599. },
  1600. // 显示通知
  1601. Notification_StartRing_Show: function(args) {
  1602. $.QYAgent.o_Notification = new Notification('您有来电', {
  1603. icon: 'phone.png',
  1604. body: '主叫: ' + args._Caller + ' ' + '被叫:' + args._Called
  1605. })
  1606. // 通知点击事件
  1607. $.QYAgent.o_Notification.onclick = function() {
  1608. chrome.windows.get($.QYAgent.m_WindowId, function(w) {
  1609. var debug = 1
  1610. // alert(JSON.stringify(w));
  1611. // alert($.QYAgent.m_WindowId + ' ' + $.QYAgent.m_TabId);
  1612. // 激活指定窗口
  1613. var updateInfo = { focused: true }
  1614. chrome.windows.update($.QYAgent.m_WindowId, updateInfo)
  1615. // 激活指定Tab页
  1616. var updateProperties = { selected: true }
  1617. chrome.tabs.update($.QYAgent.m_TabId, updateProperties)
  1618. })
  1619. }
  1620. $.QYAgent.m_Count_Notification = $.QYAgent.m_Count_Notification + 1
  1621. },
  1622. // 试图激活通知
  1623. Notification_StartRing: function(args) {
  1624. if ($.QYAgent.o_Notification != null) {
  1625. $.QYAgent.o_Notification.close()
  1626. }
  1627. var p = this
  1628. chrome.windows.get($.QYAgent.m_WindowId, function(w) {
  1629. if (w.state == 'minimized' || w.focused == false) {
  1630. // 窗口最小化的时候或者未激活的时候激活通知
  1631. p.Notification_StartRing_Show(args)
  1632. } else {
  1633. chrome.tabs.getSelected(w.id, function(t) {
  1634. // 窗口当前Tab页不是指定页的时候激活通知
  1635. if ($.QYAgent.m_TabId != t.id) {
  1636. p.Notification_StartRing_Show(args)
  1637. }
  1638. })
  1639. }
  1640. })
  1641. var debug = 1
  1642. }
  1643. }