43f8f16b6ba4f2cea17d5a2fc4fe3a651887c713
[motion2.git] / server / services / agi / events.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 _0x12f9=['subscribe','agi','emit','E_AGI_SERVER_ERROR','projectUpdate','error','EventEmitter','./error','../../config/environment','redis'];(function(_0x12810c,_0x3bd5db){var _0x352e66=function(_0x3f0a74){while(--_0x3f0a74){_0x12810c['push'](_0x12810c['shift']());}};_0x352e66(++_0x3bd5db);}(_0x12f9,0x114));var _0x912f=function(_0x29fddd,_0x5c5a80){_0x29fddd=_0x29fddd-0x0;var _0x462bbd=_0x12f9[_0x29fddd];return _0x462bbd;};'use strict';var _=require('lodash');var EventEmitter=require('events')[_0x912f('0x0')];var Redis=require('ioredis');var AGIError=require(_0x912f('0x1'));var config=require(_0x912f('0x2'));config[_0x912f('0x3')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var eventEmitter=new EventEmitter();var sub=new Redis(config[_0x912f('0x3')]);sub[_0x912f('0x4')](_0x912f('0x5'),function(_0x55da9a){if(_0x55da9a)return eventEmitter[_0x912f('0x6')]('error',new AGIError(_0x912f('0x7'),_0x55da9a));});sub['on']('message',function(_0x3a09de,_0x3ca6fb){if(_0x3a09de!=='agi')return;try{var _0xaa1537=JSON['parse'](_0x3ca6fb);eventEmitter[_0x912f('0x6')](_0x912f('0x8'),_0xaa1537);}catch(_0x11e993){eventEmitter[_0x912f('0x6')](_0x912f('0x9'),new AGIError(_0x912f('0x7'),_0x11e993));}});module['exports']={'EventEmitter':eventEmitter};