Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/anam/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,24 @@ class AgentAudioInputPayload:
sequence_number: int


def _reorder_ice_server_urls(ice_servers: list[dict[str, Any]]) -> list[dict[str, Any]]:
"""Reorder URLs to prioritize TURNS (TURN over TLS) as aiortc only uses the first TURN URI."""

def _turns_first(u):
return 0 if str(u).lower().startswith("turns:") else 1

return [
{
**s,
"urls": sorted(
[s["urls"]] if isinstance(s.get("urls"), str) else s.get("urls", []),
key=_turns_first,
),
}
for s in ice_servers
]


@dataclass
class SessionInfo:
"""Information about an active streaming session.
Expand All @@ -257,5 +275,5 @@ def from_api_response(cls, data: dict[str, Any]) -> "SessionInfo":
signalling_endpoint=data["signallingEndpoint"],
heartbeat_interval_seconds=client_config.get("heartbeatIntervalSeconds", 5),
max_reconnection_attempts=client_config.get("maxWsReconnectionAttempts", 5),
ice_servers=client_config.get("iceServers", []),
ice_servers=_reorder_ice_server_urls(client_config.get("iceServers") or []),
)
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading