phone.js 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454
  1. holly.phone = {
  2. phone_data: {},
  3. _phone_url: "",
  4. _phone_iccCount: 0,
  5. _phone_isWaitingEvent: false,
  6. _phone_isKick: true,
  7. _phone_unregister: 0,
  8. _phone_peerstate: 1,
  9. _phone_dialing: 2,
  10. _phone_innerDialing: 3,
  11. _phone_belling: 4,
  12. _phone_innerBelling: 5,
  13. _phone_listening: 6,
  14. _phone_talking: 7,
  15. _phone_threeWayTalking: 8,
  16. _phone_innerTalking: 9,
  17. _phone_dialTalking: 10,
  18. _phone_listened: 11,
  19. _phone_transferBelling: 12,
  20. _phone_transferDialing: 13,
  21. _phone_transfer: 14,
  22. _phone_dialoutTransfer: 15,
  23. _phone_systemBusy: 99,
  24. _phone_currentState: "",
  25. _phone_stateBeforeHold: "",
  26. _phone_isInvestigatting: false,
  27. _phone_stateDescription: ["unregister", "peerstate", "dialing", "innerDialing", "belling", "innerBelling", "listening", "talking", "threeWayTalking", "innerTalking", "dialTalking", "listened", "transferBelling", "transferDialing", "transfer", "dialTransfer"],
  28. _phone_peersFromSip: [],
  29. phone_peers: [],
  30. phone_peers_sip: [],
  31. phone_queues: [],
  32. phone_accountCalls: [],
  33. phone_serviceNos: [],
  34. _phone_isSettingbusy: false,
  35. _phone_isRelogin: false,
  36. phone_pbxs: [],
  37. _phone_callObject: {},
  38. _phone_sendAction: function (jsonData, onload, onerror) {
  39. var json = $.toJSON(jsonData);
  40. var timeout = 15000;
  41. if (jsonData.Timeout != undefined) {
  42. timeout = jsonData.Timeout;
  43. }
  44. $.ajax({
  45. type: "get",
  46. url: holly.phone._phone_url,
  47. timeout: timeout,
  48. cache: false,
  49. data: {json: json},
  50. dataType: "jsonp",
  51. jsonp: "callbackName",
  52. success: onload,
  53. error: onerror
  54. });
  55. },
  56. phone_register: function (config, phoneJson) {
  57. holly.phone._phone_url = config.proxy_url;
  58. var isMonitorPage = phoneJson.isMonitorPage;
  59. delete phoneJson.isMonitorPage;
  60. var onload = function (response) {
  61. var _response = response;
  62. if (!_response.Succeed) {
  63. var code = _response.Result;
  64. if (code) {
  65. if (code == 601) {
  66. hollyglobal.loginFailureCallback("您的账户通话座席登录数已达最大或者已经到期,通话功能将不能使用");
  67. } else {
  68. if (code == 602) {
  69. hollyglobal.loginFailureCallback("您的账户无通话座席登录数已达最大或者已经到期,通话功能将不能使用");
  70. } else if (code == 408) {
  71. hollyglobal.loginFailureCallback("由于您的主软电话条没有签入,不能登录软电话");
  72. } else {
  73. hollyglobal.loginFailureCallback("登录失败" + code + ",通话功能将不能使用");
  74. }
  75. }
  76. }
  77. } else if (_response.SessionID) {
  78. config.uniqueId = _response.SessionID;
  79. var date = new Date();
  80. var identity = date.valueOf();
  81. config.currentServerTime = identity - _response.Timestamp * 1000;
  82. config.phonebarConfig = _response.PhonebarConfig;
  83. config.autoBusyTime = _response.AutoBusyTime;
  84. config.userId = _response.UserID;
  85. config.pbx_in_ip = _response.PBX;
  86. config.accountId = _response.Account;
  87. config.loginName = config.user;
  88. config.sipNo = _response.SipNum;
  89. config.monitorUser = _response.MonitorUser;
  90. config.monitorPassword = _response.MonitorPassword;
  91. config.depts = $.evalJSON(_response.Departments);
  92. config.departmentID = (_response.DepartmentID) ? (_response.DepartmentID) : "";
  93. holly.session.logined = true;
  94. holly.softphonebar.softphonebar_init();
  95. holly.phone._phone_init(config);
  96. holly.phone._phone_waitEvent(isMonitorPage);
  97. if (isMonitorPage) {
  98. hollyglobal.isMonitorPage = true;
  99. var curpbx;
  100. if (holly.phone.phone_data.pbx_in_ip) {
  101. curpbx = holly.phone.phone_pbxs[holly.phone.phone_data.pbx_in_ip];
  102. curpbx.sessionId = _response.SessionID;
  103. } else {
  104. curpbx = holly.phone.phone_pbxs[hollyglobal.sipConfigId];
  105. curpbx.sessionId = _response.SessionID;
  106. holly.phone.phone_data.pbx_in_ip = hollyglobal.sipConfigId;
  107. holly.phone.phone_data.accountId = hollyglobal.accountId;
  108. if(hollyglobal.isMonitorJoint){
  109. holly.phone.phone_data.userId = window.localStorage.getItem('currentLoginAgent');
  110. }else {
  111. holly.phone.phone_data.userId = config.userId;
  112. }
  113. }
  114. //$("#monitor_allpbx").css("display", "block");
  115. holly.softphonebar.monitor_agent();
  116. } else {
  117. holly.utils.pickSoftphonebar();
  118. }
  119. hollyglobal.loginSuccessCallback(_response);
  120. }
  121. };
  122. var onerror = function (xhr, status, error) {
  123. hollyglobal.loginFailureCallback('请求超时,请检查本地网络');
  124. };
  125. holly.phone._phone_sendAction(phoneJson, onload, onerror);
  126. },
  127. _phone_init: function (config) {
  128. holly.session.user = {};
  129. holly.session.user.userId = config.userId;
  130. holly.session.user.loginName = config.loginName;
  131. holly.session.user.password = config.password;
  132. holly.session.user.extenType = config.extenType;
  133. holly.session.user.busyType = config.busyType;
  134. holly.session.user.sipConfigId = config.curPbx;
  135. holly.phone.phone_data.uniqueId = config.uniqueId;
  136. holly.phone.phone_data.currentServerTime = config.currentServerTime;
  137. holly.phone.phone_data.autoBusyTime = config.autoBusyTime;
  138. holly.phone.phone_data.userId = config.userId;
  139. holly.phone.phone_data.pbx_in_ip = config.pbx_in_ip;
  140. holly.phone.phone_data.accountId = config.accountId;
  141. holly.phone.phone_data.loginName = config.loginName;
  142. holly.phone.phone_data.sipNo = config.sipNo;
  143. holly.phone.phone_data.monitor = config.monitor;
  144. holly.phone.phone_data.user = config.user;
  145. holly.phone.phone_data.password = config.password;
  146. holly.phone.phone_data.extenType = config.extenType;
  147. holly.phone.phone_data.busyType = config.busyType;
  148. holly.phone.phone_data.monitorUser = config.monitorUser;
  149. holly.phone.phone_data.monitorPassword = config.monitorPassword;
  150. holly.phone.phone_data.depts = config.depts;
  151. holly.phone.phone_data.departmentID = config.departmentID;
  152. holly.phone.phone_data.phonebarConfig = new Array();
  153. if (config.phonebarConfig) {
  154. var peerstates = config.phonebarConfig.split(",");
  155. for (var i = 0; i < peerstates.length; i++) {
  156. holly.phone.phone_data.phonebarConfig[peerstates[i].split(":")[0]] = peerstates[i].split(":")[1]
  157. }
  158. }
  159. holly.phone._phone_currentState = holly.phone._phone_unregister;
  160. holly.phone.phone_publishEvent("toolbarupdate", [holly.phone._phone_stateDescription[holly.phone._phone_currentState], ""]);
  161. if(config.userId && hollyglobal.isMonitorJoint){
  162. window.localStorage.setItem('currentLoginAgent', config.userId);
  163. }
  164. },
  165. _phone_waitEvent: function (isMonitorPage) {
  166. if (holly.phone._phone_isWaitingEvent)
  167. return;
  168. holly.phone._phone_isWaitingEvent = true;
  169. var phoneJson = {
  170. Command: "Action",
  171. Action: "GetState",
  172. ActionID: "GetState" + Math.random(),
  173. SessionID: holly.phone.phone_data.uniqueId,
  174. User: holly.phone.phone_data.userId
  175. };
  176. var onload = function (response) {
  177. holly.phone._phone_iccCount = 0;
  178. if (!response)
  179. return;
  180. var datas = response;
  181. var _response = datas.Response;
  182. if (!_response)
  183. _response = datas;
  184. if (_response.Succeed && !_response.HasEvent) {
  185. } else if (!_response.Succeed) {
  186. if (_response.Expired && holly.phone._phone_isKick) {
  187. holly.phone._phone_relogin(isMonitorPage);
  188. holly.phone._phone_isWaitingEvent = false;
  189. return;
  190. }
  191. return;
  192. } else {
  193. if (_response.Kick) {
  194. var comments = "";
  195. if (_response.Comments)
  196. comments = _response.Comments;
  197. if (!isMonitorPage) {
  198. if (comments == "ukick" || comments == "ekick") {
  199. holly.utils.showError("您的帐号在其他地方登录了", "softphone_transfer");
  200. } else {
  201. holly.utils.showError("您已被管理员强制签出", "softphone_transfer");
  202. }
  203. holly.session.logined = false;
  204. holly.phone._phone_isWaitingEvent = false;
  205. holly.utils.kickSoftphonebar();
  206. holly.phone._phone_isKick = false;
  207. holly.softphonebar._softphonebar_barupdate('', 'unregister', '');
  208. return;
  209. }
  210. } else {
  211. var events = datas.Event;
  212. if (events != null && holly.phone._phone_isKick) {
  213. holly.phone._phone_eventHandler(events);
  214. if (hollyglobal.multiLogin && holly.phone._phone_currentState === holly.phone._phone_unregister) {
  215. holly.session.logined = false;
  216. holly.phone._phone_isWaitingEvent = false;
  217. return;
  218. }
  219. }
  220. }
  221. }
  222. holly.phone._phone_isWaitingEvent = false;
  223. //这段代码解决浏览器一直转圈的问题
  224. window.setTimeout(function () {
  225. holly.phone._phone_waitEvent(isMonitorPage);
  226. }, 100);
  227. };
  228. var onerror = function () {
  229. holly.phone._phone_isWaitingEvent = false;
  230. holly.phone._phone_isKick = true;
  231. window.setTimeout(function () {
  232. holly.phone._phone_iccCount++;
  233. if (holly.phone._phone_iccCount >= 3) {
  234. holly.phone._phone_iccCount = 0;
  235. holly.utils.unRegisterSoftphonebar();
  236. //alert("连接服务器超时,可能是您的网络问题,正在尝试重新连接...");
  237. holly.utils.showError("连接超时,尝试重新连接", "softphone_transfer");
  238. }
  239. holly.phone._phone_waitEvent(isMonitorPage);
  240. }, 1000);
  241. };
  242. holly.phone._phone_sendAction(phoneJson, onload, onerror);
  243. },
  244. _phone_relogin: function (isMonitorPage) {
  245. if (holly.phone._phone_isRelogin)
  246. return;
  247. holly.phone._phone_isRelogin = true;
  248. var actionName = "Login";
  249. if (hollyglobal.multiLogin) {
  250. actionName = "MultipleLogin";
  251. }
  252. var phoneJson = {
  253. Command: "Action",
  254. Action: actionName,
  255. ActionID: "Login" + Math.random(),
  256. Monitor: holly.phone.phone_data.monitor
  257. };
  258. var config = {
  259. monitor: false
  260. };
  261. phoneJson.ExtenType = hollyglobal.loginExtenType;
  262. phoneJson.Password = hollyglobal.loginPassword;
  263. phoneJson.BusyType = hollyglobal.loginBusyType;
  264. phoneJson.User = hollyglobal.loginUser;
  265. config.extenType = hollyglobal.loginExtenType;
  266. config.password = hollyglobal.loginPassword;
  267. config.user = hollyglobal.loginUser;
  268. if (isMonitorPage) {
  269. var phoneJson = {
  270. Command: "Action",
  271. Action: "Login",
  272. ActionID: "Login" + Math.random(),
  273. PBX: holly.session.user.sipConfigId,
  274. Account: hollyglobal.accountId,
  275. Password: hollyglobal.monitorPassword,
  276. UserID: hollyglobal.monitorUserID,
  277. MonitorUser: true
  278. };
  279. }
  280. var onload = function (response) {
  281. var _response = response;
  282. if (!_response.Succeed) {
  283. var code = _response.Result;
  284. if (code) {
  285. if (code == 601) {
  286. hollyglobal.loginFailureCallback("您的账户通话座席登录数已达最大或者已经到期,通话功能将不能使用");
  287. } else if (code == 602) {
  288. hollyglobal.loginFailureCallback("您的账户无通话座席登录数已达最大或者已经到期,通话功能将不能使用");
  289. } else if (code == 408) {
  290. hollyglobal.loginFailureCallback("由于您的主软电话条没有签入,不能签入软电话");
  291. } else {
  292. hollyglobal.loginFailureCallback("登录失败" + code + ",通话功能将不能使用");
  293. }
  294. } else {
  295. hollyglobal.loginFailureCallback("您当前的会话已经失效,通话功能将不能使用");
  296. }
  297. } else if (_response.SessionID) {
  298. config.uniqueId = _response.SessionID;
  299. var date = new Date();
  300. var identity = date.valueOf();
  301. config.currentServerTime = identity - _response.Timestamp * 1000;
  302. config.phonebarConfig = _response.PhonebarConfig;
  303. config.autoBusyTime = _response.AutoBusyTime;
  304. config.userId = _response.UserID;
  305. config.pbx_in_ip = _response.PBX;
  306. config.accountId = _response.Account;
  307. config.sipNo = _response.SipNum;
  308. config.monitorUser = _response.MonitorUser;
  309. config.monitorPassword = _response.MonitorPassword;
  310. config.depts = $.evalJSON(_response.Departments);
  311. config.departmentID = (_response.DepartmentID) ? (_response.DepartmentID) : "";
  312. holly.session.logined = true;
  313. holly.softphonebar.softphonebar_init();
  314. holly.phone._phone_init(config);
  315. if (isMonitorPage) {
  316. var curPbx;
  317. if (holly.phone.phone_data.pbx_in_ip) {
  318. curPbx = holly.phone.phone_pbxs[holly.phone.phone_data.pbx_in_ip];
  319. curPbx.sessionId = _response.SessionID;
  320. } else {
  321. curPbx = holly.phone.phone_pbxs[holly.session.user.sipConfigId];
  322. curPbx.sessionId = _response.SessionID;
  323. holly.phone.phone_data.pbx_in_ip = holly.session.user.sipConfigId;
  324. holly.phone.phone_data.accountId = hollyglobal.accountId;
  325. holly.phone.phone_data.userId = holly.session.user.userId;
  326. }
  327. } else
  328. holly.utils.pickSoftphonebar();
  329. holly.phone._phone_isWaitingEvent = false;
  330. holly.phone._phone_isKick = true;
  331. holly.phone._phone_waitEvent(isMonitorPage);
  332. hollyglobal.loginSuccessCallback(_response);
  333. }
  334. holly.phone._phone_isRelogin = false;
  335. };
  336. var onerror = function () {
  337. hollyglobal.loginFailureCallback('请求合力通话服务器超时,请检查本地网络');
  338. holly.phone._phone_isRelogin = false;
  339. holly.phone._phone_isKick = true;
  340. };
  341. holly.phone._phone_sendAction(phoneJson, onload, onerror);
  342. },
  343. _phone_eventHandler: function (evtJsons) {
  344. $.each(evtJsons, function (i, item) {
  345. holly.phone._phone_stateProcess(item);
  346. if (hollyglobal.isMonitorPage) {
  347. holly.phone._phone_monitorPeer(item);
  348. holly.phone._phone_monitorQueue(item);
  349. holly.phone._phone_monitorServiceNo(item);
  350. }
  351. if (item.Event === "UserStatus" && item.PeerStatus === "Unregistered" && holly.phone.phone_data.userId === item.UserID) {
  352. if (!holly.phone.phone_data.monitor)
  353. return false;
  354. }
  355. });
  356. },
  357. _phone_monitorAccount: function (evtJson) {
  358. if (evtJson.Event === "AccountStatus") {
  359. var account;
  360. if (!holly.phone.phone_accountCalls[evtJson.PBX]) {
  361. account = {
  362. account: evtJson.Account,
  363. inCalls: evtJson.InCalls,
  364. outComplete: evtJson.OutComplete,
  365. inComplete: evtJson.InComplete,
  366. outCalls: evtJson.OutCalls,
  367. inCallsPerHour: evtJson.InCallsPerHour,
  368. currentOutCalls: evtJson.CurrentOutCalls,
  369. pbx: evtJson.PBX,
  370. inCompletePerHour: evtJson.InCompletePerHour,
  371. outCallsPerHour: evtJson.OutCallsPerHour,
  372. currentInCalls: evtJson.CurrentInCalls,
  373. outCompletePerHour: evtJson.OutCompletePerHour
  374. };
  375. holly.phone.phone_accountCalls[evtJson.PBX] = account;
  376. holly.phone.phone_publishEvent("EvtAccountCalls", [account]);
  377. } else {
  378. account = holly.phone.phone_accountCalls[evtJson.PBX];
  379. account.account = evtJson.Account;
  380. account.inCalls = evtJson.InCalls;
  381. account.outComplete = evtJson.OutComplete;
  382. account.inComplete = evtJson.InComplete;
  383. account.outCalls = evtJson.OutCalls;
  384. account.inCallsPerHour = evtJson.InCallsPerHour;
  385. account.currentOutCalls = evtJson.CurrentOutCalls;
  386. account.pbx = evtJson.PBX;
  387. account.inCompletePerHour = evtJson.InCompletePerHour;
  388. account.outCallsPerHour = evtJson.OutCallsPerHour;
  389. account.currentInCalls = evtJson.CurrentInCalls;
  390. account.outCompletePerHour = evtJson.OutCompletePerHour;
  391. holly.phone.phone_publishEvent("EvtAccountCalls", [account]);
  392. }
  393. }
  394. },
  395. phone_pbxMonitor: function (pbx) {
  396. for (var i in holly.phone.phone_pbxs) {
  397. if (i === holly.phone.phone_data.pbx_in_ip)
  398. continue;
  399. if (i === pbx) {
  400. if (!holly.phone.phone_pbxs[pbx].monitor)
  401. holly.phone._phone_pbxMonitorResister(i);
  402. } else {
  403. if (holly.phone.phone_pbxs[i].monitor)
  404. holly.phone._phone_pbxMonitorLogOff(i)
  405. }
  406. }
  407. },
  408. _phone_pbxMonitorLogOff: function (pbx) {
  409. var phone_pbx = holly.phone.phone_pbxs[pbx];
  410. if (phone_pbx.isMonitorLogOff)
  411. return;
  412. phone_pbx.isMonitorLogOff = true;
  413. var url = phone_pbx.proxyUrl;
  414. var phoneJson = {
  415. Command: "Action",
  416. Action: "Logoff",
  417. ActionID: "Logoff" + Math.random(),
  418. SessionID: phone_pbx.sessionId
  419. };
  420. var onload = function (response) {
  421. phone_pbx.isMonitorLogOff = false;
  422. phone_pbx.monitor = false;
  423. };
  424. var onerror = function () {
  425. phone_pbx.isMonitorLogOff = false;
  426. phone_pbx.monitor = false;
  427. };
  428. var json = $.toJSON(phoneJson);
  429. var timeout = 15000;
  430. $.ajax({
  431. type: "get",
  432. url: url,
  433. timeout: timeout,
  434. cache: false,
  435. data: {json: json},
  436. dataType: "jsonp",
  437. jsonp: "callbackName",
  438. success: onload,
  439. error: onerror
  440. });
  441. },
  442. _phone_pbxMonitorResister: function (pbx) {
  443. var phone_pbx = holly.phone.phone_pbxs[pbx],
  444. url = phone_pbx.proxyUrl,
  445. phoneJson = {
  446. Command: "Action",
  447. Action: "Login",
  448. ActionID: "Login" + Math.random(),
  449. PBX: pbx,
  450. Account: holly.phone.phone_data.accountId,
  451. UserID: hollyglobal.monitorUserID,
  452. Password: hollyglobal.monitorPassword,
  453. MonitorUser: true
  454. };
  455. if (pbx === hollyglobal.sipConfigId)
  456. phoneJson.MonitorRealUserID = hollyglobal.userId;
  457. var onload = function (response) {
  458. if (response.Succeed) {
  459. holly.phone.phone_pbxs[pbx].sessionId = response.SessionID;
  460. holly.phone.phone_pbxs[pbx].isWaitingPbxEvent = false;
  461. holly.phone.phone_pbxs[pbx].monitor = true;
  462. holly.phone._phone_waitPbxEvent(pbx);
  463. } else {
  464. holly.phone.phone_pbxs[pbx].monitor = false;
  465. }
  466. };
  467. var onerror = function () {
  468. holly.phone.phone_pbxs[pbx].monitor = false;
  469. holly.utils.showError("请求超时,请检查本地网络", "softphone_transfer");
  470. };
  471. var json = $.toJSON(phoneJson);
  472. var timeout = 15000;
  473. $.ajax({
  474. type: "get",
  475. url: url,
  476. timeout: timeout,
  477. cache: false,
  478. data: {json: json},
  479. dataType: "jsonp",
  480. jsonp: "callbackName",
  481. success: onload,
  482. error: onerror
  483. });
  484. },
  485. _phone_waitPbxEvent: function (pbx) {
  486. var phone_pbx = holly.phone.phone_pbxs[pbx];
  487. if (!phone_pbx || !phone_pbx.monitor || phone_pbx.isWaitingPbxEvent)
  488. return;
  489. phone_pbx.isWaitingPbxEvent = true;
  490. var url = phone_pbx.proxyUrl,
  491. phoneJson = {
  492. Command: "Action",
  493. Action: "GetState",
  494. ActionID: "GetState" + Math.random(),
  495. SessionID: phone_pbx.sessionId,
  496. User: holly.phone.phone_data.monitorUser
  497. };
  498. var onload = function (response) {
  499. if (!response) {
  500. return;
  501. }
  502. var _response = response.Response;
  503. if (!_response.Succeed) {
  504. if (_response.Expired) {
  505. phone_pbx.isWaitingPbxEvent = false;
  506. holly.phone._phone_pbxMonitorResister(pbx, url);
  507. return;
  508. }
  509. } else if (_response.Succeed && _response.HasEvent) {
  510. var events = response.Event;
  511. if (events != null) {
  512. holly.phone._phone_eventHandler(events, true);
  513. }
  514. }
  515. phone_pbx.isWaitingPbxEvent = false;
  516. holly.phone._phone_waitPbxEvent(pbx);
  517. };
  518. var onerror = function () {
  519. phone_pbx.isWaitingPbxEvent = false;
  520. };
  521. var json = $.toJSON(phoneJson);
  522. var timeout = 15000;
  523. $.ajax({
  524. type: "get",
  525. url: url,
  526. timeout: timeout,
  527. cache: false,
  528. data: {json: json},
  529. dataType: "jsonp",
  530. jsonp: "callbackName",
  531. success: onload,
  532. error: onerror
  533. });
  534. },
  535. _phone_monitorServiceNo: function (evtJson) {
  536. if (evtJson.Event === "TrunkStatus") {
  537. var displayName, serviceNo;
  538. if (evtJson.DisplayName) {
  539. displayName = evtJson.DisplayName;
  540. if (holly.utils.startWith(displayName, "serviceno-"))
  541. displayName = "";
  542. }
  543. if (!holly.phone.phone_serviceNos[evtJson.ServiceNo]) {
  544. serviceNo = {
  545. serviceNo: evtJson.ServiceNo,
  546. inCalls: evtJson.InCalls,
  547. inLost: evtJson.InLost,
  548. inComplete: evtJson.InComplete,
  549. outCalls: 0,
  550. outComplete: 0,
  551. displayName: displayName,
  552. pbx: evtJson.PBX
  553. };
  554. holly.phone.phone_serviceNos[evtJson.ServiceNo] = serviceNo;
  555. } else {
  556. serviceNo = holly.phone.phone_serviceNos[evtJson.ServiceNo];
  557. serviceNo.inCalls = evtJson.InCalls,
  558. serviceNo.inLost = evtJson.InLost,
  559. serviceNo.inComplete = evtJson.InComplete,
  560. serviceNo.outCalls = 0,
  561. serviceNo.outComplete = 0,
  562. serviceNo.displayName = displayName
  563. }
  564. holly.phone.phone_publishEvent("EvtMonitorServiceNo", [holly.phone.phone_serviceNos[evtJson.ServiceNo]]);
  565. }
  566. },
  567. _phone_stateProcess: function (evtJson) {
  568. //console.info(evtJson.Event+':'+evtJson.PeerStatus)
  569. holly.phone._phone_super(evtJson);
  570. switch (holly.phone._phone_currentState) {
  571. case holly.phone._phone_unregister:
  572. if (evtJson.Event === "PeerStatus") {
  573. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  574. if (evtJson.PeerStatus === "Registered") {
  575. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  576. holly.phone._phone_update(evtJson);
  577. }
  578. }
  579. } else if (evtJson.Event === "UserStatus") {
  580. if (holly.phone.phone_data.userId === evtJson.UserID) {
  581. if (holly.phone.phone_data.sipNo !== evtJson.SipNum) {
  582. if (evtJson.PeerStatus === "Registered") {
  583. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  584. holly.phone._phone_update(evtJson);
  585. }
  586. }
  587. }
  588. }
  589. break;
  590. case holly.phone._phone_peerstate:
  591. if (evtJson.Event === "UserBusy") {
  592. if (holly.phone.phone_data.userId === evtJson.UserID) {
  593. holly.phone.phone_data.busyType = evtJson.BusyType;
  594. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  595. holly.phone._phone_update(evtJson);
  596. }
  597. } else if (evtJson.Event === "ChannelStatus") {
  598. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  599. if (evtJson.ChannelStatus === "Hangup") {
  600. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  601. holly.phone._phone_update(evtJson);
  602. } else if (evtJson.ChannelStatus === "Ringing") {
  603. if (evtJson.LinkedChannel.ChannelType === "normal") {
  604. holly.phone._phone_currentState = holly.phone._phone_belling;
  605. holly.phone._phone_update(evtJson);
  606. } else if (evtJson.LinkedChannel.ChannelType === "inner") {
  607. holly.phone._phone_currentState = holly.phone._phone_innerBelling;
  608. holly.phone._phone_update(evtJson);
  609. } else if (evtJson.LinkedChannel.ChannelType === "transfer") {
  610. holly.phone._phone_currentState = holly.phone._phone_transferBelling;
  611. holly.phone._phone_update(evtJson);
  612. } else if (evtJson.LinkedChannel.ChannelType === "dialTransfer") {
  613. holly.phone._phone_currentState = holly.phone._phone_transferDialing;
  614. holly.phone._phone_update(evtJson);
  615. }
  616. } else if (evtJson.ChannelStatus === "Ring") {
  617. if (evtJson.ChannelType === "dialout") {
  618. holly.phone._phone_currentState = holly.phone._phone_dialing;
  619. holly.phone._phone_update(evtJson);
  620. } else if (evtJson.ChannelType === "inner") {
  621. holly.phone._phone_currentState = holly.phone._phone_innerDialing;
  622. holly.phone._phone_update(evtJson);
  623. } else if (evtJson.ChannelType === "listen") {
  624. holly.phone._phone_currentState = holly.phone._phone_listening;
  625. holly.phone._phone_update(evtJson);
  626. }
  627. } else if (evtJson.ChannelStatus === "Link") {
  628. if (evtJson.LinkedChannel.ChannelType === "normal") {
  629. holly.phone._phone_currentState = holly.phone._phone_talking;
  630. holly.phone._phone_update(evtJson);
  631. } else if (evtJson.LinkedChannel.ChannelType === "threeWayCall") {
  632. holly.phone._phone_currentState = holly.phone._phone_threeWayTalking;
  633. holly.phone._phone_update(evtJson);
  634. } else if (evtJson.LinkedChannel.ChannelType === "inner") {
  635. holly.phone._phone_currentState = holly.phone._phone_innerTalking;
  636. holly.phone._phone_update(evtJson);
  637. } else if (evtJson.LinkedChannel.ChannelType === "dialout") {
  638. holly.phone._phone_currentState = holly.phone._phone_dialTalking;
  639. holly.phone._phone_update(evtJson);
  640. } else if (evtJson.LinkedChannel.ChannelType === "transfer") {
  641. holly.phone._phone_currentState = holly.phone._phone_transfer;
  642. holly.phone._phone_update(evtJson);
  643. } else if (evtJson.LinkedChannel.ChannelType === "dialTransfer") {
  644. holly.phone._phone_currentState = holly.phone._phone_dialoutTransfer;
  645. holly.phone._phone_update(evtJson);
  646. }
  647. } else if (evtJson.ChannelStatus === "Up") {
  648. if (evtJson.ChannelType === "listen") {
  649. holly.phone._phone_currentState = holly.phone._phone_listened;
  650. holly.phone._phone_update(evtJson);
  651. }
  652. }
  653. }
  654. } else if (evtJson.Event === "PeerStatus") {
  655. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  656. if (evtJson.PeerStatus !== "Registered") {
  657. holly.phone._phone_currentState = holly.phone._phone_unregister;
  658. holly.phone._phone_update(evtJson);
  659. }
  660. }
  661. }
  662. break;
  663. case holly.phone._phone_dialing:
  664. if (evtJson.Event === "ChannelStatus") {
  665. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  666. if (evtJson.ChannelStatus === "Hangup") {
  667. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  668. holly.phone._phone_update(evtJson);
  669. } else if (evtJson.ChannelStatus === "Link") {
  670. if (evtJson.ChannelType === "dialout") {
  671. holly.phone._phone_currentState = holly.phone._phone_dialTalking;
  672. holly.phone._phone_update(evtJson);
  673. }
  674. }
  675. }
  676. }
  677. break;
  678. case holly.phone._phone_innerDialing:
  679. if (evtJson.Event === "ChannelStatus") {
  680. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  681. if (evtJson.ChannelStatus === "Hangup") {
  682. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  683. holly.phone._phone_update(evtJson);
  684. } else if (evtJson.ChannelStatus === "Link") {
  685. if (evtJson.ChannelType === "inner") {
  686. holly.phone._phone_currentState = holly.phone._phone_innerTalking;
  687. holly.phone._phone_update(evtJson);
  688. }
  689. }
  690. }
  691. }
  692. break;
  693. case holly.phone._phone_belling:
  694. if (evtJson.Event === "ChannelStatus") {
  695. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  696. if (evtJson.ChannelStatus === "Hangup") {
  697. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  698. holly.phone._phone_update(evtJson);
  699. } else if (evtJson.ChannelStatus === "Link") {
  700. if (evtJson.LinkedChannel.ChannelType === "normal") {
  701. holly.phone._phone_currentState = holly.phone._phone_talking;
  702. holly.phone._phone_update(evtJson);
  703. } else if (evtJson.LinkedChannel.ChannelType === "threeWayCall") {
  704. holly.phone._phone_currentState = holly.phone._phone_threeWayTalking;
  705. holly.phone._phone_update(evtJson);
  706. } else if (evtJson.LinkedChannel.ChannelType === "transfer") {
  707. holly.phone._phone_currentState = holly.phone._phone_transfer;
  708. holly.phone._phone_update(evtJson);
  709. } else if (evtJson.LinkedChannel.ChannelType === "dialTransfer") {
  710. holly.phone._phone_currentState = holly.phone._phone_dialoutTransfer;
  711. holly.phone._phone_update(evtJson);
  712. }
  713. }
  714. }
  715. }
  716. break;
  717. case holly.phone._phone_innerBelling:
  718. if (evtJson.Event === "ChannelStatus") {
  719. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  720. if (evtJson.ChannelStatus === "Hangup") {
  721. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  722. holly.phone._phone_update(evtJson);
  723. } else if (evtJson.ChannelStatus === "Link") {
  724. if (evtJson.LinkedChannel.ChannelType === "threeWayCall") {
  725. holly.phone._phone_currentState = holly.phone._phone_threeWayTalking;
  726. holly.phone._phone_update(evtJson);
  727. } else if (evtJson.LinkedChannel.ChannelType === "inner") {
  728. holly.phone._phone_currentState = holly.phone._phone_innerTalking;
  729. holly.phone._phone_update(evtJson);
  730. }
  731. }
  732. }
  733. }
  734. break;
  735. case holly.phone._phone_listening:
  736. if (evtJson.Event === "ChannelStatus") {
  737. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  738. if (evtJson.ChannelStatus === "Hangup") {
  739. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  740. holly.phone._phone_update(evtJson);
  741. } else if (evtJson.ChannelStatus === "Up") {
  742. if (evtJson.ChannelType === "listen") {
  743. holly.phone._phone_currentState = holly.phone._phone_listened;
  744. holly.phone._phone_update(evtJson);
  745. }
  746. }
  747. }
  748. }
  749. break;
  750. case holly.phone._phone_talking:
  751. if (evtJson.Event === "ChannelStatus") {
  752. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  753. if (evtJson.ChannelStatus === "Hangup") {
  754. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  755. holly.phone._phone_update(evtJson);
  756. } else if (evtJson.ChannelStatus === "Link") {
  757. if (evtJson.LinkedChannel.ChannelType === "ThreeWayCall") {
  758. holly.phone._phone_currentState = holly.phone._phone_threeWayTalking;
  759. holly.phone._phone_update(evtJson);
  760. }
  761. }
  762. }
  763. }
  764. break;
  765. case holly.phone._phone_transfer:
  766. if (evtJson.Event === "ChannelStatus") {
  767. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  768. if (evtJson.ChannelStatus === "Hangup") {
  769. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  770. holly.phone._phone_update(evtJson);
  771. } else if (evtJson.ChannelStatus === "Link") {
  772. if (evtJson.LinkedChannel.ChannelType === "ThreeWayCall") {
  773. holly.phone._phone_currentState = holly.phone._phone_threeWayTalking;
  774. holly.phone._phone_update(evtJson);
  775. }
  776. }
  777. }
  778. }
  779. break;
  780. case holly.phone._phone_dialoutTransfer:
  781. if (evtJson.Event === "ChannelStatus") {
  782. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  783. if (evtJson.ChannelStatus === "Hangup") {
  784. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  785. holly.phone._phone_update(evtJson);
  786. } else if (evtJson.ChannelStatus === "Link") {
  787. if (evtJson.LinkedChannel.ChannelType === "ThreeWayCall") {
  788. holly.phone._phone_currentState = holly.phone._phone_threeWayTalking;
  789. holly.phone._phone_update(evtJson);
  790. }
  791. }
  792. }
  793. }
  794. break;
  795. case holly.phone._phone_threeWayTalking:
  796. if (evtJson.Event === "ChannelStatus") {
  797. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  798. if (evtJson.ChannelStatus === "Hangup") {
  799. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  800. holly.phone._phone_update(evtJson);
  801. }
  802. }
  803. }
  804. break;
  805. case holly.phone._phone_innerTalking:
  806. if (evtJson.Event === "ChannelStatus") {
  807. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  808. if (evtJson.ChannelStatus === "Hangup") {
  809. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  810. holly.phone._phone_update(evtJson);
  811. }
  812. }
  813. }
  814. break;
  815. case holly.phone._phone_dialTalking:
  816. if (evtJson.Event === "ChannelStatus") {
  817. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  818. if (evtJson.ChannelStatus === "Hangup") {
  819. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  820. holly.phone._phone_update(evtJson);
  821. } else if (evtJson.ChannelStatus === "Link") {
  822. if (evtJson.LinkedChannel.ChannelType === "ThreeWayCall") {
  823. holly.phone._phone_currentState = holly.phone._phone_threeWayTalking;
  824. holly.phone._phone_update(evtJson);
  825. }
  826. }
  827. }
  828. }
  829. break;
  830. case holly.phone._phone_listened:
  831. if (evtJson.Event === "ChannelStatus") {
  832. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  833. if (evtJson.ChannelStatus === "Hangup") {
  834. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  835. holly.phone._phone_update(evtJson);
  836. }
  837. }
  838. }
  839. break;
  840. case holly.phone._phone_transferBelling:
  841. if (evtJson.Event === "ChannelStatus") {
  842. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  843. if (evtJson.ChannelStatus == "Hangup") {
  844. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  845. holly.phone._phone_update(evtJson);
  846. } else if (evtJson.ChannelStatus === "Link") {
  847. if (evtJson.LinkedChannel.ChannelType === "normal") {
  848. holly.phone._phone_currentState = holly.phone._phone_talking;
  849. holly.phone._phone_update(evtJson);
  850. } else if (evtJson.LinkedChannel.ChannelType === "threeWayCall") {
  851. holly.phone._phone_currentState = holly.phone._phone_threeWayTalking;
  852. holly.phone._phone_update(evtJson);
  853. } else if (evtJson.LinkedChannel.ChannelType === "transfer") {
  854. holly.phone._phone_currentState = holly.phone._phone_transfer;
  855. holly.phone._phone_update(evtJson);
  856. } else if (evtJson.LinkedChannel.ChannelType === "dialTransfer") {
  857. holly.phone._phone_currentState = holly.phone._phone_dialoutTransfer;
  858. holly.phone._phone_update(evtJson);
  859. }
  860. }
  861. }
  862. }
  863. break;
  864. case holly.phone._phone_transferDialing:
  865. if (evtJson.Event === "ChannelStatus") {
  866. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  867. if (evtJson.ChannelStatus === "Hangup") {
  868. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  869. holly.phone._phone_update(evtJson);
  870. } else if (evtJson.ChannelStatus === "Link") {
  871. if (evtJson.LinkedChannel.ChannelType === "normal") {
  872. holly.phone._phone_currentState = holly.phone._phone_talking;
  873. holly.phone._phone_update(evtJson);
  874. } else if (evtJson.LinkedChannel.ChannelType === "threeWayCall") {
  875. holly.phone._phone_currentState = holly.phone._phone_threeWayTalking;
  876. holly.phone._phone_update(evtJson);
  877. } else if (evtJson.LinkedChannel.ChannelType === "transfer") {
  878. holly.phone._phone_currentState = holly.phone._phone_transfer;
  879. holly.phone._phone_update(evtJson);
  880. } else if (evtJson.LinkedChannel.ChannelType === "dialTransfer") {
  881. holly.phone._phone_currentState = holly.phone._phone_dialoutTransfer;
  882. holly.phone._phone_update(evtJson);
  883. }
  884. }
  885. }
  886. }
  887. break;
  888. }
  889. },
  890. _phone_monitorPeer: function (evtJson) {
  891. if (evtJson.Event === "ChannelStatus") {
  892. if (evtJson.ChannelStatus === "Hangup" && !evtJson.UserID)
  893. return;
  894. var peer = holly.phone.phone_peers_sip[evtJson.Exten];
  895. if (!peer)
  896. return;
  897. if (evtJson.ChannelStatus === "Down") {
  898. peer.callStatus = "Down";
  899. peer.channel = evtJson.Channel;
  900. holly.phone._phone_updateQueueInfo();
  901. } else if (evtJson.ChannelStatus === "Ring") {
  902. peer.callStatus = "Ring";
  903. peer.called = false;
  904. peer.C5Status = evtJson.C5Status;
  905. peer.timestamp = evtJson.Timestamp;
  906. peer.channel = evtJson.Channel;
  907. peer.queueName = "";
  908. if (evtJson.C5Status === "OutboundCall"
  909. || evtJson.C5Status === "InboundCall"
  910. || evtJson.C5Status === "listen") {
  911. peer.callNo = evtJson.Data.ListenExten;
  912. } else if (evtJson.FromDid)
  913. peer.callNo = evtJson.FromDid;
  914. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  915. } else if (evtJson.ChannelStatus === "Ringing") {
  916. peer.called = true;
  917. peer.callStatus = "Ringing";
  918. peer.C5Status = evtJson.C5Status;
  919. peer.channel = evtJson.Channel;
  920. peer.linkedChannel = evtJson.LinkedChannel.Channel;
  921. if (evtJson.LinkedChannel)
  922. peer.queueName = evtJson.LinkedChannel.QueueName;
  923. if (evtJson.ChannelType === "dialTransfer")
  924. peer.callNo = evtJson.FromDid;
  925. else
  926. peer.callNo = evtJson.FromCid;
  927. peer.timestamp = evtJson.Timestamp;
  928. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  929. } else if (evtJson.ChannelStatus === "Up") {
  930. if (evtJson.ChannelType === "listen") {
  931. peer.callNo = evtJson.Data.ListenExten;
  932. peer.timestamp = evtJson.Timestamp;
  933. peer.C5Status = evtJson.C5Status;
  934. peer.callStatus = evtJson.ChannelType;
  935. peer.linked = true;
  936. peer.channel = evtJson.Channel;
  937. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  938. }
  939. } else if (evtJson.ChannelStatus === "Link") {
  940. peer.timestamp = evtJson.Timestamp;
  941. peer.C5Status = evtJson.C5Status;
  942. peer.linked = true;
  943. peer.channel = evtJson.Channel;
  944. peer.callStatus = evtJson.ChannelType;
  945. if (evtJson.LinkedChannel) {
  946. peer.linkedChannel = evtJson.LinkedChannel.Channel;
  947. peer.queueName = evtJson.LinkedChannel.QueueName;
  948. }
  949. if (evtJson.ChannelType === "dialout"
  950. || evtJson.ChannelType === "dialTransfer")
  951. peer.callNo = evtJson.FromDid;
  952. else if (evtJson.ChannelType === "inner") {
  953. if (evtJson.LinkedChannel) {
  954. var linkExten = evtJson.LinkedChannel.Exten;
  955. // var linkPeer = holly.phone._phone_getUserFromSip(linkExten);
  956. var linkPeer = holly.phone.phone_peers_sip[linkExten];
  957. if (linkPeer) {
  958. if (linkPeer.callStatus !== "inner") {
  959. peer.callNo = evtJson.FromDid;
  960. } else {
  961. peer.callNo = evtJson.FromCid;
  962. }
  963. } else {
  964. peer.callNo = evtJson.FromCid;
  965. }
  966. } else {
  967. peer.callNo = evtJson.FromCid;
  968. }
  969. } else
  970. peer.callNo = evtJson.FromCid;
  971. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  972. } else if (evtJson.ChannelStatus === "Unlink") {
  973. } else if (evtJson.ChannelStatus === "Hangup") {
  974. if (evtJson.ChannelType === "listen") {
  975. if (holly.phone.phone_data._curChannel === evtJson.Channel) {
  976. holly.phone.phone_data._otherChannel = "";
  977. holly.phone.phone_publishEvent("EvtEndListen", []);
  978. }
  979. }
  980. if (peer.channel === evtJson.Channel) {
  981. if (holly.phone.phone_data._otherChannel === evtJson.Channel
  982. && (holly.phone._phone_stateDescription[holly.phone._phone_currentState] === "listening"
  983. || holly.phone._phone_stateDescription[holly.phone._phone_currentState] == "listened")) {
  984. holly.phone.phone_hangup();
  985. }
  986. }
  987. peer.callNo = "";
  988. peer.callStatus = "Idle";
  989. peer.timestamp = evtJson.Timestamp;
  990. peer.channel = "";
  991. peer.linkedChannel = "";
  992. peer.queueName = "";
  993. holly.phone._phone_updateQueueInfo();
  994. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  995. if (evtJson.Exten && peer.sipNo === evtJson.Exten) {
  996. if (hollyglobal.hangupEvent && typeof hollyglobal.hangupEvent === 'function') {
  997. // hollyglobal.hangupEvent(peer);
  998. }
  999. }
  1000. }
  1001. } else if (evtJson.Event === "UserStatus") {
  1002. var isRegistered = false;
  1003. if (evtJson.PeerStatus === "Registered")
  1004. isRegistered = true;
  1005. if (!holly.phone.phone_peers[evtJson.UserID]) {
  1006. peer = {
  1007. exten: evtJson.Exten,
  1008. sipNo: evtJson.SipNum,
  1009. name: evtJson.User,
  1010. DisplayName: evtJson.DisplayName,
  1011. loginExten: evtJson.LoginExten,
  1012. peerStatus: evtJson.PeerStatus,
  1013. status: evtJson.Status,
  1014. C5Status: evtJson.C5Status,
  1015. busy: evtJson.Busy,
  1016. extenType: evtJson.ExtenType,
  1017. login: evtJson.Login,
  1018. userId: evtJson.UserID,
  1019. user: evtJson.User,
  1020. localNo: evtJson.Local,
  1021. register: isRegistered,
  1022. InCalls: evtJson.InCalls,
  1023. InComplete: evtJson.InComplete,
  1024. TransferComplete: evtJson.TransferComplete,
  1025. OutCalls: evtJson.OutCalls,
  1026. OutComplete: evtJson.OutComplete,
  1027. DialoutTimeLength: evtJson.DialoutTimeLength,
  1028. linked: false,
  1029. channel: "",
  1030. linkedChannel: "",
  1031. called: false,//是否是被呼
  1032. callStatus: "Idle",
  1033. callNo: "",
  1034. department: evtJson.DepartmentID ? evtJson.DepartmentID : "",
  1035. timestamp: evtJson.Login ? (evtJson.BusyTimestamp) : "",
  1036. busyTimestamp: evtJson.BusyTimestamp,
  1037. loginTimestamp: evtJson.LoginTimestamp,
  1038. busyType: evtJson.BusyType,
  1039. pinyin: cnToSpell.getSpell(evtJson.DisplayName),
  1040. pbx: evtJson.PBX
  1041. };
  1042. holly.phone.phone_peers[evtJson.UserID] = peer;
  1043. holly.phone.phone_peers_sip[evtJson.SipNum] = peer;
  1044. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  1045. } else {
  1046. peer = holly.phone.phone_peers[evtJson.UserID];
  1047. peer.peerStatus = evtJson.PeerStatus;
  1048. peer.status = evtJson.Status;
  1049. peer.exten = evtJson.Exten;
  1050. peer.sipNo = evtJson.SipNum;
  1051. peer.C5Status = evtJson.C5Status;
  1052. peer.busy = evtJson.Busy;
  1053. peer.extenType = evtJson.ExtenType;
  1054. peer.login = evtJson.Login;
  1055. peer.loginExten = evtJson.LoginExten;
  1056. peer.name = evtJson.User;
  1057. peer.DisplayName = evtJson.DisplayName;
  1058. peer.userId = evtJson.UserID;
  1059. peer.user = evtJson.User;
  1060. peer.localNo = evtJson.Local;
  1061. peer.register = isRegistered;
  1062. peer.InCalls = evtJson.InCalls;
  1063. peer.InComplete = evtJson.InComplete;
  1064. peer.TransferComplete = evtJson.TransferComplete;
  1065. peer.DialoutTimeLength = evtJson.DialoutTimeLength;
  1066. peer.OutCalls = evtJson.OutCalls;
  1067. peer.OutComplete = evtJson.OutComplete;
  1068. peer.department = evtJson.DepartmentID ? evtJson.DepartmentID : "";
  1069. peer.busyTimestamp = evtJson.BusyTimestamp;
  1070. peer.loginTimestamp = evtJson.LoginTimestamp;
  1071. peer.busyType = evtJson.BusyType;
  1072. peer.timestamp = peer.login ? (peer.busyTimestamp) : "";
  1073. if (peer.DisplayName !== evtJson.DisplayName)
  1074. peer.pinyin = cnToSpell.getSpell(evtJson.DisplayName);
  1075. holly.phone.phone_peers_sip[evtJson.SipNum] = peer;
  1076. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  1077. holly.phone._phone_updateQueueInfo();
  1078. }
  1079. } else if (evtJson.Event === "UserBusy") {
  1080. if (holly.phone.phone_peers[evtJson.UserID]) {
  1081. peer = holly.phone.phone_peers[evtJson.UserID];
  1082. peer.busy = evtJson.Busy;
  1083. peer.busyType = evtJson.BusyType;
  1084. peer.busyTimestamp = evtJson.BusyTimestamp;
  1085. peer.timestamp = peer.login ? (peer.busyTimestamp) : "";
  1086. peer.loginTimestamp = evtJson.LoginTimestamp;
  1087. holly.phone.phone_peers_sip[peer.sipNo] = peer;
  1088. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  1089. holly.phone._phone_updateQueueInfo();
  1090. }
  1091. } else if (evtJson.Event === "UserCallsUpdate") {
  1092. if (holly.phone.phone_peers[evtJson.UserID]) {
  1093. peer = holly.phone.phone_peers[evtJson.UserID];
  1094. peer.InCalls = evtJson.InCalls;
  1095. peer.InComplete = evtJson.InComplete;
  1096. peer.TransferComplete = evtJson.TransferComplete;
  1097. peer.DialoutTimeLength = evtJson.DialoutTimeLength;
  1098. peer.OutCalls = evtJson.OutCalls;
  1099. peer.OutComplete = evtJson.OutComplete;
  1100. holly.phone.phone_peers_sip[peer.sipNo] = peer;
  1101. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  1102. holly.phone._phone_updateQueueInfo();
  1103. }
  1104. } else if (evtJson.Event === "UserSignIn") {
  1105. if (holly.phone.phone_peers[evtJson.UserID]) {
  1106. peer = holly.phone.phone_peers[evtJson.UserID];
  1107. peer.extenType = evtJson.ExtenType;
  1108. peer.login = evtJson.Login;
  1109. peer.sipNo = evtJson.SipNum;
  1110. holly.phone.phone_peers_sip[peer.sipNo] = peer;
  1111. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  1112. holly.phone._phone_updateQueueInfo();
  1113. }
  1114. } else if (evtJson.Event === "UserSignOut") {
  1115. if (holly.phone.phone_peers[evtJson.UserID]) {
  1116. peer = holly.phone.phone_peers[evtJson.UserID];
  1117. peer.extenType = evtJson.ExtenType;
  1118. peer.sipNo = evtJson.SipNum;
  1119. peer.login = evtJson.Login;
  1120. holly.phone.phone_peers_sip[peer.sipNo] = peer;
  1121. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  1122. holly.phone._phone_updateQueueInfo();
  1123. }
  1124. } else if (evtJson.Event === "PeerStatus") {
  1125. isRegistered = false;
  1126. if (evtJson.PeerStatus === "Registered")
  1127. isRegistered = true;
  1128. // var peer = holly.phone._phone_getUserFromSip(evtJson.Exten);
  1129. peer = holly.phone.phone_peers_sip[evtJson.Exten];
  1130. if (peer) {
  1131. peer.register = isRegistered;
  1132. peer.status = evtJson.Status;
  1133. if (evtJson.ExtenType && evtJson.ExtenType === 'Local') {
  1134. peer.localNo = evtJson.LocalNum;
  1135. peer.loginExten = evtJson.LocalNum;
  1136. }
  1137. holly.phone.phone_peers[peer.userId] = peer;
  1138. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  1139. holly.phone._phone_updateQueueInfo();
  1140. }
  1141. }
  1142. },
  1143. phone_registerEvent: function (eventName, method) {
  1144. $("#icc_event").on(eventName, method);
  1145. },
  1146. phone_publishEvent: function (eventName, params) {
  1147. $("#icc_event").trigger(eventName, params);
  1148. },
  1149. _phone_updateQueueInfo: function () {
  1150. // if(!phone_queues || phone_queues.length<1)
  1151. // return;
  1152. for (var i in holly.phone.phone_queues) {
  1153. var queue = holly.phone.phone_queues[i];
  1154. var members = queue.members;
  1155. queue.busyAgentCount = 0;
  1156. queue.idleAgentCount = 0;
  1157. for (var j in members) {
  1158. // var peer = holly.phone._phone_getUserFromSip(members[j]);
  1159. var peer = holly.phone.phone_peers_sip[members[j]];
  1160. if (peer) {
  1161. if (peer.extenType === "sip") {
  1162. if (!peer.register
  1163. || !peer.login
  1164. || peer.busy
  1165. || peer.callStatus !== "Idle") {
  1166. queue.busyAgentCount++;
  1167. } else {
  1168. queue.idleAgentCount++;
  1169. }
  1170. } else if (peer.extenType === "gateway") {
  1171. if (!peer.register
  1172. || peer.busy
  1173. || peer.callStatus !== "Idle") {
  1174. queue.busyAgentCount++;
  1175. } else {
  1176. queue.idleAgentCount++;
  1177. }
  1178. } else if (peer.extenType === "Local") {
  1179. if (peer.busy
  1180. || peer.callStatus !== "Idle") {
  1181. queue.busyAgentCount++;
  1182. } else {
  1183. queue.idleAgentCount++;
  1184. }
  1185. } else {
  1186. queue.busyAgentCount++;
  1187. }
  1188. } else {
  1189. queue.idleAgentCount++;
  1190. }
  1191. }
  1192. holly.phone.phone_publishEvent("EvtMonitorQueue", [queue, "noNeedWaitCount"]);
  1193. }
  1194. },
  1195. _phone_update: function (evtJson) {
  1196. //console.info(evtJson)
  1197. var timestamp = "";
  1198. if (evtJson.Event === "ChannelStatus") {
  1199. if (evtJson.Timestamp)
  1200. timestamp = evtJson.Timestamp;
  1201. } else if (evtJson.Event === "UserStatus") {
  1202. timestamp = (evtJson.Login ? (evtJson.BusyTimestamp) : "");
  1203. } else if (evtJson.Event === "UserBusy") {
  1204. timestamp = evtJson.BusyTimestamp;
  1205. }
  1206. if (holly.phone._phone_currentState !== holly.phone._phone_peerstate) {
  1207. holly.utils.hideSoftphonebar();
  1208. } else {
  1209. holly.utils.pickSoftphonebar();
  1210. }
  1211. holly.phone.phone_publishEvent("toolbarupdate", [holly.phone._phone_stateDescription[holly.phone._phone_currentState], timestamp]);
  1212. switch (holly.phone._phone_currentState) {
  1213. case holly.phone._phone_unregister:
  1214. break;
  1215. case holly.phone._phone_peerstate:
  1216. if (evtJson.Event === "ChannelStatus") {
  1217. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  1218. holly.phone.phone_data._curChannel = evtJson.Channel;
  1219. if (evtJson.ChannelStatus === "Hangup") {
  1220. holly.phone.phone_publishEvent("EvtHangup", evtJson);
  1221. }
  1222. }
  1223. }
  1224. break;
  1225. case holly.phone._phone_dialing:
  1226. holly.phone.phone_data._curChannel = evtJson.Channel;
  1227. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  1228. holly.phone.phone_publishEvent("EvtRing", evtJson);
  1229. // holly.softphonebar._softphonebar_evtRing(evtJson);
  1230. }
  1231. break;
  1232. case holly.phone._phone_innerDialing:
  1233. holly.phone.phone_data._curChannel = evtJson.Channel;
  1234. break;
  1235. case holly.phone._phone_belling:
  1236. holly.phone.phone_data._curChannel = evtJson.Channel;
  1237. holly.phone.phone_data._otherChannel = evtJson.LinkedChannel.Channel;
  1238. if (evtJson.Link) {
  1239. holly.phone.phone_publishEvent("EvtRing", evtJson);
  1240. // holly.softphonebar._softphonebar_evtRing(evtJson);
  1241. }
  1242. break;
  1243. case holly.phone._phone_innerBelling:
  1244. holly.phone.phone_data._curChannel = evtJson.Channel;
  1245. holly.phone.phone_data._otherChannel = evtJson.LinkedChannel.Channel;
  1246. if (evtJson.Link) {
  1247. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  1248. // holly.phone.phone_publishEvent("EvtRing", evtJson);
  1249. }
  1250. }
  1251. break;
  1252. case holly.phone._phone_listening:
  1253. holly.phone.phone_data._curChannel = evtJson.Channel;
  1254. break;
  1255. case holly.phone._phone_talking:
  1256. holly.phone.phone_data._curChannel = evtJson.Channel;
  1257. holly.phone.phone_data._otherChannel = evtJson.LinkedChannel.Channel;
  1258. if (evtJson.Exten == holly.phone.phone_data.sipNo) {
  1259. // holly.phone.phone_publishEvent("EvtTalking", evtJson);
  1260. holly.softphonebar._softphonebar_evtTalking(evtJson);
  1261. }
  1262. break;
  1263. case holly.phone._phone_transfer:
  1264. holly.phone.phone_data._curChannel = evtJson.Channel;
  1265. holly.phone.phone_data._otherChannel = evtJson.LinkedChannel.Channel;
  1266. if (evtJson.Link) {
  1267. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  1268. // holly.phone.phone_publishEvent("EvtTalking", evtJson);
  1269. }
  1270. }
  1271. break;
  1272. case holly.phone._phone_dialoutTransfer:
  1273. holly.phone.phone_data._curChannel = evtJson.Channel;
  1274. if (evtJson.LinkedChannel) {
  1275. holly.phone.phone_data._otherChannel = evtJson.LinkedChannel.Channel;
  1276. }
  1277. break;
  1278. case holly.phone._phone_threeWayTalking:
  1279. holly.phone.phone_data._curChannel = evtJson.Channel;
  1280. holly.phone.phone_data._otherChannel = evtJson.LinkedChannel.Channel;
  1281. break;
  1282. case holly.phone._phone_innerTalking:
  1283. holly.phone.phone_data._curChannel = evtJson.Channel;
  1284. if (evtJson.LinkedChannel)
  1285. holly.phone.phone_data._otherChannel = evtJson.LinkedChannel.Channel;
  1286. if (evtJson.Link) {
  1287. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  1288. // holly.phone.phone_publishEvent("EvtTalking", evtJson);
  1289. }
  1290. }
  1291. break;
  1292. case holly.phone._phone_dialTalking:
  1293. holly.phone.phone_data._curChannel = evtJson.Channel;
  1294. holly.phone.phone_data._otherChannel = evtJson.LinkedChannel.Channel;
  1295. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  1296. // holly.phone.phone_publishEvent("EvtTalking", evtJson);
  1297. holly.softphonebar._softphonebar_evtTalking(evtJson);
  1298. }
  1299. break;
  1300. case holly.phone._phone_listened:
  1301. holly.phone.phone_data._curChannel = evtJson.Channel;
  1302. break;
  1303. case holly.phone._phone_transferBelling:
  1304. holly.phone.phone_data._curChannel = evtJson.Channel;
  1305. holly.phone.phone_data._otherChannel = evtJson.LinkedChannel.Channel;
  1306. if (evtJson.Link) {
  1307. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  1308. // holly.phone.phone_publishEvent("EvtRing", evtJson);
  1309. }
  1310. }
  1311. break;
  1312. case holly.phone._phone_transferDialing:
  1313. holly.phone.phone_data._curChannel = evtJson.Channel;
  1314. holly.phone.phone_data._otherChannel = evtJson.LinkedChannel.Channel;
  1315. if (evtJson.Link) {
  1316. var linkedChannel = evtJson.LinkedChannel;
  1317. if (holly.phone._phone_callObject.callId !== linkedChannel.Uniqueid) {
  1318. holly.phone._phone_callObject.callId = linkedChannel.Uniqueid;
  1319. var callsheetid = "";
  1320. if (linkedChannel.Data && linkedChannel.Data.CallSheetID)
  1321. callsheetid = linkedChannel.Data.CallSheetID;
  1322. holly.phone._phone_callObject = {
  1323. callSheetId: callsheetid,
  1324. originId: linkedChannel.Uniqueid,
  1325. originCallNo: linkedChannel.FromDid,
  1326. originCalledNo: linkedChannel.FromCid,
  1327. callType: linkedChannel.ChannelType,
  1328. callId: linkedChannel.Uniqueid,
  1329. queue: linkedChannel.Queue,
  1330. location: linkedChannel.Location,
  1331. offeringTime: holly.phone._phone_dateParse(new Date(evtJson.Timestamp * 1000)),
  1332. callerProvince: decodeURIComponent(evtJson.CallerProvince),
  1333. callerProvinceCode: evtJson.CallerProvinceCode,
  1334. callerCity: decodeURIComponent(evtJson.CallerCity),
  1335. callerCityCode: evtJson.CallerCityCode,
  1336. data: {}
  1337. };
  1338. if (linkedChannel.Data) {
  1339. holly.phone._phone_callObject.data = linkedChannel.Data;
  1340. holly.phone._phone_callObject.data.callSheetId = callsheetid;
  1341. }
  1342. var queue = holly.phone.phone_queues[holly.phone._phone_callObject.queue];
  1343. if (queue) {
  1344. holly.phone._phone_callObject.queueName = queue.queueName;
  1345. }
  1346. // holly.phone.phone_publishEvent("EvtRing", [holly.phone._phone_callObject]);
  1347. }
  1348. }
  1349. break;
  1350. }
  1351. },
  1352. _phone_getUserFromSip: function (sipNo) {
  1353. var peer = holly.phone._phone_peersFromSip[sipNo];
  1354. if (!peer) {
  1355. if (!holly.phone.phone_peers)
  1356. return null;
  1357. for (var i in holly.phone.phone_peers) {
  1358. if (holly.phone.phone_peers[i].sipNo === sipNo) {
  1359. holly.phone._phone_peersFromSip[sipNo] = holly.phone.phone_peers[i];
  1360. return holly.phone._phone_peersFromSip[sipNo];
  1361. }
  1362. }
  1363. return null;
  1364. } else {
  1365. return peer;
  1366. }
  1367. },
  1368. _phone_getUserFromExten: function (exten) {
  1369. if (!holly.phone.phone_peers)
  1370. return null;
  1371. for (var i in holly.phone.phone_peers) {
  1372. if (holly.phone.phone_peers[i].exten === exten) {
  1373. return holly.phone.phone_peers[i];
  1374. }
  1375. }
  1376. return null;
  1377. },
  1378. //根据工号获取坐席登录状态
  1379. _phone_getUserStatusFromExten:function (exten) {
  1380. var peer = holly.phone._phone_getUserFromExten(exten);
  1381. if(peer ==null){
  1382. return "";
  1383. }
  1384. var statusDesc = holly.softphonebar._softphonebar_displayStatus(peer);
  1385. var status = "";
  1386. if (statusDesc.indexOf("span") != -1) {
  1387. status = statusDesc.replace(/<\/?.+?>/g,"");
  1388. } else {
  1389. status = statusDesc;
  1390. }
  1391. return status;
  1392. },
  1393. _phone_super: function (evtJson) {
  1394. if (evtJson.Event === "UserStatus") {
  1395. if (holly.phone.phone_data.userId === evtJson.UserID) {
  1396. holly.phone.phone_data.busyType = evtJson.BusyType;
  1397. if (holly.phone.phone_data.sipNo !== evtJson.SipNum) {
  1398. holly.phone.phone_data.sipNo = evtJson.SipNum;
  1399. if (evtJson.PeerStatus === "Unregistered") {
  1400. holly.phone._phone_currentState = holly.phone._phone_unregister;
  1401. holly.phone._phone_update(evtJson);
  1402. if (hollyglobal.multiLogin) {
  1403. holly.utils.kickSoftphonebar();
  1404. }
  1405. } else if (evtJson.PeerStatus === "Registered") {
  1406. holly.phone._phone_currentState = holly.phone._phone_peerstate;
  1407. holly.phone._phone_update(evtJson);
  1408. if (hollyglobal.multiLogin) {
  1409. holly.utils.pickSoftphonebar();
  1410. }
  1411. }
  1412. }
  1413. }
  1414. } else if (evtJson.Event === "UserBusy") {//空闲
  1415. if (holly.phone.phone_data.userId === evtJson.UserID){
  1416. holly.phone.phone_data.busyType = evtJson.BusyType;
  1417. //console.info(evtJson)
  1418. if(holly.phone.phone_data.busyType!="99"){//通话中时状态
  1419. hollyglobal.actionEvent('busy',evtJson.Busy);
  1420. }
  1421. }
  1422. } else if (evtJson.Event === "ChannelStatus") {
  1423. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  1424. if (evtJson.ChannelStatus === "Unlink") {
  1425. holly.phone.phone_data._curChannel = evtJson.Channel;
  1426. holly.phone.phone_data._callId = "";
  1427. }
  1428. }
  1429. } else if (evtJson.Event === "PeerStatus") {
  1430. if (evtJson.Exten === holly.phone.phone_data.sipNo) {
  1431. if (holly.phone._phone_currentState == holly.phone._phone_peerstate)
  1432. return;
  1433. if (holly.phone.phone_data.busyType == holly.phone._phone_systemBusy)
  1434. return;
  1435. // var peer = holly.phone._phone_getUserFromSip(evtJson.Exten);
  1436. var peer = holly.phone.phone_peers_sip[evtJson.Exten];
  1437. //console.info(peer)
  1438. if (peer)
  1439. holly.phone.phone_publishEvent("toolbarupdate", [holly.phone._phone_stateDescription[holly.phone._phone_currentState], ""]);
  1440. }
  1441. } else if (evtJson.Event === "TransferSuccess"
  1442. || evtJson.Event === "TransferFailed") {
  1443. evtJson.Type = "Transfer";
  1444. if (evtJson.Investigate) {
  1445. evtJson.Type = "Investigate";
  1446. }
  1447. holly.phone.phone_publishEvent("transfering", [evtJson]);
  1448. } else if (evtJson.Event === "IvrMenuEnd") {
  1449. holly.phone.phone_publishEvent("ivrMenuTransfering", [evtJson]);
  1450. } else if (evtJson.Event === "DialinAgentBusyMessage") {
  1451. holly.phone.phone_publishEvent("EvtDialinAgentBusyMessage", [evtJson]);
  1452. }
  1453. },
  1454. phone_dialout: function (phoneNum, interfaceData) {
  1455. if (/^\d+$/.test(phoneNum)) {
  1456. var call_type = "";
  1457. if (phoneNum.length < 5 && phoneNum.length !== 4) {
  1458. var peer = holly.phone._phone_getUserFromExten(phoneNum);
  1459. if (!peer) {
  1460. phoneNum = "9" + phoneNum;
  1461. call_type = "dialout";
  1462. } else {
  1463. call_type = "inner";
  1464. }
  1465. } else if (phoneNum.length === 4) {
  1466. call_type = "inner";
  1467. } else if (phoneNum.length === 5) {
  1468. if (holly.utils.startWith(phoneNum, '1') || holly.utils.startWith(phoneNum, '0') || holly.utils.startWith(phoneNum, '9')) {
  1469. phoneNum = "9" + phoneNum;
  1470. call_type = "dialout";
  1471. } else {
  1472. call_type = "inner";
  1473. }
  1474. } else {
  1475. phoneNum = "9" + phoneNum;
  1476. call_type = "dialout";
  1477. }
  1478. interfaceData = {'tt': '131'};
  1479. // var Variable = "directCallerIDNum%3d13488817474";
  1480. hollyglobal.isPopPage = true;
  1481. var phoneJson = {
  1482. Command: "Action",
  1483. Action: "Originate",
  1484. ActionID: "Originate" + Math.random(),
  1485. Channel: "SIP/" + holly.phone.phone_data.sipNo,
  1486. Context: holly.phone.phone_data.accountId,
  1487. Exten: phoneNum,
  1488. Priority: '1',
  1489. UserID: holly.phone.phone_data.userId,
  1490. Timeout: 60000,
  1491. Async: "true",
  1492. CallType: call_type,
  1493. // Variable:Variable,
  1494. PBX: holly.phone.phone_data.pbx_in_ip,
  1495. Account: holly.phone.phone_data.accountId,
  1496. SessionID: holly.phone.phone_data.uniqueId
  1497. };
  1498. // if(interfaceData)
  1499. // phoneJson.InterfaceData = interfaceData;
  1500. var onload = function (response) {
  1501. try {
  1502. if (!response.Succeed) {
  1503. if (response.Expired) {
  1504. holly.phone._phone_relogin(false);
  1505. }
  1506. } else {
  1507. // if($('#DialEnable'))
  1508. // $('#DialEnable').removeAttr("disabled");
  1509. }
  1510. } catch (e) {
  1511. //if ($('#DialEnable'))
  1512. // $('#DialEnable').removeAttr("disabled");
  1513. }
  1514. }
  1515. var onerror = function () {
  1516. //if ($('#DialEnable'))
  1517. //$('#DialEnable').removeAttr("disabled");
  1518. };
  1519. holly.phone._phone_sendAction(phoneJson, onload, onerror);
  1520. return true;
  1521. } else {
  1522. hollyglobal.msgEvent("请输入正确的电话号码");
  1523. //if ($('#DialEnable'))
  1524. // $('#DialEnable').removeAttr("disabled");
  1525. return false;
  1526. }
  1527. },
  1528. phone_setBusy: function (isBusy, busyType) {
  1529. if (holly.phone._phone_isSettingbusy)
  1530. return;
  1531. else
  1532. holly.phone._phone_isSettingbusy = true;
  1533. var phoneJson = {
  1534. Command: "Action",
  1535. Action: "Busy",
  1536. ActionID: "Busy" + Math.random(),
  1537. Exten: holly.phone.phone_data.userId,
  1538. Busy: isBusy,
  1539. BusyType: "" + busyType,
  1540. PBX: holly.phone.phone_data.pbx_in_ip,
  1541. Account: holly.phone.phone_data.accountId,
  1542. SessionID: holly.phone.phone_data.uniqueId
  1543. };
  1544. var onload = function (response) {
  1545. if (!response.Succeed) {
  1546. if (response.Expired) {
  1547. holly.phone._phone_relogin();
  1548. }
  1549. }
  1550. else {
  1551. //console.info(busyType)
  1552. hollyglobal.actionEvent('busy',busyType==0?false:true)
  1553. //console.info(response)
  1554. }
  1555. holly.phone._phone_isSettingbusy = false;
  1556. }
  1557. var onerror = function () {
  1558. holly.phone._phone_isSettingbusy = false;
  1559. };
  1560. holly.phone._phone_sendAction(phoneJson, onload, onerror);
  1561. },
  1562. phone_hangup: function () {
  1563. var phoneJson = {
  1564. Command: "Action",
  1565. Action: "Hangup",
  1566. ActionID: "Hangup" + Math.random(),
  1567. Channel: holly.phone.phone_data._curChannel,
  1568. PBX: holly.phone.phone_data.pbx_in_ip,
  1569. Account: holly.phone.phone_data.accountId,
  1570. SessionID: holly.phone.phone_data.uniqueId
  1571. };
  1572. var onload = function (response) {
  1573. if (!response.Succeed) {
  1574. if (response.Expired) {
  1575. holly.phone._phone_relogin();
  1576. }
  1577. }
  1578. //else
  1579. // hollyglobal.actionEvent('hangup',true);
  1580. //console.info(response)
  1581. }
  1582. holly.phone._phone_sendAction(phoneJson, onload, function () {
  1583. });
  1584. },
  1585. phone_hold: function () {
  1586. var phoneJson = {
  1587. Command: "Action",
  1588. Action: "Hold",
  1589. ActionID: "Hold" + Math.random(),
  1590. Channel: holly.phone.phone_data._otherChannel,
  1591. UserID: holly.phone.phone_data.userId,
  1592. PBX: holly.phone.phone_data.pbx_in_ip,
  1593. Account: holly.phone.phone_data.accountId,
  1594. SessionID: holly.phone.phone_data.uniqueId
  1595. };
  1596. var onload = function (response) {
  1597. if (response.Succeed) {
  1598. holly.phone._phone_stateBeforeHold = holly.phone._phone_currentState;
  1599. hollyglobal.actionEvent('hold',true);
  1600. //holly.phone.phone_publishEvent("barupdate", ["hold", "continueTime"]);
  1601. } else {
  1602. if (response.Expired) {
  1603. holly.phone._phone_relogin();
  1604. }
  1605. }
  1606. }
  1607. holly.phone._phone_sendAction(phoneJson, onload, function () {
  1608. });
  1609. },
  1610. phone_unhold: function () {
  1611. var phoneJson = {
  1612. Command: "Action",
  1613. Action: "Unhold",
  1614. ActionID: "Unhold" + Math.random(),
  1615. Channel: holly.phone.phone_data._otherChannel,
  1616. UserID: holly.phone.phone_data.userId,
  1617. PBX: holly.phone.phone_data.pbx_in_ip,
  1618. Account: holly.phone.phone_data.accountId,
  1619. SessionID: holly.phone.phone_data.uniqueId
  1620. };
  1621. var onload = function (response) {
  1622. if (response.Succeed) {
  1623. hollyglobal.actionEvent('unhold',true);
  1624. //holly.phone.phone_publishEvent("barupdate", [holly.phone._phone_stateDescription[holly.phone._phone_stateBeforeHold], "continueTime"]);
  1625. } else {
  1626. if (response.Expired) {
  1627. holly.phone._phone_relogin();
  1628. }
  1629. }
  1630. }
  1631. holly.phone._phone_sendAction(phoneJson, onload, function () {
  1632. });
  1633. },
  1634. phone_consult: function (phoneNum, mode) {
  1635. if (mode === "number") {
  1636. if (phoneNum.length <= 6) {
  1637. var phoneNumBak = phoneNum;
  1638. phoneNum = phoneNum.substr(1);
  1639. if (phoneNum.length === 5) {
  1640. if (holly.utils.startWith(phoneNum, '1') || holly.utils.startWith(phoneNum, '0') || holly.utils.startWith(phoneNum, '9')) {
  1641. holly.softphonebar._softphonebar_showConsult(phoneNumBak + " ");
  1642. phoneNum = phoneNumBak;
  1643. } else {
  1644. holly.softphonebar._softphonebar_showConsult("工号 " + phoneNum + " ");
  1645. }
  1646. } else if (phoneNum.length === 4) {
  1647. if (holly.utils.startWith(phoneNum, '0') || holly.utils.startWith(phoneNum, '9')) {
  1648. holly.softphonebar._softphonebar_showConsult(phoneNumBak + " ");
  1649. phoneNum = phoneNumBak;
  1650. } else {
  1651. holly.softphonebar._softphonebar_showConsult("工号 " + phoneNum + " ");
  1652. }
  1653. }
  1654. } else
  1655. holly.softphonebar._softphonebar_showConsult(phoneNum + " ");
  1656. } else if (mode === "skillgroup") {
  1657. holly.softphonebar._softphonebar_showConsult(phoneNum + " ");
  1658. }
  1659. var phoneJson = {
  1660. Command: "Action",
  1661. Action: "Consult",
  1662. ActionID: "Consult" + Math.random(),
  1663. FromExten: holly.phone.phone_data.sipNo,
  1664. Exten: phoneNum,
  1665. Timeout: 60000,
  1666. UserID: holly.phone.phone_data.userId,
  1667. PBX: holly.phone.phone_data.pbx_in_ip,
  1668. Account: holly.phone.phone_data.accountId,
  1669. SessionID: holly.phone.phone_data.uniqueId
  1670. };
  1671. var onload = function (response) {
  1672. holly.softphonebar.softphonebar_close();
  1673. if (response.Succeed) {
  1674. holly.utils.showTransferOrConsultSucc("咨询成功", "softphone_consult");
  1675. holly.phone.phone_publishEvent("toolbarupdate", ["consultTalking", "continueTime"]);
  1676. } else {
  1677. holly.utils.showTransferOrConsultError("咨询失败", "softphone_consult");
  1678. if (response.Expired) {
  1679. holly.phone._phone_relogin();
  1680. }
  1681. }
  1682. }
  1683. var error = function () {
  1684. holly.softphonebar.softphonebar_close();
  1685. holly.utils.showTransferOrConsultError("咨询失败", "softphone_consult");
  1686. }
  1687. holly.phone._phone_sendAction(phoneJson, onload, error);
  1688. },
  1689. phone_stopConsult: function () {
  1690. var phoneJson = {
  1691. Command: "Action",
  1692. Action: "StopConsult",
  1693. ActionID: "StopConsult" + Math.random(),
  1694. FromExten: holly.phone.phone_data.sipNo,
  1695. Timeout: 60000,
  1696. UserID: holly.phone.phone_data.userId,
  1697. PBX: holly.phone.phone_data.pbx_in_ip,
  1698. Account: holly.phone.phone_data.accountId,
  1699. SessionID: holly.phone.phone_data.uniqueId
  1700. };
  1701. var onload = function (response) {
  1702. if (response.Succeed) {
  1703. if (response.Message != undefined) {
  1704. if (response.Message === "Idle") {
  1705. holly.phone.phone_publishEvent("toolbarupdate", ["peerstate", "continueTime"]);
  1706. } else {
  1707. holly.phone.phone_publishEvent("toolbarupdate", ["talking", "continueTime"]);
  1708. }
  1709. } else {
  1710. holly.phone.phone_publishEvent("toolbarupdate", ["talking", "continueTime"]);
  1711. }
  1712. } else {
  1713. holly.utils.showTransferOrConsultError("结束咨询通话失败", "softphone_consult");
  1714. if (response.Expired) {
  1715. holly.phone._phone_relogin();
  1716. }
  1717. }
  1718. }
  1719. var error = function () {
  1720. holly.utils.showTransferOrConsultError("结束咨询通话失败", "softphone_consult");
  1721. }
  1722. holly.phone._phone_sendAction(phoneJson, onload, error);
  1723. },
  1724. phone_toMenu: function (exten, displayName) {
  1725. holly.softphonebar.softphonebar_closeModel();
  1726. holly.softphonebar._softphonebar_showToMenu(displayName);
  1727. var phoneJson = {
  1728. Command: "Action",
  1729. Action: "IvrMenu",
  1730. ActionID: "IvrMenu" + Math.random(),
  1731. Channel: holly.phone.phone_data._otherChannel,
  1732. Context: exten,
  1733. PBX: holly.phone.phone_data.pbx_in_ip,
  1734. Account: holly.phone.phone_data.accountId
  1735. }
  1736. var onload = function (response) {
  1737. if (response.Succeed) {
  1738. //holly.softphonebar.softphonebar_closeModel();
  1739. } else {
  1740. holly.softphonebar.softphonebar_close();
  1741. holly.utils.showError("转IVR菜单失败", "softphone_transfer");
  1742. if (response.Expired) {
  1743. holly.phone._phone_relogin();
  1744. }
  1745. }
  1746. }
  1747. var error = function () {
  1748. holly.softphonebar.softphonebar_close();
  1749. holly.utils.showError("转IVR菜单失败", "softphone_transfer");
  1750. }
  1751. holly.phone._phone_sendAction(phoneJson, onload, error);
  1752. },
  1753. phone_transfer: function (phoneNum, mode) {
  1754. if (mode == "number") {
  1755. if (phoneNum.length <= 6) {
  1756. var phoneNumBak = phoneNum;
  1757. phoneNum = phoneNum.substr(1);
  1758. if (phoneNum.length === 5) {
  1759. if (holly.utils.startWith(phoneNum, '1') || holly.utils.startWith(phoneNum, '0') || holly.utils.startWith(phoneNum, '9')) {
  1760. holly.softphonebar._softphonebar_showTranster(phoneNumBak + " ");
  1761. phoneNum = phoneNumBak;
  1762. } else {
  1763. holly.softphonebar._softphonebar_showTranster("工号 " + phoneNum + " ");
  1764. }
  1765. } else if (phoneNum.length === 4) {
  1766. if (holly.utils.startWith(phoneNum, '0') || holly.utils.startWith(phoneNum, '9')) {
  1767. holly.softphonebar._softphonebar_showTranster(phoneNumBak + " ");
  1768. phoneNum = phoneNumBak;
  1769. } else {
  1770. holly.softphonebar._softphonebar_showTranster("工号 " + phoneNum + " ");
  1771. }
  1772. }
  1773. } else
  1774. holly.softphonebar._softphonebar_showTranster(phoneNum + " ");
  1775. } else if (mode == "skillgroup") {
  1776. holly.softphonebar._softphonebar_showTranster(phoneNum + " ");
  1777. }
  1778. var phoneJson = {
  1779. Command: "Action",
  1780. Action: "Transfer",
  1781. ActionID: "Transfer" + Math.random(),
  1782. Exten: phoneNum,
  1783. Channel: holly.phone.phone_data._otherChannel,
  1784. ExtraChannel: holly.phone.phone_data._curChannel,
  1785. UserID: holly.phone.phone_data.userId,
  1786. Context: holly.phone.phone_data.accountId,
  1787. PBX: holly.phone.phone_data.pbx_in_ip,
  1788. Account: holly.phone.phone_data.accountId,
  1789. SessionID: holly.phone.phone_data.uniqueId
  1790. };
  1791. var onload = function (response) {
  1792. if (response.Succeed) {
  1793. holly.softphonebar.softphonebar_close();
  1794. holly.utils.showTransferOrConsultSucc("转接成功", 'softphone_transfer');
  1795. } else {
  1796. holly.softphonebar.softphonebar_close();
  1797. var message = "";
  1798. if (response.Message == "310") {
  1799. message = "未配置外呼线路";
  1800. } else if (response.Message == "311") {
  1801. message = "转接的用户忙";
  1802. } else if (response.Message == "312") {
  1803. message = "转接的用户未签入";
  1804. } else if (response.Message == "313") {
  1805. message = "转接的用户正在通话";
  1806. } else if (response.Message == "314") {
  1807. message = "转接的用户没有以通话方式登录";
  1808. } else if (response.Message == "315") {
  1809. message = "无法呼通转接的用户";
  1810. } else if (response.Message == "316") {
  1811. message = "转接用户不存在";
  1812. } else {
  1813. message = "";
  1814. }
  1815. if (message == "") {
  1816. holly.utils.showTransferOrConsultError("转接失败", 'softphone_transfer');
  1817. } else {
  1818. holly.utils.showTransferOrConsultError("转接失败:" + message, 'softphone_transfer');
  1819. }
  1820. if (response.Expired) {
  1821. holly.phone._phone_relogin();
  1822. }
  1823. }
  1824. }
  1825. var error = function () {
  1826. holly.softphonebar.softphonebar_close();
  1827. holly.utils.showTransferOrConsultError("转接失败", 'softphone_transfer');
  1828. }
  1829. holly.phone._phone_sendAction(phoneJson, onload, error);
  1830. },
  1831. phone_cancelTransfer: function () {
  1832. if (holly.phone.phone_data._otherChannel) {
  1833. var phoneJson = {
  1834. Command: "Action",
  1835. Action: "CancelTransfer",
  1836. ActionID: "CancelTransfer" + Math.random(),
  1837. Channel: holly.phone.phone_data._otherChannel,
  1838. PBX: holly.phone.phone_data.pbx_in_ip,
  1839. Account: holly.phone.phone_data.accountId,
  1840. SessionID: holly.phone.phone_data.uniqueId
  1841. };
  1842. var onload = function (response) {
  1843. holly.softphonebar.softphonebar_close();
  1844. if (response.Succeed) {
  1845. holly.utils.showTransferOrConsultSucc("取消转接成功", 'softphone_transfer');
  1846. } else {
  1847. holly.utils.showTransferOrConsultError("取消转接失败", 'softphone_transfer');
  1848. if (response.Expired) {
  1849. holly.phone._phone_relogin();
  1850. }
  1851. }
  1852. }
  1853. var error = function () {
  1854. holly.softphonebar.softphonebar_close();
  1855. holly.utils.showTransferOrConsultError("取消转接失败", "softphone_transfer");
  1856. }
  1857. holly.phone._phone_sendAction(phoneJson, onload, error);
  1858. }
  1859. },
  1860. phone_threewaycall: function (phoneNum) {
  1861. var phoneJson = {
  1862. Command: "Action",
  1863. Action: "ThreeWayCall",
  1864. ActionID: "ThreeWayCall" + Math.random(),
  1865. FromExten: holly.phone.phone_data.sipNo,
  1866. Exten: phoneNum,
  1867. Timeout: 60000,
  1868. UserID: holly.phone.phone_data.userId,
  1869. PBX: holly.phone.phone_data.pbx_in_ip,
  1870. Account: holly.phone.phone_data.accountId,
  1871. SessionID: holly.phone.phone_data.uniqueId
  1872. };
  1873. var onload = function (response) {
  1874. holly.softphonebar.softphonebar_close();
  1875. if (response.Succeed) {
  1876. holly.utils.showTransferOrConsultSucc("三方通话成功", "softphone_consult");
  1877. holly.phone.phone_publishEvent("toolbarupdate", ["threeWayTalking", ""]);
  1878. } else {
  1879. holly.utils.showTransferOrConsultError("三方通话失败", "softphone_consult");
  1880. if (response.Expired) {
  1881. holly.phone._phone_relogin();
  1882. }
  1883. }
  1884. }
  1885. var error = function () {
  1886. holly.softphonebar.softphonebar_close();
  1887. holly.utils.showTransferOrConsultError("咨询失败", "softphone_consult");
  1888. }
  1889. holly.phone._phone_sendAction(phoneJson, onload, error);
  1890. },
  1891. phone_kick: function (userId) {
  1892. var currentPeer = holly.phone.phone_peers[window.localStorage.getItem('currentLoginAgent')];
  1893. var phoneJson = {
  1894. Command: "Action",
  1895. Action: "Kick",
  1896. ActionID: "Kick" + Math.random(),
  1897. Exten: userId,
  1898. UserID: holly.phone.phone_data.userId,
  1899. PBX: holly.phone.phone_data.pbx_in_ip || currentPeer.pbx,
  1900. Account: holly.phone.phone_data.accountId || currentPeer.accountId,
  1901. SessionID: holly.phone.phone_data.uniqueId
  1902. };
  1903. var onload = function (response) {
  1904. if (response.Succeed) {
  1905. var peer = holly.phone.phone_peers[userId];
  1906. if (peer) {
  1907. peer.C5Status = "";
  1908. peer.callNo = "";
  1909. peer.callStatus = "Idle";
  1910. var date = new Date();
  1911. var identity = date.valueOf();
  1912. peer.timestamp = identity / 1000;
  1913. peer.channel = "";
  1914. peer.linkedChannel = "";
  1915. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  1916. holly.phone._phone_updateQueueInfo();
  1917. }
  1918. } else {
  1919. if (response.Expired) {
  1920. holly.phone._phone_relogin();
  1921. }
  1922. }
  1923. }
  1924. var error = function () {
  1925. }
  1926. holly.phone._phone_sendAction(phoneJson, onload, error);
  1927. },
  1928. phone_toIVR: function () {
  1929. if (holly.phone._phone_isToIVR)
  1930. return;
  1931. holly.phone._phone_isToIVR = true;
  1932. var phoneJson = {
  1933. Command: "Action",
  1934. Action: "Validate",
  1935. ActionID: "Validate" + Math.random(),
  1936. Exten: 's',
  1937. Channel: holly.phone.phone_data._otherChannel,
  1938. Timeout: 60000,
  1939. UserID: holly.phone.phone_data.userId,
  1940. Context: holly.phone.phone_data.accountId + "-validate",
  1941. PBX: holly.phone.phone_data.pbx_in_ip,
  1942. Account: holly.phone.phone_data.accountId,
  1943. SessionID: holly.phone.phone_data.uniqueId
  1944. };
  1945. var onload = function (response) {
  1946. if (!response.Succeed) {
  1947. if (response.Expired) {
  1948. holly.phone._phone_relogin();
  1949. }
  1950. }
  1951. holly.phone._phone_isToIVR = false;
  1952. }
  1953. var error = function () {
  1954. holly.phone._phone_isToIVR = false;
  1955. }
  1956. holly.phone._phone_sendAction(phoneJson, onload, error);
  1957. },
  1958. phone_kickFromPbx: function (userId, pbx) {
  1959. var phone_pbx = holly.phone.phone_pbxs[pbx];
  1960. var currentPeer = holly.phone.phone_peers[window.localStorage.getItem('currentLoginAgent')];
  1961. var url = phone_pbx.proxyUrl;
  1962. var phoneJson = {
  1963. Command: "Action",
  1964. Action: "Kick",
  1965. ActionID: "Kick" + Math.random(),
  1966. Exten: userId,
  1967. UserID: holly.phone.phone_data.userId,
  1968. PBX: pbx,
  1969. Account: holly.phone.phone_data.accountId || currentPeer.accountId,
  1970. SessionID: phone_pbx.sessionId
  1971. };
  1972. var onload = function (response) {
  1973. if (response.Succeed) {
  1974. var peer = holly.phone.phone_peers[userId];
  1975. if (peer) {
  1976. peer.C5Status = "";
  1977. peer.callNo = "";
  1978. peer.callStatus = "Idle";
  1979. var date = new Date();
  1980. var identity = date.valueOf();
  1981. peer.timestamp = identity / 1000;
  1982. peer.channel = "";
  1983. peer.linkedChannel = "";
  1984. holly.phone.phone_publishEvent("EvtMonitorPeer", [peer]);
  1985. holly.phone._phone_updateQueueInfo();
  1986. }
  1987. } else {
  1988. if (response.Expired) {
  1989. holly.phone._phone_relogin();
  1990. }
  1991. }
  1992. }
  1993. var error = function () {
  1994. }
  1995. var json = $.toJSON(phoneJson);
  1996. var timeout = 15000;
  1997. $.ajax({
  1998. type: "get",
  1999. url: url,
  2000. timeout: timeout,
  2001. cache: false,
  2002. data: {json: json},
  2003. dataType: "jsonp",
  2004. jsonp: "callbackName",
  2005. success: onload,
  2006. error: onerror
  2007. });
  2008. },
  2009. phone_pick: function (userId) {
  2010. var currentPeer = holly.phone.phone_peers[window.localStorage.getItem('currentLoginAgent')];
  2011. var peer = holly.phone.phone_peers[userId];
  2012. if (peer == null || peer.localNo == null || peer.localNo == "") {
  2013. holly.utils.showError("不能对没有直线号码的座席做签入操作", "softphone_transfer");
  2014. return;
  2015. }
  2016. var phoneJson = {
  2017. Command: "Action",
  2018. Action: "SignIn",
  2019. ActionID: "SignIn" + Math.random(),
  2020. User: userId,
  2021. UserID: holly.phone.phone_data.userId,
  2022. PBX: holly.phone.phone_data.pbx_in_ip || currentPeer.pbx,
  2023. Account: holly.phone.phone_data.accountId || currentPeer.accountId,
  2024. SessionID: holly.phone.phone_data.uniqueId
  2025. };
  2026. var onload = function (response) {
  2027. if (response.Succeed) {
  2028. holly.utils.showSucc("座席签入成功", "softphone_transfer");
  2029. } else {
  2030. holly.utils.showError("当前在线座席总数已达最大值,无法再签入", "softphone_transfer");
  2031. if (response.Expired) {
  2032. holly.phone._phone_relogin();
  2033. }
  2034. }
  2035. }
  2036. var error = function () {
  2037. }
  2038. holly.phone._phone_sendAction(phoneJson, onload, error);
  2039. },
  2040. phone_hangupChannel: function (channel) {
  2041. var currentPeer = holly.phone.phone_peers[window.localStorage.getItem('currentLoginAgent')];
  2042. var phoneJson = {
  2043. Command: "Action",
  2044. Action: "Hangup",
  2045. ActionID: "ForceHangup" + Math.random(),
  2046. Channel: channel,
  2047. UserID: holly.phone.phone_data.userId,
  2048. PBX: holly.phone.phone_data.pbx_in_ip || currentPeer.pbx,
  2049. Account: holly.phone.phone_data.accountId || currentPeer.accountId,
  2050. SessionID: holly.phone.phone_data.uniqueId
  2051. };
  2052. var onload = function (response) {
  2053. }
  2054. var error = function () {
  2055. }
  2056. holly.phone._phone_sendAction(phoneJson, onload, error);
  2057. },
  2058. phone_hangupChannelFromPbx: function (channel, pbx) {
  2059. var phone_pbx = holly.phone.phone_pbxs[pbx];
  2060. var currentPeer = holly.phone.phone_peers[window.localStorage.getItem('currentLoginAgent')];
  2061. var url = phone_pbx.proxyUrl;
  2062. var phoneJson = {
  2063. Command: "Action",
  2064. Action: "Hangup",
  2065. ActionID: "ForceHangup" + Math.random(),
  2066. Channel: channel,
  2067. UserID: holly.phone.phone_data.userId,
  2068. PBX: pbx,
  2069. Account: holly.phone.phone_data.accountId || currentPeer.accountId,
  2070. SessionID: phone_pbx.sessionId
  2071. };
  2072. var onload = function (response) {
  2073. }
  2074. var error = function () {
  2075. }
  2076. var json = $.toJSON(phoneJson);
  2077. var timeout = 15000;
  2078. $.ajax({
  2079. type: "get",
  2080. url: url,
  2081. timeout: timeout,
  2082. cache: false,
  2083. data: {json: json},
  2084. dataType: "jsonp",
  2085. jsonp: "callbackName",
  2086. success: onload,
  2087. error: onerror
  2088. });
  2089. },
  2090. phone_loot: function (channel) {
  2091. var currentPeer = holly.phone.phone_peers[window.localStorage.getItem('currentLoginAgent')];
  2092. if (currentPeer.busyType == "0") {
  2093. holly.utils.showError("请先将电话置为忙碌", "softphone_transfer");
  2094. return;
  2095. }
  2096. var phoneJson = {
  2097. Command: "Action",
  2098. Action: "Transfer",
  2099. ActionID: "Transfer" + Math.random(),
  2100. Exten: holly.phone.phone_data.sipNo || currentPeer.sipNo,
  2101. Channel: channel,
  2102. CallType: "Loot",
  2103. Context: holly.phone.phone_data.accountId || currentPeer.accountId,
  2104. UserID: holly.phone.phone_data.userId,
  2105. PBX: holly.phone.phone_data.pbx_in_ip || currentPeer.pbx,
  2106. Account: holly.phone.phone_data.accountId || currentPeer.accountId,
  2107. SessionID: holly.phone.phone_data.uniqueId
  2108. };
  2109. var onload = function (response) {
  2110. if (!response.Succeed) {
  2111. if (response.Expired) {
  2112. holly.phone._phone_relogin();
  2113. }
  2114. }
  2115. }
  2116. var error = function () {
  2117. }
  2118. holly.phone._phone_sendAction(phoneJson, onload, error);
  2119. },
  2120. phone_pickFromPbx: function (userId, pbx) {
  2121. var peer = holly.phone.phone_peers[userId];
  2122. var currentPeer = holly.phone.phone_peers[window.localStorage.getItem('currentLoginAgent')];
  2123. if (peer == null || peer.localNo == null || peer.localNo == "") {
  2124. holly.utils.showError("不能对没有直线号码的座席做签入操作", "softphone_transfer");
  2125. return;
  2126. }
  2127. var phone_pbx = holly.phone.phone_pbxs[pbx];
  2128. var url = phone_pbx.proxyUrl;
  2129. var phoneJson = {
  2130. Command: "Action",
  2131. Action: "SignIn",
  2132. ActionID: "SignIn" + Math.random(),
  2133. User: userId,
  2134. UserID: holly.phone.phone_data.userId,
  2135. PBX: pbx,
  2136. Account: holly.phone.phone_data.accountId || currentPeer.accountId,
  2137. SessionID: phone_pbx.sessionId
  2138. };
  2139. var onload = function (response) {
  2140. if (response.Succeed) {
  2141. holly.utils.showSucc("座席签入成功", "softphone_transfer");
  2142. } else {
  2143. holly.utils.showError("当前在线座席总数已达最大值,无法再签入", "softphone_transfer");
  2144. if (response.Expired) {
  2145. holly.phone._phone_relogin(true);
  2146. }
  2147. }
  2148. }
  2149. var error = function () {
  2150. }
  2151. var json = $.toJSON(phoneJson);
  2152. var timeout = 15000;
  2153. $.ajax({
  2154. type: "get",
  2155. url: url,
  2156. timeout: timeout,
  2157. cache: false,
  2158. data: {json: json},
  2159. dataType: "jsonp",
  2160. jsonp: "callbackName",
  2161. success: onload,
  2162. error: onerror
  2163. });
  2164. },
  2165. phone_investigate: function () {
  2166. if (holly.phone._phone_isInvestigatting)
  2167. return;
  2168. holly.phone._phone_isInvestigatting = true;
  2169. var phoneJson = {
  2170. Command: "Action",
  2171. Action: "Transfer",
  2172. ActionID: "Transfer" + Math.random(),
  2173. Exten: 's',
  2174. Channel: holly.phone.phone_data._otherChannel,
  2175. Timeout: 60000,
  2176. CallType: 'investigate',
  2177. UserID: holly.phone.phone_data.userId,
  2178. Context: holly.phone.phone_data.accountId + "-investigate",
  2179. PBX: holly.phone.phone_data.pbx_in_ip,
  2180. Account: holly.phone.phone_data.accountId,
  2181. SessionID: holly.phone.phone_data.uniqueId
  2182. };
  2183. var onload = function (response) {
  2184. if (response.Succeed) {
  2185. } else {
  2186. if (response.Expired) {
  2187. holly.phone._phone_relogin();
  2188. }
  2189. }
  2190. holly.phone._phone_isInvestigatting = false;
  2191. }
  2192. var error = function () {
  2193. holly.phone._phone_isInvestigatting = false;
  2194. }
  2195. holly.phone._phone_sendAction(phoneJson, onload, error);
  2196. },
  2197. _phone_exit: function (removeQueue) {
  2198. if (!removeQueue)
  2199. removeQueue = false;
  2200. if (!holly.phone.phone_data.uniqueId) {
  2201. phone_data = {};
  2202. holly.session.logined = false;
  2203. window.location = './softphoneBar.html';
  2204. return;
  2205. }
  2206. var actionName = "Logoff";
  2207. if (hollyglobal.multiLogin) {
  2208. actionName = "MultipleLogoff";
  2209. }
  2210. var phoneJson = {
  2211. Command: "Action",
  2212. Action: "Logoff",
  2213. ActionID: "Logoff" + Math.random(),
  2214. QueueRemove: removeQueue,
  2215. User: holly.phone.phone_data.userId,
  2216. PBX: holly.phone.phone_data.pbx_in_ip,
  2217. Account: holly.phone.phone_data.accountId,
  2218. SessionID: holly.phone.phone_data.uniqueId
  2219. };
  2220. var onload = function (response) {
  2221. if (response.Succeed) {
  2222. holly.utils.kickSoftphonebar();
  2223. holly.session.logined = false;
  2224. holly.phone._phone_isKick = false;
  2225. holly.softphonebar._softphonebar_barupdate('', 'unregister', '');
  2226. }
  2227. }
  2228. holly.phone._phone_sendAction(phoneJson, onload, function () {
  2229. });
  2230. },
  2231. _phone_dateParse: function (date) {
  2232. var year = date.getFullYear();
  2233. var month = date.getMonth() + 1;
  2234. var day = date.getDate();
  2235. var hour = date.getHours();
  2236. var minute = date.getMinutes();
  2237. var second = date.getSeconds();
  2238. return year + "-" + (month > 9 ? month : "0" + month) + "-" + (day > 9 ? day : "0" + day) + " "
  2239. + (hour > 9 ? hour : "0" + hour) + ":" + (minute > 9 ? minute : "0" + minute) + ":" + (second > 9 ? second : "0" + second);
  2240. },
  2241. phone_isAllowDialout: function () {
  2242. //console.info(holly.phone._phone_stateDescription[holly.phone._phone_currentState])
  2243. return holly.phone._phone_stateDescription[holly.phone._phone_currentState] == "peerstate";
  2244. },
  2245. phone_closeTransfer: function () {
  2246. var bgObj = document.getElementById("hollyc5.bgDiv");
  2247. var msgObj = document.getElementById("hollyc5.msgDiv");
  2248. if (msgObj != null) {
  2249. document.getElementById("TransferEnable1").removeChild(msgObj);
  2250. }
  2251. if (bgObj != null) {
  2252. document.getElementById("TransferEnable1").removeChild(bgObj);
  2253. }
  2254. },
  2255. phone_openTransferOrConsult: function (objectId) {
  2256. $("#softphone-bar-bgdiv").css({display: "block", height: $(document).height()});
  2257. var inputElement = "<input type=\"text\" id=\"" + objectId + "_div_input\" style=\"width:160px;height:20px;color:#938c8c;float:left;padding-right: 10px;\" " +
  2258. "value=\"请输入工号或者手机号\" onfocus=\"if(this.value=='请输入工号或者手机号'){this.value='';this.style.color='#000'}\" " +
  2259. "onblur=\"if(this.value==''){this.value='请输入工号或者手机号';this.style.color='#938c8c'}\" autocomplete='off'/>";
  2260. var bodyHtml = "<div class='modal-body' style='height:30px;padding:9px 0 0 2px;' >" + inputElement;
  2261. if (objectId === 'softphone_transfer') {
  2262. bodyHtml += "<button class='btn btn-small btn-primary' type='button' style='float:left;margin-left:5px;' onclick=\"javascript:holly.softphonebar.softphonebar_transfer($('#" + objectId + "_div_input').val())\">转 接</button>";
  2263. // bodyHtml +="<button class='btn btn-small btn-primary' type='button' style='float:left;margin-left:5px;' onclick=\"holly.softphonebar._softphonebar_showTranster('913488817474')\">转 接</button>";
  2264. // bodyHtml +="<button class='btn btn-small btn-primary' type='button' style='float:left;margin-left:5px;' onclick=\"holly.utils.showTransferOrConsultError('913488817474','softphone_transfer')\">转 接</button>";
  2265. } else
  2266. bodyHtml += "<button class='btn btn-small btn-primary' type='button' style='float:left;margin-left:5px;' onclick=\"javascript:holly.softphonebar.softphonebar_consult($('#" + objectId + "_div_input').val())\">咨 询</button>";
  2267. // bodyHtml +="<button class='btn btn-small btn-primary' type='button' style='float:left;margin-left:5px;' onclick=\"holly.softphonebar._softphonebar_showConsult('913488817474')\">咨 询</button>";
  2268. bodyHtml += "<button class='btn btn-small btn-primary' type='button' style='float:left;margin-left:5px;' onclick=\"javascript:holly.phone.phone_closeDiv();\">关 闭</button></div>";
  2269. $('#' + objectId).empty();
  2270. $('#' + objectId).html(bodyHtml);
  2271. document.documentElement.scrollTop = 0;
  2272. $('#' + objectId).fadeIn('fast');
  2273. },
  2274. phone_listen: function (curChannel,currentPeer) {
  2275. var phoneJson = {
  2276. Command: "Action",
  2277. Action: "Originate",
  2278. ActionID: "Originate" + Math.random(),
  2279. Channel: "SIP/" + holly.phone.phone_data.sipNo,
  2280. Application: "ChanSpy",
  2281. Data: curChannel + "|bq",
  2282. Callerid: holly.phone.phone_data.sipNo || currentPeer.sipNo,
  2283. UserID: holly.phone.phone_data.userId,
  2284. PBX: holly.phone.phone_data.pbx_in_ip || currentPeer.pbx,
  2285. Account: holly.phone.phone_data.accountId || currentPeer.accountId,
  2286. SessionID: holly.phone.phone_data.uniqueId
  2287. };
  2288. var onload = function (response) {
  2289. if (response.Succeed) {
  2290. holly.phone.phone_data._otherChannel = curChannel;
  2291. } else {
  2292. if (response.Expired) {
  2293. holly.phone._phone_relogin();
  2294. }
  2295. }
  2296. }
  2297. var error = function () {
  2298. }
  2299. holly.phone._phone_sendAction(phoneJson, onload, error);
  2300. return true;
  2301. },
  2302. phone_closeDiv: function () {
  2303. var pagedir = $('#softphone-bar-bgdiv');
  2304. var transferObj = $('#softphone_transfer');
  2305. var consultObj = $('#softphone_consult');
  2306. if (transferObj != null) {
  2307. transferObj.css('display', 'none');
  2308. }
  2309. if (consultObj != null) {
  2310. consultObj.css('display', 'none');
  2311. }
  2312. if (pagedir != null) {
  2313. pagedir.css('display', 'none');
  2314. }
  2315. },
  2316. phone_unregisterEvent: function (eventName) {
  2317. $("#icc_event").unbind(eventName);
  2318. },
  2319. _phone_queryQueueItem: function (evtJson) {
  2320. return holly.phone.phone_queues[evtJson.Queue];
  2321. },
  2322. _phone_monitorQueue: function (evtJson) {
  2323. if (evtJson.Event === "QueueParams") {
  2324. var queueItem = holly.phone._phone_queryQueueItem(evtJson);
  2325. var member;
  2326. if (queueItem) {
  2327. if (evtJson.Removed) {
  2328. queueItem.removed = true;
  2329. }
  2330. queueItem.queueName = evtJson.DisplayName;
  2331. queueItem.idleAgentCount = evtJson.Members - evtJson.BusyMembers;
  2332. queueItem.busyAgentCount = evtJson.BusyMembers;
  2333. queueItem.totalAgentCount = evtJson.Members;
  2334. queueItem.queueWaitCount = evtJson.Calls;
  2335. queueItem.abadonedCalls = evtJson.Abandoned;
  2336. queueItem.totalCalls = evtJson.TotalCalls;
  2337. queueItem.DisplayName = evtJson.DisplayName;
  2338. queueItem.members = [];
  2339. for (var i in evtJson.QueueMember) {
  2340. member = evtJson.QueueMember[i];
  2341. queueItem.members[member] = member;
  2342. }
  2343. holly.phone.phone_publishEvent("EvtMonitorQueue", [queueItem, "needWaitCount"]);
  2344. } else {
  2345. queueItem = {
  2346. queueName: evtJson.DisplayName,
  2347. queueId: evtJson.Queue,
  2348. idleAgentCount: evtJson.Members - evtJson.BusyMembers,
  2349. busyAgentCount: evtJson.BusyMembers,
  2350. totalAgentCount: evtJson.Members,
  2351. queueWaitCount: evtJson.Calls,
  2352. abadonedCalls: evtJson.Abandoned,
  2353. DisplayName: evtJson.DisplayName,
  2354. totalCalls: evtJson.TotalCalls,
  2355. members: [],
  2356. removed: false,
  2357. pbx: evtJson.PBX
  2358. };
  2359. for (var i in evtJson.QueueMember) {
  2360. member = evtJson.QueueMember[i];
  2361. queueItem.members[member] = member;
  2362. }
  2363. holly.phone.phone_queues[evtJson.Queue] = queueItem;
  2364. holly.phone.phone_publishEvent("EvtMonitorQueue", [queueItem, "needWaitCount"]);
  2365. }
  2366. } else if (evtJson.Event === "QueueMemberAdded") {
  2367. var queueItem = holly.phone._phone_queryQueueItem(evtJson);
  2368. if (queueItem) {
  2369. if (!queueItem.members[evtJson.Exten]) {
  2370. queueItem.members[evtJson.Exten] = evtJson.Exten; //change
  2371. queueItem.totalAgentCount++;
  2372. holly.phone._phone_updateQueueInfo();
  2373. }
  2374. }
  2375. } else if (evtJson.Event === "QueueMemberRemoved") {
  2376. var queueItem = holly.phone._phone_queryQueueItem(evtJson);
  2377. if (queueItem) {
  2378. if (queueItem.members[evtJson.Exten]) {
  2379. delete queueItem.members[evtJson.Exten];
  2380. queueItem.totalAgentCount--;
  2381. holly.phone.phone_publishEvent("EvtMonitorQueue", [queueItem, "noNeedWaitCount"]);
  2382. }
  2383. }
  2384. } else if (evtJson.Event === "Join") {
  2385. var queueItem = holly.phone._phone_queryQueueItem(evtJson);
  2386. if (queueItem) {
  2387. queueItem.queueWaitCount++;
  2388. holly.phone.phone_publishEvent("EvtMonitorQueue", [queueItem, "needWaitCount"]);
  2389. }
  2390. } else if (evtJson.Event === "Leave") {
  2391. var queueItem = holly.phone._phone_queryQueueItem(evtJson);
  2392. if (queueItem) {
  2393. queueItem.totalCalls++;
  2394. queueItem.queueWaitCount--;
  2395. if (queueItem.queueWaitCount < 0)
  2396. queueItem.queueWaitCount = 0;
  2397. holly.phone.phone_publishEvent("EvtMonitorQueue", [queueItem, "needWaitCount"]);
  2398. }
  2399. } else if (evtJson.Event === "QueueCallerAbandon") {
  2400. var queueItem = holly.phone._phone_queryQueueItem(evtJson);
  2401. if (queueItem) {
  2402. queueItem.abadonedCalls++;
  2403. holly.phone.phone_publishEvent("EvtMonitorQueue", [queueItem, "noNeedWaitCount"]);
  2404. }
  2405. }
  2406. },
  2407. dialoutInterface: function () {
  2408. var url = "http://127.0.0.1:7788/app?Action=Dialout&ActionID=Dialout" + Math.random() + "&Account=N000000007121&FromExten=8000&PBX=2.3.1.100&Exten=13488817474";
  2409. var ExternalData = {
  2410. callNum: "131313"
  2411. };
  2412. var json = encodeURI(ExternalData);
  2413. var onload = function (response) {
  2414. console.log(response);
  2415. };
  2416. var onerror = function (error) {
  2417. console.log(error);
  2418. };
  2419. holly.phone._phone_test_sendAction(json, onload, onerror, url);
  2420. },
  2421. _phone_test_sendAction: function (jsonData, onload, onerror, url) {
  2422. jsonData = $.toJSON("{'callNum' = '131313'}");
  2423. var timeout = 15000;
  2424. $.ajax({
  2425. type: "get",
  2426. url: url,
  2427. timeout: timeout,
  2428. cache: false,
  2429. data: {ExternalData: jsonData},
  2430. dataType: "jsonp",
  2431. jsonp: "callbackName",
  2432. success: onload,
  2433. error: onerror
  2434. });
  2435. }
  2436. }