|
@@ -1,30 +1,30 @@
|
|
|
#!/usr/bin/env python3
|
|
|
# encoding:utf-8
|
|
|
|
|
|
-import json
|
|
|
import random
|
|
|
-
|
|
|
+import logging
|
|
|
import ESL
|
|
|
import time
|
|
|
import mmh3
|
|
|
import threading
|
|
|
import traceback
|
|
|
-import socketserver
|
|
|
import concurrent.futures
|
|
|
-from http.server import BaseHTTPRequestHandler
|
|
|
-from http.server import HTTPServer
|
|
|
-import src.core.callcenter.utils.call_cache_util as CacheUtil
|
|
|
-from src.core.callcenter.constant.constant import AT, CO, SK, saasId, EMPTY
|
|
|
-from src.core.callcenter.constant.esl_constant import BRIDGE_VARIABLES, BRIDGE, HANGUP, NORMAL_CLEARING, SIP_HEADER, SPACE, SPLIT, SOFIA, \
|
|
|
+from src.core import singleton
|
|
|
+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, \
|
|
|
ORIGINATE, PARK, SET, EAVESDROP, SMF_ALEG, EXECUTE, PLAYBACK, PAUSE, TRANSFER, UUID_TRANSFER, UUID_BROADCAST, UUID_BREAK, UUID_HOLD, \
|
|
|
UUID_RECORD, UUID_SETVAR, UUID_GETVAR
|
|
|
-import src.core.callcenter.utils.esl_event_util as EslEventUtil
|
|
|
-import src.core.callcenter.handler as event_handler
|
|
|
-from src.core.callcenter.constant.sip_header_constant import sipHeaderHoldMusic
|
|
|
+import src.core.callcenter.esl.utils.esl_event_util as EslEventUtil
|
|
|
+import src.core.callcenter.esl.handler as event_handler
|
|
|
+from src.core.callcenter.esl.constant.sip_header_constant import sipHeaderHoldMusic
|
|
|
from src.core.callcenter.enumeration import CallCauseEnum
|
|
|
-from src.core.callcenter.handler.default_esl_event_handler import DefaultEslEventHandler
|
|
|
+from src.core.callcenter.esl.handler.default_esl_event_handler import DefaultEslEventHandler
|
|
|
+
|
|
|
|
|
|
+logger = logging.getLogger(__name__)
|
|
|
|
|
|
+
|
|
|
+@singleton
|
|
|
class InboundClient:
|
|
|
|
|
|
def __init__(self):
|
|
@@ -36,8 +36,9 @@ class InboundClient:
|
|
|
self.host, self.port, self.password = 'localhost', '8021', '4918257983818884358'
|
|
|
self.executors = {x: concurrent.futures.ThreadPoolExecutor(max_workers=1) for x in range(self.thread_num)}
|
|
|
|
|
|
- gw = CacheUtil.getRouteGetway(saasId)
|
|
|
- self.make_call(gw, '63366692', '13241676588', 'C111111111', 'D1111111')
|
|
|
+ threading.Thread(target=self.start, args=()).start()
|
|
|
+ # gw = CacheUtil.getRouteGetway(saasId)
|
|
|
+ # self.make_call(gw, '63366692', '13241676588', 'C111111111', 'D1111111')
|
|
|
|
|
|
def scan_esl_event_handlers(self):
|
|
|
import inspect
|
|
@@ -60,6 +61,7 @@ class InboundClient:
|
|
|
return handlers
|
|
|
|
|
|
def start(self):
|
|
|
+ print('inbound.start')
|
|
|
self.con = ESL.ESLconnection(self.host, self.port, self.password)
|
|
|
if self.con.connected():
|
|
|
print('inbound esl connected ... ')
|
|
@@ -71,6 +73,7 @@ class InboundClient:
|
|
|
# print(e.serialize('json'))
|
|
|
event_name = e.getHeader("Event-Name")
|
|
|
if event_name == "SERVER_DISCONNECTED":
|
|
|
+ print('come in SERVER_DISCONNECTED case')
|
|
|
self.con.disconnect()
|
|
|
time.sleep(3)
|
|
|
self.start()
|
|
@@ -165,7 +168,7 @@ class InboundClient:
|
|
|
builder.append(f"{SOFIA}{SK}{route_gateway.profile}{SK}{called}{PARK}")
|
|
|
cmd = "".join(builder)
|
|
|
print(cmd)
|
|
|
- # self.con.bgapi(ORIGINATE, cmd)
|
|
|
+ self.con.bgapi(ORIGINATE, cmd)
|
|
|
|
|
|
def call_timeout(self, call_id, device_id, timeout):
|
|
|
"""呼叫超时主动挂机"""
|
|
@@ -203,7 +206,7 @@ class InboundClient:
|
|
|
msg.addHeader("call-command", EXECUTE)
|
|
|
msg.addHeader("execute-app-name", HANGUP)
|
|
|
msg.addHeader("execute-app-arg", NORMAL_CLEARING)
|
|
|
- # log.info("hangupCall挂机 hangup media:{} call: {}, device: {}, ctiCauseEnum:{}", media,callId, deviceId, ctiCauseEnum);
|
|
|
+ logger.info("hangup_call挂机 hangup call: {}, device: {}, ctiCauseEnum:{}", call_id, device_id, case_enum)
|
|
|
self.send_args(device_id, SET, EslEventUtil.SIP_H_P_WDH_HANGUP_CAUSE + "=" + case_enum.description)
|
|
|
self.con.sendEvent(msg)
|
|
|
|
|
@@ -276,7 +279,7 @@ class InboundClient:
|
|
|
|
|
|
def record(self, uuid, action, path, limit):
|
|
|
builder = [
|
|
|
- UUID_TRANSFER,
|
|
|
+ UUID_RECORD,
|
|
|
uuid,
|
|
|
action,
|
|
|
path,
|