qyproxy-3.0.0.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. (function($) {
  2. $.extend({
  3. QYProxy: {
  4. m_bLoging: false,
  5. o_LoginParam: '',
  6. m_CurrentState: 0,
  7. Internal_trim: function(str) {
  8. str = str.replace(/^(\s|\u00A0)+/, '')
  9. for (var i = str.length - 1; i >= 0; i--) {
  10. if (/\S/.test(str.charAt(i))) {
  11. str = str.substring(0, i + 1)
  12. break
  13. }
  14. }
  15. return str
  16. },
  17. // 将函数的参数列表转换为Json对象
  18. GetFunctionJsonParamInfo: function(funcobj, funcobjname, newName) {
  19. // 获取参数名称列表
  20. var text = ''
  21. if (newName) {
  22. text = newName.toString()
  23. } else {
  24. text = ''
  25. }
  26. // var pos1 = text.indexOf('(')
  27. // var pos2 = text.indexOf(')')
  28. // text = text.substring(pos1 + 1, pos2)
  29. console.log(text, 'text.......')
  30. var paramnames = text.split(',')
  31. console.log(paramnames, 'paramnamesparamnamesparamnames')
  32. //
  33. var numargs = funcobj.arguments.length // 获取实际被传递参数的数值。
  34. var expargs = funcobj.length // 获取期望参数的数值,函数定义时的预期参数个数。
  35. // expargs 是等于 paramnames数组元素的个数的
  36. var ss = { opcode: funcobjname }
  37. if (paramnames.length != 0) {
  38. ss[this.Internal_trim(paramnames[0])] = funcobj.arguments[0]
  39. for (let i = 1; i < paramnames.length; i++) { // 获取参数内容。
  40. ss[this.Internal_trim(paramnames[i])] = funcobj.arguments[i]
  41. }
  42. }
  43. // var ss = funcobj.arguments[0]
  44. console.log(ss, funcobj.arguments, 'sssssss')
  45. return (ss) // 返回函数信息。
  46. },
  47. dateFormatter: function(value) {
  48. var date
  49. if (value) {
  50. date = new Date(value)
  51. } else {
  52. date = new Date()
  53. }
  54. return date.getFullYear() + '-' +
  55. parseInt(date.getMonth() + 1) + '-' +
  56. parseInt(date.getDate()) + ' ' +
  57. parseInt(date.getHours()) + ':' +
  58. parseInt(date.getMinutes()) + ':' +
  59. parseInt(date.getSeconds()) + ':' +
  60. parseInt(date.getMilliseconds())
  61. },
  62. Internal_postMessage: function(funcobj, funcobjname, newName) {
  63. // console.info(this.dateFormatter() + " ===========0 ---- " + funcobjname);
  64. var s = this.GetFunctionJsonParamInfo(funcobj, funcobjname, newName)
  65. try {
  66. // console.info(this.dateFormatter() + " ===========1 ---- " + funcobjname);
  67. // setTimeout( window.postMessage(msg, "*"), 0);
  68. // window.postMessage(msg, "*");
  69. $.QYAgent[funcobjname](s)
  70. // console.info(this.dateFormatter() + " ===========2 ----" + funcobjname);
  71. } catch (e) {
  72. }
  73. },
  74. on: function(eventname, handler) {
  75. try {
  76. // var s = { type: "FROM_PAGE", text: { opcode: "RegisterEvent", eventname: eventname, handler: handler} };
  77. // window.postMessage(s, "*");
  78. eventTarget.on(eventname, handler)
  79. } catch (e) {
  80. }
  81. },
  82. un: function(eventname, handler) {
  83. eventTarget.un(eventname, handler)
  84. },
  85. // 更新当前坐席状态
  86. UpdateCurrentState: function() {
  87. this.Internal_postMessage(this.UpdateCurrentState, 'UpdateCurrentState')
  88. },
  89. // 获取当前坐席状态
  90. GetCurrentState: function() {
  91. return this.m_CurrentState
  92. },
  93. // 综合的登录操作(包括连接as,AgentRegister,AgentLogin三部分异步操作)
  94. DoLogin: function(LoginParam) {
  95. this.Internal_postMessage(this.DoLogin, 'DoLogin', 'LoginParam')
  96. },
  97. // 20150424
  98. // 综合的sa登录操作(包括连接as,SALogin两部分异步操作)
  99. DoSALogin: function(Ip, Port, CId, Code) {
  100. this.Internal_postMessage(this.DoSALogin, 'DoSALogin', 'Ip, Port, CId, Code')
  101. },
  102. // sa登出
  103. SALogout: function() {
  104. this.Internal_postMessage(this.SALogout, 'SALogout')
  105. },
  106. // 20160906
  107. DoMoLogin: function(ip_mo, port_mo, user, password) {
  108. this.Internal_postMessage(this.DoMoLogin, 'DoMoLogin', 'ip_mo, port_mo, user, password')
  109. },
  110. // 20161021
  111. MoLogout: function() {
  112. this.Internal_postMessage(this.MoLogout, 'MoLogout')
  113. },
  114. // 20160906
  115. MoGetPageHead: function(module_name, page_index) {
  116. this.Internal_postMessage(this.MoGetPageHead, 'MoGetPageHead', 'module_name, page_index')
  117. },
  118. // 20160906
  119. MoPageSwitch: function(module_name, page_index, search_value, switch_flag) {
  120. this.Internal_postMessage(this.MoPageSwitch, 'MoPageSwitch', 'module_name, page_index, search_value, switch_flag')
  121. },
  122. MoCommand: function(module_name, command, param) {
  123. this.Internal_postMessage(this.MoCommand, 'MoCommand', 'module_name, command, param')
  124. },
  125. // 20150424
  126. // 聊天信息
  127. SendChat: function(MessageID, Receiver) {
  128. this.Internal_postMessage(this.SendChat, 'SendChat', 'MessageID, Receiver')
  129. },
  130. //
  131. NotifyCodeList: function() {
  132. this.Internal_postMessage(this.NotifycodeList, 'NotifycodeList')
  133. },
  134. SetDebug: function(bDebug) {
  135. this.Internal_postMessage(this.SetDebug, 'SetDebug', 'bDebug')
  136. },
  137. Logout: function() {
  138. this.Internal_postMessage(this.Logout, 'Logout')
  139. this.m_CurrentState = 0
  140. },
  141. // 发送置忙请求
  142. SetBusy: function() {
  143. this.Internal_postMessage(this.SetBusy, 'SetBusy')
  144. },
  145. // 发送置闲请求
  146. SetFree: function() {
  147. this.Internal_postMessage(this.SetFree, 'SetFree')
  148. },
  149. // 发送小休请求 20170517 增加参数CustomName
  150. SetRest: function(CustomName) {
  151. this.Internal_postMessage(this.SetRest, 'SetRest', 'CustomName')
  152. },
  153. // 发送抢接请求 20140806
  154. Snatch: function(nType, FormatStr) {
  155. this.Internal_postMessage(this.Snatch, 'Snatch', 'nType, FormatStr')
  156. },
  157. // 发送获取坐席信息请求
  158. GetAgentInfo: function(nType, nFlag, CodeList) {
  159. this.Internal_postMessage(this.GetAgentInfo, 'GetAgentInfo', 'nType, nFlag, CodeList')
  160. },
  161. // 发送获取外线排队长度信息请求
  162. GetChannelQueueSize: function(Gid, nFlag) {
  163. this.Internal_postMessage(this.GetChannelQueueSize, 'GetChannelQueueSize', 'Gid, nFlag')
  164. },
  165. // 发送获取外线排队信息请求
  166. GetChannelQueueInfo: function(Gid, nFlag) {
  167. this.Internal_postMessage(this.GetChannelQueueInfo, 'GetChannelQueueInfo', 'Gid, nFlag')
  168. },
  169. // 发送接听请求
  170. ClientAnswer: function(nType) {
  171. this.Internal_postMessage(this.ClientAnswer, 'ClientAnswer', 'nType')
  172. },
  173. // 发送挂机请求
  174. Hangup: function() {
  175. this.Internal_postMessage(this.Hangup, 'Hangup')
  176. },
  177. // 发送话后处理请求
  178. EndProcessing: function() {
  179. this.Internal_postMessage(this.EndProcessing, 'EndProcessing')
  180. },
  181. // 发送保持请求
  182. Keep: function() {
  183. this.Internal_postMessage(this.Keep, 'Keep')
  184. },
  185. // 20160119
  186. // 发送静音请求
  187. Silence: function() {
  188. this.Internal_postMessage(this.Silence, 'Silence')
  189. },
  190. // 发送恢复请求
  191. Restore: function() {
  192. this.Internal_postMessage(this.Restore, 'Restore')
  193. },
  194. // 发送呼叫请求
  195. MakeCallOut: function(CallerNo, CalledNo, BusinessCode, Reserved) {
  196. this.Internal_postMessage(this.MakeCallOut, 'MakeCallOut', 'CallerNo, CalledNo, BusinessCode, Reserved')
  197. },
  198. // 发送呼叫取消请求
  199. MakeCallOutCancel: function() {
  200. this.Internal_postMessage(this.MakeCallOutCancel, 'MakeCallOutCancel')
  201. },
  202. // 发送转移外线请求
  203. TransTel: function(CallerNo, CalledNo, BusinessCode, Reserved) {
  204. this.Internal_postMessage(this.TransTel, 'TransTel', 'CallerNo, CalledNo, BusinessCode, Reserved')
  205. },
  206. // 发送转移内线请求
  207. TransAgent: function(nType, FormatStr) {
  208. this.Internal_postMessage(this.TransAgent, 'TransAgent', 'nType, FormatStr')
  209. },
  210. // 发送转移ivr请求
  211. TransIVR: function(BusinessCode) {
  212. this.Internal_postMessage(this.TransIVR, 'TransIVR', 'BusinessCode')
  213. },
  214. // 发送转移取消请求
  215. TransCancel: function() {
  216. this.Internal_postMessage(this.TransCancel, 'TransCancel')
  217. },
  218. // 发送三方通话请求
  219. ConfStart: function(CallerNo, CalledNo, BusinessCode) {
  220. this.Internal_postMessage(this.ConfStart, 'ConfStart', 'CallerNo, CalledNo, BusinessCode')
  221. },
  222. // 发送三方通话取消请求
  223. ConfStartCancel: function() {
  224. this.Internal_postMessage(this.ConfStartCancel, 'ConfStartCancel')
  225. },
  226. // 发送 转接成功待确认
  227. TransConfirm: function(Response) {
  228. this.Internal_postMessage(this.TransConfirm, 'TransConfirm', 'Response')
  229. },
  230. // 发送 三方通话确认第三方
  231. ConfConfirm: function(Response) {
  232. this.Internal_postMessage(this.ConfConfirm, 'ConfConfirm', 'Response')
  233. },
  234. // 发送 进入管理状态
  235. InManager: function() {
  236. this.Internal_postMessage(this.InManager, 'InManager')
  237. },
  238. // 发送 退出管理状态
  239. OutManager: function() {
  240. this.Internal_postMessage(this.OutManager, 'OutManager')
  241. },
  242. // 发送 监听
  243. Listen: function(Code) {
  244. this.Internal_postMessage(this.Listen, 'Listen', 'Code')
  245. },
  246. // 发送 退出监听
  247. ExitListen: function() {
  248. this.Internal_postMessage(this.ExitListen, 'ExitListen')
  249. },
  250. // 发送 强插
  251. ForceInsert: function(Code) {
  252. this.Internal_postMessage(this.ForceInsert, 'ForceInsert', 'Code')
  253. },
  254. // 发送 退出强插
  255. ExitForceInsert: function() {
  256. this.Internal_postMessage(this.ExitForceInsert, 'ExitForceInsert')
  257. },
  258. // 发送 强制拆线
  259. ForceRelease: function(Code) {
  260. this.Internal_postMessage(this.ForceRelease, 'ForceRelease', 'Code')
  261. },
  262. // 发送 强制置忙
  263. ForceSetBusy: function(Code) {
  264. this.Internal_postMessage(this.ForceSetBusy, 'ForceSetBusy', 'Code')
  265. },
  266. // 发送 强制置闲
  267. ForceSetFree: function(Code) {
  268. this.Internal_postMessage(this.ForceSetFree, 'ForceSetFree', 'Code')
  269. },
  270. // 发送 强制注销
  271. ForceLogout: function(Code) {
  272. this.Internal_postMessage(this.ForceLogout, 'ForceLogout', 'Code')
  273. },
  274. // 发送会议发起请求
  275. MeetingStart: function() {
  276. this.Internal_postMessage(this.MeetingStart, 'MeetingStart')
  277. },
  278. // 发送会议增加成员请求
  279. MeetingAdd: function(CalledList) {
  280. this.Internal_postMessage(this.MeetingAdd, 'MeetingAdd', 'CalledList')
  281. },
  282. // 发送会议更改成员模式请求
  283. MeetingUpdateMode: function(MeetingNumber, nMode) {
  284. this.Internal_postMessage(this.MeetingUpdateMode, 'MeetingUpdateMode', 'MeetingNumber, nMode')
  285. },
  286. // 发送会议成员挂断请求
  287. MeetingHangup: function(MeetingNumber) {
  288. this.Internal_postMessage(this.MeetingHangup, 'MeetingHangup', 'MeetingNumber')
  289. },
  290. // 发送会议结束会议请求
  291. MeetingEnd: function() {
  292. this.Internal_postMessage(this.MeetingEnd, 'MeetingEnd')
  293. },
  294. // 发送DTMF
  295. SendDTMF: function(Keys) {
  296. this.Internal_postMessage(this.SendDTMF, 'SendDTMF', 'Keys')
  297. },
  298. // 发送自定义命令 //20140827
  299. CustomCommand: function(nType, sData) {
  300. this.Internal_postMessage(this.CustomCommand, 'CustomCommand', 'Type, sData')
  301. },
  302. // 20140924(前锋)
  303. // 获取当前空闲坐席个数
  304. GetFreeAgentCount: function(gid) {
  305. this.Internal_postMessage(this.GetFreeAgentCount, 'GetFreeAgentCount', 'gid')
  306. },
  307. // 20141017
  308. // 申请电话登陆(仅适用于内线电话)
  309. ApplyTelLogin: function(Channel) {
  310. this.Internal_postMessage(this.ApplyTelLogin, 'ApplyTelLogin', 'Channel')
  311. },
  312. // 20141124 增加GetBusyState 1-当前状态为忙 0-当前状态为闲
  313. // 20141209 更改为SetBusyState
  314. SetBusyState: function(bBusy) {
  315. this.Internal_postMessage(this.SetBusyState, 'SetBusyState', 'bBusy')
  316. },
  317. // 20160303
  318. // 播音
  319. PlayAudio: function(Command, Param1, Param2, Param3) {
  320. this.Internal_postMessage(this.PlayAudio, 'PlayAudio', 'Command, Param1, Param2, Param3')
  321. },
  322. // 20170930
  323. // 设置unload状态
  324. // unloadstate - 1 当前处于unload状态(刷新或关闭浏览器) 0 - 当前处于刷新后load状态
  325. SetUnloadState: function(unloadState) {
  326. this.Internal_postMessage(this.SetUnloadState, 'SetUnloadState', 'unloadState')
  327. },
  328. // 20171020
  329. // 获取predial info
  330. GetPredialInfo: function(cid, ids) {
  331. this.Internal_postMessage(this.GetPredialInfo, 'GetPredialInfo', 'cid, ids')
  332. },
  333. // 20171127
  334. // 任务模式下发送任务相关操作
  335. // operate -- 0退出任务 1进入任务
  336. SetPredialTaskInfo: function(taskid, taskname, operate) {
  337. this.Internal_postMessage(this.GetPredialInfo, 'SetPredialTaskInfo', 'taskid, taskname, operate')
  338. }
  339. }
  340. })
  341. // 插件事件入口
  342. window.addEventListener('message', function(event) {
  343. if (event.source != window) { return }
  344. if (event.data.type && (event.data.type == 'FROM_BK')) {
  345. // $.QYProxy.SocektEvent[event.data.handler](event.data.bkdata.args);
  346. // console.info(event.data.handler+":"+JSON.stringify(event.data.bkdata.args)+"---------------1:"+(new Date()).toLocaleString()+":"+(new Date()).getMilliseconds());
  347. if (event.data.handler == 'S_AgentState') {
  348. // console.info("QYAgent: ON_S_AgentState:"+event.data.bkdata.args.State+"----------------2");
  349. $.QYProxy.m_CurrentState = event.data.bkdata.args.State
  350. }
  351. setTimeout($.acooly.agent[event.data.handler](event.data.bkdata.args), 0)
  352. }
  353. }, false)
  354. })(jQuery)