|
@@ -3,12 +3,15 @@
|
|
|
|
|
|
import json
|
|
import json
|
|
import random
|
|
import random
|
|
|
|
+import socketserver
|
|
|
|
+
|
|
import ESL
|
|
import ESL
|
|
import time
|
|
import time
|
|
import mmh3
|
|
import mmh3
|
|
import threading
|
|
import threading
|
|
import traceback
|
|
import traceback
|
|
import concurrent.futures
|
|
import concurrent.futures
|
|
|
|
+import src.core.callcenter.cache as Cache
|
|
from src.core.callcenter.constant import SK, EMPTY
|
|
from src.core.callcenter.constant import SK, EMPTY
|
|
from src.core.callcenter.esl.constant.esl_constant import BRIDGE_VARIABLES, BRIDGE, HANGUP, NORMAL_CLEARING, SIP_HEADER, SPACE, SPLIT, SOFIA, \
|
|
from src.core.callcenter.esl.constant.esl_constant import BRIDGE_VARIABLES, BRIDGE, HANGUP, NORMAL_CLEARING, SIP_HEADER, SPACE, SPLIT, SOFIA, \
|
|
ORIGINATE, PARK, SET, EAVESDROP, SMF_ALEG, EXECUTE, PLAYBACK, PAUSE, TRANSFER, UUID_TRANSFER, UUID_BROADCAST, UUID_BREAK, UUID_HOLD, \
|
|
ORIGINATE, PARK, SET, EAVESDROP, SMF_ALEG, EXECUTE, PLAYBACK, PAUSE, TRANSFER, UUID_TRANSFER, UUID_BROADCAST, UUID_BREAK, UUID_HOLD, \
|
|
@@ -18,18 +21,17 @@ import src.core.callcenter.esl.handler as event_handler
|
|
from src.core.callcenter.esl.constant.sip_header_constant import sipHeaderHoldMusic
|
|
from src.core.callcenter.esl.constant.sip_header_constant import sipHeaderHoldMusic
|
|
from src.core.callcenter.enumeration import CallCause
|
|
from src.core.callcenter.enumeration import CallCause
|
|
from src.core.callcenter.esl.handler.default_esl_event_handler import DefaultEslEventHandler
|
|
from src.core.callcenter.esl.handler.default_esl_event_handler import DefaultEslEventHandler
|
|
-from src.core.voip.bot import BotAgent
|
|
|
|
from src.core.voip.constant import *
|
|
from src.core.voip.constant import *
|
|
|
|
|
|
|
|
|
|
class InboundClient:
|
|
class InboundClient:
|
|
|
|
|
|
- def __init__(self, logger):
|
|
|
|
|
|
+ def __init__(self, agent, logger):
|
|
self.con = None
|
|
self.con = None
|
|
self.thread_num = 32
|
|
self.thread_num = 32
|
|
self.is_stopping = False
|
|
self.is_stopping = False
|
|
self.logger = logger
|
|
self.logger = logger
|
|
- self.bot_agent = BotAgent(logger)
|
|
|
|
|
|
+ self.bot_agent = agent
|
|
self.handler_table = self.scan_esl_event_handlers()
|
|
self.handler_table = self.scan_esl_event_handlers()
|
|
self.default_event_handler = DefaultEslEventHandler(self, self.bot_agent, self.logger)
|
|
self.default_event_handler = DefaultEslEventHandler(self, self.bot_agent, self.logger)
|
|
self.host, self.port, self.password = SERVE_HOST, '8021', '4918257983818884358'
|
|
self.host, self.port, self.password = SERVE_HOST, '8021', '4918257983818884358'
|
|
@@ -371,55 +373,63 @@ class InboundClient:
|
|
self.is_stopping = True
|
|
self.is_stopping = True
|
|
|
|
|
|
|
|
|
|
-# class OutboundClient:
|
|
|
|
-#
|
|
|
|
-# class ESLRequestHandler(socketserver.BaseRequestHandler):
|
|
|
|
-#
|
|
|
|
-# def setup(self):
|
|
|
|
-# try:
|
|
|
|
-# print(self.client_address, 'connected!')
|
|
|
|
-# fd = self.request.fileno()
|
|
|
|
-# print('0000', fd)
|
|
|
|
-# con = ESL.ESLconnection(fd)
|
|
|
|
-# print('Connected: ', con.connected())
|
|
|
|
-# if con.connected():
|
|
|
|
-# info = con.getInfo()
|
|
|
|
-# print(json.loads(info.serialize('json')))
|
|
|
|
-# event_name = info.getHeader("Event-Name")
|
|
|
|
-# uuid = info.getHeader("unique-id")
|
|
|
|
-# print(uuid, event_name)
|
|
|
|
-#
|
|
|
|
-# # destination = "user/1001"
|
|
|
|
-# # msg = ESL.ESLevent("sendmsg", uuid)
|
|
|
|
-# # msg.addHeader("call-command", "execute")
|
|
|
|
-# # msg.addHeader("execute-app-name", "bridge")
|
|
|
|
-# # msg.addHeader("execute-app-arg", destination)
|
|
|
|
-# # # 发送消息以执行 bridge 操作
|
|
|
|
-# # con.sendEvent(msg)
|
|
|
|
-# # print(f"Call {uuid} is bridged to {destination}")
|
|
|
|
-#
|
|
|
|
-# con.execute("answer", "", uuid)
|
|
|
|
-#
|
|
|
|
-# # con.execute("transfer", "1001 XML default", uuid)
|
|
|
|
-# con.execute("bridge", "user/1001", uuid)
|
|
|
|
-# # try:
|
|
|
|
-# # con.disconnect()
|
|
|
|
-# # except:
|
|
|
|
-# # print('come in ')
|
|
|
|
-# # traceback.print_exc()
|
|
|
|
-# else:
|
|
|
|
-# print("Failed to connect to FreeSWITCH")
|
|
|
|
-# except:
|
|
|
|
-# print('come in 1')
|
|
|
|
-# traceback.print_exc()
|
|
|
|
-#
|
|
|
|
-# def ack(self, con):
|
|
|
|
-# OutboundClient.ack(self, con)
|
|
|
|
-#
|
|
|
|
-# def start(self, HOST= '0.0.0.0', PORT=8084):
|
|
|
|
-# # HOST, PORT = "0.0.0.0", 8084
|
|
|
|
-#
|
|
|
|
-# # 创建一个 TCP 服务器
|
|
|
|
-# with socketserver.TCPServer((HOST, PORT), self.ESLRequestHandler) as server:
|
|
|
|
-# print(f"ESL server listening on {HOST}:{PORT}")
|
|
|
|
-# server.serve_forever()
|
|
|
|
|
|
+class OutboundClient:
|
|
|
|
+
|
|
|
|
+ def __init__(self, agent, logger):
|
|
|
|
+ self.bot_agent = agent
|
|
|
|
+ self.logger = logger
|
|
|
|
+ threading.Thread(target=self.start, args=()).start()
|
|
|
|
+
|
|
|
|
+ class ESLRequestHandler(socketserver.BaseRequestHandler):
|
|
|
|
+ def __init__(self, outbound):
|
|
|
|
+ self.bot_agent = outbound.bot_agent
|
|
|
|
+ self.logger = outbound.logger
|
|
|
|
+
|
|
|
|
+ def setup(self):
|
|
|
|
+ try:
|
|
|
|
+ print(self.client_address, 'connected!')
|
|
|
|
+ fd = self.request.fileno()
|
|
|
|
+ con = ESL.ESLconnection(fd)
|
|
|
|
+ print('Connected: ', con.connected())
|
|
|
|
+ if con.connected():
|
|
|
|
+ info = con.getInfo()
|
|
|
|
+
|
|
|
|
+ # print(json.loads(info.serialize('json')))
|
|
|
|
+ event_name = info.getHeader("Event-Name")
|
|
|
|
+ device_id = info.getHeader("unique-id")
|
|
|
|
+ kwargs = json.loads(info.serialize('json'))
|
|
|
|
+ destination = self.bot_agent.register(**kwargs)
|
|
|
|
+ self.logger.info("device_id=%s, destination=%s", device_id, destination)
|
|
|
|
+
|
|
|
|
+ Cache.add_device_user_part(device_id, destination)
|
|
|
|
+ con.execute("bridge", f"user/{destination}", device_id)
|
|
|
|
+
|
|
|
|
+ # destination = "user/1001"
|
|
|
|
+ # msg = ESL.ESLevent("sendmsg", uuid)
|
|
|
|
+ # msg.addHeader("call-command", "execute")
|
|
|
|
+ # msg.addHeader("execute-app-name", "bridge")
|
|
|
|
+ # msg.addHeader("execute-app-arg", destination)
|
|
|
|
+ # # 发送消息以执行 bridge 操作
|
|
|
|
+ # con.sendEvent(msg)
|
|
|
|
+ # print(f"Call {uuid} is bridged to {destination}")
|
|
|
|
+
|
|
|
|
+ # con.execute("answer", "", uuid)
|
|
|
|
+
|
|
|
|
+ # con.execute("transfer", "1001 XML default", uuid)
|
|
|
|
+ # try:
|
|
|
|
+ # con.disconnect()
|
|
|
|
+ # except:
|
|
|
|
+ # print('come in ')
|
|
|
|
+ # traceback.print_exc()
|
|
|
|
+ else:
|
|
|
|
+ print("Failed to connect to FreeSWITCH")
|
|
|
|
+ except:
|
|
|
|
+ traceback.print_exc()
|
|
|
|
+
|
|
|
|
+ def start(self, HOST= '0.0.0.0', PORT=8084):
|
|
|
|
+ # HOST, PORT = "0.0.0.0", 8084
|
|
|
|
+
|
|
|
|
+ # 创建一个 TCP 服务器
|
|
|
|
+ with socketserver.TCPServer((HOST, PORT), self.ESLRequestHandler(self)) as server:
|
|
|
|
+ print(f"ESL server listening on {HOST}:{PORT}")
|
|
|
|
+ server.serve_forever()
|