Built motion from commit ded33658aad58fc8de845a8299a9db59a88cc353. Version 3.0.0...
[motion-next.git] / server / app.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 const a822_0x3924=['SIGUSR2','./config/schedule/transcribe','DB\x20Sync\x20Error:\x0a','None','./mysqldb','delete','name','debounce','Starting\x20DB\x20seed...','apps','Online\x20apps:','error','Database','kill','start','sync','App\x20shut\x20down','isTest','db-query','Development\x20Mode','process\x20or\x20namespace\x20not\x20found','./config/license','Cannot\x20kill\x20','online','./config/pm2','RPC\x20Error','message','environment','./config/environment','once','./config/schedule/chat','log','Offline\x20apps:','\x0a*****\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20Caught\x20','map','sequelize','xCally\x20ready!','./globals','close','stack','Seed\x20DB\x20ok','\x20signal!\x20\x20\x20\x20\x20\x20\x20\x20*****\x0a','info','status','debug','test','SIGINT','xCally\x20Starting...\x20','./config/schedule','isProduction','Error\x20on\x20server\x20exit','filter','Server\x20failed\x20to\x20start\x20due\x20to\x20error:','ONCE\x20SIGINT','join','exit','lodash','./rpc','./config/config.service','\x20deleted','./rediscache'];(function(_0xaa4e44,_0x392486){const _0x16ace8=function(_0x23ff60){while(--_0x23ff60){_0xaa4e44['push'](_0xaa4e44['shift']());}};_0x16ace8(++_0x392486);}(a822_0x3924,0x14b));const a822_0x16ac=function(_0xaa4e44,_0x392486){_0xaa4e44=_0xaa4e44-0x0;let _0x16ace8=a822_0x3924[_0xaa4e44];return _0x16ace8;};const _0x43024f=a822_0x16ac;'use strict';require(_0x43024f('0xb'));const mysqldb=require(_0x43024f('0x27')),{RPC}=require(_0x43024f('0x1f')),{getConfigService}=require(_0x43024f('0x20')),config=require(_0x43024f('0x2')),logger=require('./config/logger'),pm2=require(_0x43024f('0x3b')),pm2Config=require('./config/pm2/config'),schedule=require(_0x43024f('0x16')),chat=require(_0x43024f('0x4')),transcribe=require(_0x43024f('0x24')),{default:seedDB}=require('./config/seedDB'),{default:checkLicense}=require(_0x43024f('0x38')),{getRedis}=require(_0x43024f('0x22')),cs=getConfigService(),_=require(_0x43024f('0x1e')),appLogger=logger('app'),queryLogger=logger(_0x43024f('0x35'));function logDatabase(_0x23ff60){const _0x2b7a6f=_0x43024f;try{queryLogger[_0x2b7a6f('0x10')](_0x2b7a6f('0x2f'),_0x23ff60);}catch(_0x208773){console['error'](_0x208773);}}function onRPCError(_0x205a13){const _0x5b5ae3=_0x43024f;appLogger[_0x5b5ae3('0x2e')](_0x5b5ae3('0x3c'),_0x205a13);}const rpc=new RPC(onRPCError),onServerExitHandler=_[_0x43024f('0x2a')](async function onServerExit(_0x4390d1){const _0x1d1378=_0x43024f;console[_0x1d1378('0x5')](_0x1d1378('0x7')+_0x4390d1+_0x1d1378('0xf'));try{await rpc[_0x1d1378('0xc')](),appLogger['debug']('Rpc\x20closed');for(const _0x37194f of pm2Config[_0x1d1378('0x2c')]){try{await pm2[_0x1d1378('0x28')](_0x37194f[_0x1d1378('0x29')]),appLogger[_0x1d1378('0x12')](_0x37194f[_0x1d1378('0x29')]+_0x1d1378('0x21'));}catch(_0x339881){_0x339881[_0x1d1378('0x0')]!==_0x1d1378('0x37')&&(console[_0x1d1378('0x2e')](_0x1d1378('0x39')+_0x37194f['name'],_0x339881),appLogger[_0x1d1378('0x2e')](_0x1d1378('0x39')+_0x37194f['name']+':\x20'+_0x339881[_0x1d1378('0x0')]+'\x0a'+_0x339881[_0x1d1378('0xd')]));}}console[_0x1d1378('0x5')]('\x0a*****\x20\x20\x20\x20\x20\x20\x20Stopped\x20and\x20removed\x20all\x20subprocesses\x20\x20\x20\x20\x20\x20*****\x0a\x0a\x0a'),getRedis()['disconnect'](),appLogger[_0x1d1378('0x12')]('Redis\x20disconnected'),appLogger[_0x1d1378('0x12')](_0x1d1378('0x33'));}catch(_0x44e3b0){console[_0x1d1378('0x2e')](_0x1d1378('0x18'),_0x44e3b0),appLogger['error']('Error\x20on\x20server\x20exit:\x20'+_0x44e3b0['message']+'\x0a'+_0x44e3b0[_0x1d1378('0xd')]);}},0x7d0,{'leading':!![]});!(cs[_0x43024f('0x17')]||cs[_0x43024f('0x34')])?(process[_0x43024f('0x3')](_0x43024f('0x23'),async function(){const _0x5e1a43=_0x43024f;await onServerExitHandler(_0x5e1a43('0x23')),process[_0x5e1a43('0x30')](process['pid'],_0x5e1a43('0x23'));}),process['on'](_0x43024f('0x14'),async function(){const _0x556e55=_0x43024f;console[_0x556e55('0x5')]('ON\x20SIGINT'),await onServerExitHandler(_0x556e55('0x14')),process[_0x556e55('0x1d')](0x0);})):process[_0x43024f('0x3')](_0x43024f('0x14'),async function(){const _0x2fb298=_0x43024f;console[_0x2fb298('0x5')](_0x2fb298('0x1b')),await onServerExitHandler('SIGINT'),process['exit'](0x0);});async function main(){const _0x36e8cd=_0x43024f;try{console[_0x36e8cd('0x5')](_0x36e8cd('0x15')+(cs[_0x36e8cd('0x17')]?'':_0x36e8cd('0x36')));try{await mysqldb['db'][_0x36e8cd('0x9')][_0x36e8cd('0x32')]({'logging':cs[_0x36e8cd('0x17')]||cs[_0x36e8cd('0x1')]===_0x36e8cd('0x13')?![]:logDatabase});}catch(_0x2fcb63){console['warn'](_0x36e8cd('0x25'),_0x2fcb63),queryLogger['error']('DB\x20Sync\x20Error:\x20'+_0x2fcb63[_0x36e8cd('0x0')]+',\x20'+_0x2fcb63[_0x36e8cd('0xd')]);}config['seedDB']===!![]&&(console[_0x36e8cd('0x5')](_0x36e8cd('0x2b')),await seedDB(),console[_0x36e8cd('0x5')](_0x36e8cd('0xe')));await checkLicense();const _0x13cf1a=await rpc['listen']();appLogger['info'](_0x13cf1a),await chat[_0x36e8cd('0x31')](),await schedule[_0x36e8cd('0x31')]();const _0x1107a8=await transcribe[_0x36e8cd('0x31')]();appLogger[_0x36e8cd('0x10')](_0x1107a8);const _0x3cfdbf=await pm2[_0x36e8cd('0x31')](pm2Config);appLogger[_0x36e8cd('0x10')](_0x36e8cd('0x2d'),_[_0x36e8cd('0x8')](_[_0x36e8cd('0x19')](_0x3cfdbf,{'status':_0x36e8cd('0x3a')}),_0x36e8cd('0x29'))[_0x36e8cd('0x1c')]()),appLogger[_0x36e8cd('0x10')](_0x36e8cd('0x6'),_[_0x36e8cd('0x8')](_[_0x36e8cd('0x19')](_0x3cfdbf,function(_0x22d3aa){const _0x2e7541=_0x36e8cd;return _0x22d3aa[_0x2e7541('0x11')]!==_0x2e7541('0x3a');}),_0x36e8cd('0x29'))[_0x36e8cd('0x1c')]()||_0x36e8cd('0x26')),console[_0x36e8cd('0x5')](_0x36e8cd('0xa'));}catch(_0x12d053){console[_0x36e8cd('0x2e')](_0x12d053),appLogger[_0x36e8cd('0x2e')](_0x36e8cd('0x1a'),_0x12d053);throw _0x12d053;}}main();