From 84ded2e436c7341113146bdb7f3897b335a7a407 Mon Sep 17 00:00:00 2001 From: jaminh Date: Wed, 31 Jul 2024 16:42:53 -0500 Subject: [PATCH] Switch to using the From header for device ID (#20) It appears the From header is actually more meaningingful for calls coming from Asterisk, as the Contact header does not distinguish between which device initiated a call like the From header does. --- voip_utils/sip.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/voip_utils/sip.py b/voip_utils/sip.py index fde83ba..7d63134 100644 --- a/voip_utils/sip.py +++ b/voip_utils/sip.py @@ -86,12 +86,12 @@ def datagram_received(self, data: bytes, addr): caller_uri = None caller_name = None - # The Contact header should give us the URI used for sending SIP messages to the device - if headers.get("contact") is not None: - caller_uri, caller_name = self._parse_uri_header(headers.get("contact")) - # We can try using the From header as a fallback - elif headers.get("from") is not None: + # The From header should give us the URI used for sending SIP messages to the device + if headers.get("from") is not None: caller_uri, caller_name = self._parse_uri_header(headers.get("from")) + # We can try using the Contact header as a fallback + elif headers.get("contact") is not None: + caller_uri, caller_name = self._parse_uri_header(headers.get("contact")) # If all else fails try to generate a URI based on the IP and port from the address the message came from else: caller_uri = "sip:" + caller_ip + ":" + caller_sip_port