余尚辉 vor 7 Monaten
Ursprung
Commit
ae246bcdcf
3 geänderte Dateien mit 38 neuen und 7 gelöschten Zeilen
  1. BIN
      .DS_Store
  2. 1 1
      README.md
  3. 37 6
      voip/gateway.py

BIN
.DS_Store


+ 1 - 1
README.md

@@ -7,7 +7,7 @@
 [![Coverity-Scan](https://scan.coverity.com/projects/905/badge.svg)](https://scan.coverity.com/projects/pjsip)
 [![Coverity-Scan](https://scan.coverity.com/projects/905/badge.svg)](https://scan.coverity.com/projects/pjsip)
 [![CodeQL](https://github.com/pjsip/pjproject/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/pjsip/pjproject/actions/workflows/codeql-analysis.yml)
 [![CodeQL](https://github.com/pjsip/pjproject/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/pjsip/pjproject/actions/workflows/codeql-analysis.yml)
 [![docs.pjsip.org](https://readthedocs.org/projects/pjsip/badge/?version=latest)](https://docs.pjsip.org/en/latest/)
 [![docs.pjsip.org](https://readthedocs.org/projects/pjsip/badge/?version=latest)](https://docs.pjsip.org/en/latest/)
-ceshi
+
 
 
 # PJSIP
 # PJSIP
 
 

+ 37 - 6
voip/gateway.py

@@ -17,12 +17,30 @@ class InboundClient:
 
 
     def start(self):
     def start(self):
         if self.con.connected():
         if self.con.connected():
+            print('inbound esl connected ... ')
             self.con.events('plain', 'all')
             self.con.events('plain', 'all')
             while not self.is_stopping:
             while not self.is_stopping:
                 e = self.con.recvEvent()
                 e = self.con.recvEvent()
                 if e:
                 if e:
-                    print(e)
+                    print(json.loads(e.serialize('json')))
                     # print(e.serialize('json'))
                     # print(e.serialize('json'))
+                event_name = e.getHeader("Event-Name")
+                if event_name == "CHANNEL_PARK":
+                    # 获取通话的 UUID
+                    call_uuid = e.getHeader("Unique-ID")
+                    print(f"Incoming call with UUID: {call_uuid}")
+
+                    self.con.execute("bridge", "user/1001", call_uuid)
+
+                    destination = "user/1001"
+                    # msg = ESL.ESLevent("sendmsg", call_uuid)
+                    # msg.addHeader("call-command", "execute")
+                    # msg.addHeader("execute-app-name", "bridge")
+                    # msg.addHeader("execute-app-arg", destination)
+                    # msg.addHeader("execute-app-arg", destination)
+                    # # 发送消息以执行 bridge 操作
+                    # self.con.sendEvent(msg)
+                    print(f"Call {call_uuid} is bridged to {destination}")
 
 
     def stop(self):
     def stop(self):
         self.is_stopping = True
         self.is_stopping = True
@@ -33,12 +51,25 @@ class OutboundClient:
     @staticmethod
     @staticmethod
     def ack(esl, con):
     def ack(esl, con):
         info = con.getInfo()
         info = con.getInfo()
-        print(info.serialize('json'))
+        print(json.loads(info.serialize('json')))
         event_name = info.getHeader("Event-Name")
         event_name = info.getHeader("Event-Name")
         uuid = info.getHeader("unique-id")
         uuid = info.getHeader("unique-id")
         print(uuid, event_name)
         print(uuid, event_name)
-        con.execute("answer", "", uuid)
-        con.execute("playback", "/Users/davidliu/sip/pjproject/voip/test111.wav", uuid)
+
+        # 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("park", "", uuid)
+        con.execute("bridge", "user/1001", uuid)
+
+        # con.execute("answer", "", uuid)
+        # con.execute("playback", "/Users/davidliu/sip/pjproject/voip/test111.wav", uuid)
 
 
         con.disconnect()
         con.disconnect()
 
 
@@ -70,8 +101,8 @@ class OutboundClient:
 
 
 def main():
 def main():
     on = InboundClient()
     on = InboundClient()
-    out = OutboundClient()
-    threading.Thread(target=out.start, args=()).start()
+    # out = OutboundClient()
+    # threading.Thread(target=out.start, args=()).start()
     threading.Thread(target=on.start, args=()).start()
     threading.Thread(target=on.start, args=()).start()
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':