Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / services / xdr / members.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xfb68=['name','internal','CreateMemberReport','getUserByName','split','request','catch','error','[%s][members][writeDB]','startsWith','devicestatechange','debug','[%s][members][devicestatechange]','device','state','BUSY','now','agent','NOT_INUSE','duration','exitAt','agentcomplete','isNil','info','[%s][members][agentcomplete]\x20interface:%s\x20queue:%s','queue','assign','[%s][members][cdr]','data2','data3','destination','[%s][members][cdr]\x20type:%s\x20source:%s\x20destination:%s','data1','source','lodash','util','./utils','Local/_attended@transfer','Queue:','format','[%s][members][writeDB]\x20interface:%s\x20channel:%s\x20data2:%s\x20agent:%s\x20type:%s','uniqueid','interface','channel','membername','type','getUserByInterface','then'];(function(_0x2de012,_0x5276dd){var _0x5b6423=function(_0x50136d){while(--_0x50136d){_0x2de012['push'](_0x2de012['shift']());}};_0x5b6423(++_0x5276dd);}(_0xfb68,0x1d2));var _0x8fb6=function(_0x3f5f4a,_0x56220b){_0x3f5f4a=_0x3f5f4a-0x0;var _0x2e8114=_0xfb68[_0x3f5f4a];return _0x2e8114;};'use strict';var _=require(_0x8fb6('0x0'));var util=require(_0x8fb6('0x1'));var utils=require(_0x8fb6('0x2'));var members={};var exclude=[_0x8fb6('0x3'),_0x8fb6('0x4')];function writeDB(_0x5b1aea){utils['info'](util[_0x8fb6('0x5')](_0x8fb6('0x6'),_0x5b1aea[_0x8fb6('0x7')],_0x5b1aea[_0x8fb6('0x8')],_0x5b1aea[_0x8fb6('0x9')],_0x5b1aea['data2'],_0x5b1aea[_0x8fb6('0xa')],_0x5b1aea[_0x8fb6('0xb')]));if(_0x5b1aea[_0x8fb6('0x8')]){utils[_0x8fb6('0xc')](_0x5b1aea[_0x8fb6('0x8')])[_0x8fb6('0xd')](function(_0x368988){if(_0x368988){_0x5b1aea['membername']=_0x368988[_0x8fb6('0xe')];_0x5b1aea['internal']=_0x368988[_0x8fb6('0xf')];utils['request'](_0x8fb6('0x10'),_0x5b1aea);}else{utils[_0x8fb6('0x11')](_0x5b1aea['interface'][_0x8fb6('0x12')]('/')[0x1])[_0x8fb6('0xd')](function(_0x28d16b){if(_0x28d16b){_0x5b1aea[_0x8fb6('0xa')]=_0x28d16b[_0x8fb6('0xe')];_0x5b1aea['internal']=_0x28d16b[_0x8fb6('0xf')];utils[_0x8fb6('0x13')]('CreateMemberReport',_0x5b1aea);}});}})[_0x8fb6('0x14')](function(_0x287935){utils[_0x8fb6('0x15')](util[_0x8fb6('0x5')](_0x8fb6('0x16'),_0x5b1aea[_0x8fb6('0x7')]),_0x287935);});}delete members[_0x5b1aea[_0x8fb6('0x8')]];}function startsWith(_0x11543c,_0x10db95){return _['some'](_0x11543c,function(_0x551c16){return _[_0x8fb6('0x17')](_0x10db95,_0x551c16);});}exports[_0x8fb6('0x18')]=function(_0x259deb){try{utils[_0x8fb6('0x19')](util[_0x8fb6('0x5')](_0x8fb6('0x1a'),members[_0x259deb[_0x8fb6('0x1b')]]?members[_0x259deb[_0x8fb6('0x1b')]][_0x8fb6('0x7')]:_0x259deb[_0x8fb6('0x1b')]),_0x259deb);utils['info'](util[_0x8fb6('0x5')]('[%s][members][devicestatechange]\x20state:%s\x20interface:%s',members[_0x259deb['device']]?members[_0x259deb[_0x8fb6('0x1b')]][_0x8fb6('0x7')]:_0x259deb['device'],_0x259deb['state'],_0x259deb[_0x8fb6('0x1b')]));switch(_0x259deb[_0x8fb6('0x1c')]){case'INUSE':case _0x8fb6('0x1d'):if(!startsWith(exclude,_0x259deb['device'])){members[_0x259deb['device']]={'channel':'voice','interface':_0x259deb[_0x8fb6('0x1b')],'type':'TALKING','enterAt':utils[_0x8fb6('0x1e')](),'role':_0x8fb6('0x1f')};}break;case _0x8fb6('0x20'):if(!_['isNil'](members[_0x259deb[_0x8fb6('0x1b')]])){members[_0x259deb[_0x8fb6('0x1b')]]['exitAt']=utils[_0x8fb6('0x1e')]();members[_0x259deb['device']][_0x8fb6('0x21')]=utils['diffTime'](members[_0x259deb[_0x8fb6('0x1b')]][_0x8fb6('0x22')],members[_0x259deb[_0x8fb6('0x1b')]]['enterAt']);if(members[_0x259deb['device']]['uniqueid']){writeDB(members[_0x259deb[_0x8fb6('0x1b')]]);}}break;default:break;}}catch(_0x443cce){utils[_0x8fb6('0x15')](util[_0x8fb6('0x5')]('[%s][members][devicestatechange]',members[_0x259deb[_0x8fb6('0x1b')]]?members[_0x259deb[_0x8fb6('0x1b')]][_0x8fb6('0x7')]:_0x259deb[_0x8fb6('0x1b')]),_0x443cce);}};exports[_0x8fb6('0x23')]=function(_0x4438c3){try{if(!_[_0x8fb6('0x24')](members[_0x4438c3['interface']])){utils[_0x8fb6('0x19')](util[_0x8fb6('0x5')]('[%s][members][agentcomplete]',_0x4438c3['uniqueid']),_0x4438c3);utils[_0x8fb6('0x25')](util['format'](_0x8fb6('0x26'),_0x4438c3[_0x8fb6('0x7')],_0x4438c3[_0x8fb6('0x8')],_0x4438c3[_0x8fb6('0x27')]));members[_0x4438c3['interface']]=_[_0x8fb6('0x28')](members[_0x4438c3[_0x8fb6('0x8')]],{'data4':_0x4438c3[_0x8fb6('0x27')],'uniqueid':_0x4438c3[_0x8fb6('0x7')]});}}catch(_0xcdecf0){utils[_0x8fb6('0x15')](util[_0x8fb6('0x5')]('[%s][members][agentcomplete]',_0x4438c3[_0x8fb6('0x7')]),_0xcdecf0);}};exports['cdr']=function(_0x44236a){try{utils[_0x8fb6('0x19')](util['format'](_0x8fb6('0x29'),_0x44236a[_0x8fb6('0x7')]),_0x44236a);if(_0x44236a[_0x8fb6('0x9')]){var _0x35898f=_0x44236a[_0x8fb6('0x9')][_0x8fb6('0x12')]('-')[0x0];if(!_['isNil'](members[_0x35898f])){members[_0x35898f]=_[_0x8fb6('0x28')](members[_0x35898f],{'data1':members[_0x35898f]['data1']||_0x44236a[_0x8fb6('0xb')],'data2':members[_0x35898f][_0x8fb6('0x2a')]||_0x44236a['source'],'data3':members[_0x35898f][_0x8fb6('0x2b')]||_0x44236a[_0x8fb6('0x2c')],'uniqueid':members[_0x35898f]['uniqueid']||_0x44236a[_0x8fb6('0x7')]});utils['info'](util['format'](_0x8fb6('0x2d'),_0x44236a[_0x8fb6('0x7')],members[_0x35898f][_0x8fb6('0x2e')],members[_0x35898f]['data2'],members[_0x35898f]['data3']));if(members[_0x35898f][_0x8fb6('0x22')]){writeDB(members[_0x35898f]);}}}if(_0x44236a['destinationchannel']){var _0x5d9a95=_0x44236a['destinationchannel']['split']('-')[0x0];if(!_[_0x8fb6('0x24')](members[_0x5d9a95])){members[_0x5d9a95]=_['assign'](members[_0x5d9a95],{'data1':members[_0x5d9a95][_0x8fb6('0x2e')]||_0x44236a[_0x8fb6('0xb')],'data2':members[_0x5d9a95][_0x8fb6('0x2a')]||_0x44236a[_0x8fb6('0x2f')],'data3':members[_0x5d9a95][_0x8fb6('0x2b')]||_0x44236a['destination'],'uniqueid':members[_0x5d9a95][_0x8fb6('0x7')]||_0x44236a['uniqueid']});utils[_0x8fb6('0x25')](util[_0x8fb6('0x5')](_0x8fb6('0x2d'),_0x44236a[_0x8fb6('0x7')],members[_0x5d9a95][_0x8fb6('0x2e')],members[_0x5d9a95][_0x8fb6('0x2a')],members[_0x5d9a95][_0x8fb6('0x2b')]));if(members[_0x5d9a95]['exitAt']){writeDB(members[_0x5d9a95]);}}}}catch(_0x306f7c){utils[_0x8fb6('0x15')](util[_0x8fb6('0x5')](_0x8fb6('0x29'),_0x44236a[_0x8fb6('0x7')]),_0x306f7c);}};