774056846 4 maanden geleden
bovenliggende
commit
d0277158af
1 gewijzigde bestanden met toevoegingen van 24 en 31 verwijderingen
  1. 24 31
      src/core/callcenter/esl/client.py

+ 24 - 31
src/core/callcenter/esl/client.py

@@ -323,19 +323,8 @@ class InboundClient:
             var,
             val
         ]
-        _con = None
-        try:
-            command = ' '.join(builder)
-            _con = ESL.ESLconnection(self.host, self.port, self.password)
-            if _con.connected():
-                print('debugger::set_var, command=%s'%command, flush=True)
-                e = _.bgapi(command, EMPTY)
-                print('debugger::set_var success, arg=%s, event=%s' % (command, e.serialize('json')), flush=True)
-        except:
-            traceback.print_exc()
-        finally:
-            if _con:
-                _con.disconnect()
+        command = ' '.join(builder)
+        self.bgapi(command, desc ="bridge_break")
 
     def multi_set_var(self, uuid, params):
         builder = [
@@ -386,19 +375,8 @@ class InboundClient:
             device_id,
             f"  -both 'set:hangup_after_bridge=false,set:park_after_bridge=true,set:{SIP_HEADER}{sipHeaderHoldMusic}={call_id},park:' inline "
         ]
-        _con = None
-        try:
-            arg = ''.join(builder)
-            _con = ESL.ESLconnection(self.host, self.port, self.password)
-            if _con.connected():
-                print('debugger::bridge_break, arg=%s'%arg, flush=True)
-                e = _con.api(TRANSFER, arg)
-                print('debugger::bridge_break success, arg=%s, event=%s' % (arg, e.serialize('json')), flush=True)
-        except:
-            traceback.print_exc()
-        finally:
-            if _con:
-                _con.disconnect()
+        arg = ''.join(builder)
+        self.api(TRANSFER, arg, "bridge_break")
 
     def play_file(self, call_id, device_id, file, sync):
         """放音"""
@@ -430,15 +408,30 @@ class InboundClient:
             " ",
             SMF_ALEG
         ]
+        arg = ''.join(builder)
+        self.api(UUID_BROADCAST, arg, "hold_play")
+
+    def api(self, command, arg=EMPTY, desc=""):
+        _con = None
+        try:
+            _con = ESL.ESLconnection(self.host, self.port, self.password)
+            if _con.connected():
+                e = _con.api(command, arg)
+                print('debugger::%s success, arg=%s, event=%s' % (desc, command + ' ' + arg, e.serialize('json')),
+                      flush=True)
+        except:
+            traceback.print_exc()
+        finally:
+            if _con:
+                _con.disconnect()
+
+    def bgapi(self, command, arg=EMPTY, desc=""):
         _con = None
         try:
-            arg = ''.join(builder)
-            print('debugger::hold_play, device_id=%s, play=%s' % (device_id, play), flush=True)
             _con = ESL.ESLconnection(self.host, self.port, self.password)
             if _con.connected():
-                print('debugger::hold_play, arg=%s' % arg, flush=True)
-                e = _con.api(UUID_BROADCAST, arg)
-                print('debugger::hold_play success, arg=%s, event=%s' % (arg, e.serialize('json')), flush=True)
+                e = _con.bgapi(command, arg)
+                print('debugger::%s success, arg=%s, event=%s' % (desc, command + ' '+arg, e.serialize('json')), flush=True)
         except:
             traceback.print_exc()
         finally: