From cc1a84a26b28f5305fff79e06200c4c8604c0c11 Mon Sep 17 00:00:00 2001 From: Thijs Raymakers Date: Thu, 29 May 2025 00:03:49 +0200 Subject: [PATCH] Revert "Print exception instead of just supressing it" This reverts commit 4daccf60ee85e3b6d2d8ad0513854b8f868192dd. --- main.py | 58 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/main.py b/main.py index 59a254b..5c5ff6f 100644 --- a/main.py +++ b/main.py @@ -21,6 +21,10 @@ VISITOR_COUNT_FILE = "visitor_count" LIB = None def call(): + sip_server = str(getenv("SIP_SERVER")) + sip_username = str(getenv("SIP_USERNAME")) + sip_password = str(getenv("SIP_PASSWORD")) + # Initialize lib LIB = pj.Endpoint() LIB.libCreate() @@ -34,24 +38,6 @@ def call(): LIB.libStart() - while True: - try: - id = QUEUE.get(block = True) - - sip_server = str(getenv("SIP_SERVER")) - sip_username = str(getenv("SIP_USERNAME")) - sip_password = str(getenv("SIP_PASSWORD")) - - # Spawn audio on phone - call_phone(sip_server, sip_username, sip_password) - - # authorize guest after a certain amount of time - unifi.authorize_guest(id, 1) - except Exception as e: - print(f"Exception: {e}") - sleep(5) - -def call_phone(hostname, username, password): class MyAccount(pj.Account): def __init__(self): pj.Account.__init__(self) @@ -59,6 +45,31 @@ def call_phone(hostname, username, password): def onRegState(self, prm): print("Registration state:", prm.code) + # Account config + acc_cfg = pj.AccountConfig() + acc_cfg.idUri = f"sip:{sip_username}@{sip_server}" + acc_cfg.regConfig.registrarUri = f"sip:{sip_server}" + cred = pj.AuthCredInfo("digest", "*", sip_username, 0, sip_password) + acc_cfg.sipConfig.authCreds.append(cred) + + acc = MyAccount() + acc.create(acc_cfg) + + + while True: + try: + id = QUEUE.get(block = True) + + # Spawn audio on phone + call_phone(sip_server, acc) + + # authorize guest after a certain amount of time + unifi.authorize_guest(id, 1) + except: + sleep(5) + +def call_phone(hostname, acc): + # Make call class MyCall(pj.Call): def __init__(self, acc, dest_uri): pj.Call.__init__(self, acc) @@ -68,17 +79,6 @@ def call_phone(hostname, username, password): ci = self.getInfo() print("Call state:", ci.stateText) - # Account config - acc_cfg = pj.AccountConfig() - acc_cfg.idUri = f"sip:{username}@{hostname}" - acc_cfg.regConfig.registrarUri = f"sip:{hostname}" - cred = pj.AuthCredInfo("digest", "*", username, 0, password) - acc_cfg.sipConfig.authCreds.append(cred) - - acc = MyAccount() - acc.create(acc_cfg) - - # Make call call = MyCall(acc, f"sip:3002@{hostname}") # Keep the program running for the duration of the ringtone