Skip to content
Merged
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
39 changes: 39 additions & 0 deletions intriniorealtime/_websocket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import threading
import time
from typing import Optional


def close_websocket_app(app) -> None:
"""Best-effort close using websocket-client's public API only."""
if app is None:
return
try:
app.close()
except Exception:
pass


def should_abort_handshake(
handshake_event: threading.Event,
stop_flag: Optional[threading.Event],
generation: int,
current_generation,
deadline: float,
) -> bool:
while True:
if handshake_event.is_set():
return False
if stop_flag is not None and stop_flag.is_set():
return False
current = current_generation() if callable(current_generation) else current_generation
if generation != current:
return False
remaining = deadline - time.monotonic()
if remaining <= 0:
return True
handshake_event.wait(min(remaining, 0.1))


def _redact_api_key(message, api_key):
text = str(message)
return text.replace(api_key, "<redacted>") if api_key else text
Loading