-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include URI for device identification #18
Conversation
When receiving a call parse the SIP URI from the Contact or From header to use for identifying a device. Using the URI will make it possible to distinguish between multiple endpoints calling through a centralized server (such as Asterisk) which would otherwise appear to come from the same IP address. Keeping track of the Contact header URI will also make it possible to send outbound calls to the device using the correct URI.
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): | ||
caller_uri, caller_name = self._parse_uri_header(headers.get('from')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great opportunity to leverage the walrus
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): | |
caller_uri, caller_name = self._parse_uri_header(headers.get('from')) | |
if contact_header := headers.get('contact'): | |
caller_uri, caller_name = self._parse_uri_header(contact_header) | |
# We can try using the From header as a fallback | |
elif from_header := headers.get('from'): | |
caller_uri, caller_name = self._parse_uri_header(from_header) |
@@ -203,6 +229,26 @@ def answer( | |||
server_rtp_port, | |||
) | |||
|
|||
def _parse_uri_header( | |||
header: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All methods shuold start with self
. The test passed but the code wasn't working. I fixed it in 4d08d66
I'll admit python is a second language for me, so thank you for the feedback. With this change merged we might want to reopen https://github.com/home-assistant/core/pull/111050/files for the associated changes in HA, although it needs to be updated for the change to using the entire URI rather than parsing the individual parts like I was doing originally. |
When receiving a call parse the SIP URI from the Contact or From header to use for identifying a device. Using the URI will make it possible to distinguish between multiple endpoints calling through a centralized server (such as Asterisk) which would otherwise appear to come from the same IP address. Keeping track of the Contact header URI will also make it possible to send outbound calls to the device using the correct URI.