diff --git a/main.py b/main.py index bbc7281..8e1307d 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,23 +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: - sleep(5) - -def call_phone(hostname, username, password): class MyAccount(pj.Account): def __init__(self): pj.Account.__init__(self) @@ -69,14 +56,28 @@ def call_phone(hostname, username, password): # 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.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 call = MyCall(acc, f"sip:3002@{hostname}")