SignalingClient¶
pybticino.signaling.SignalingClient ¶
Handles the WebRTC signaling WebSocket for BTicino devices.
This client connects to the Netatmo signaling endpoint, subscribes using the "app_security" app type, and provides methods to send/receive WebRTC signaling messages (offer, answer, ICE candidates, terminate).
is_connected
property
¶
Return True if the signaling WS is connected and subscribed.
__init__ ¶
__init__(auth_handler: AuthHandler, on_answer: OnAnswerCallback | None = None, on_candidate: OnCandidateCallback | None = None, on_event: OnEventCallback | None = None) -> None
Initialize the signaling client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth_handler
|
AuthHandler
|
An authenticated AuthHandler instance. |
required |
on_answer
|
OnAnswerCallback | None
|
Async callback invoked when an answer SDP is received. Called with (session_id, sdp). |
None
|
on_candidate
|
OnCandidateCallback | None
|
Async callback invoked when an ICE candidate is received. Called with (session_id, ice_candidate_dict). |
None
|
on_event
|
OnEventCallback | None
|
Async callback for other signaling events (rescind, terminate). Called with (session_id, event_type, full_data). |
None
|
resubscribe
async
¶
Re-subscribe on the existing connection with a fresh token and wait for ack.
Sends a new subscribe message with a refreshed OAuth token on the current WebSocket connection and waits for the server's subscribe ack (correlation_id 0) before returning, keeping existing sessions intact while avoiding a race where a subsequent offer/answer reaches the server before the token refresh is processed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Maximum seconds to wait for the subscribe ack. |
10.0
|
Raises:
| Type | Description |
|---|---|
PyBticinoException
|
If not connected, if the ack reports an error, if the connection closes, or if waiting times out. |
ensure_connected
async
¶
Ensure the signaling WS is connected, reconnecting if needed.
send_offer
async
¶
Send an SDP offer to initiate a call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_id
|
str
|
The bridge MAC address. |
required |
sdp
|
str
|
The SDP offer string from the local PeerConnection. |
required |
module_id
|
str | None
|
Optional module ID (external unit) to call. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The session_id assigned by the server. |
Raises:
| Type | Description |
|---|---|
PyBticinoException
|
If the offer fails or times out. |
send_answer
async
¶
Send an SDP answer (for incoming calls).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sdp
|
str
|
The SDP answer string. |
required |
session_id
|
str | None
|
The session to answer. Defaults to the most recent one. |
None
|
send_candidate
async
¶
Send an ICE candidate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidate
|
str
|
The ICE candidate string. |
required |
sdp_m_line_index
|
int
|
The m-line index for the candidate. |
required |
session_id
|
str | None
|
The session it belongs to. Defaults to the most recent one. |
None
|
send_terminate
async
¶
Terminate a call session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str | None
|
The session to terminate. Defaults to the most recent one. Other sessions, including the most recent, are left intact. |
None
|
set_session_from_push ¶
Set session state from a push WS offer (incoming call).
When a call comes in via the push WS, the session details are in the push event. This method sets them so send_answer/send_candidate can be used without first sending an offer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
From extra_params.session_id in the push event. |
required |
tag_id
|
str
|
From extra_params.tag_id in the push event. |
required |
correlation_id
|
str
|
From extra_params.correlation_id in the push event. |
required |
device_id
|
str
|
The bridge MAC (extra_params.device_id). |
required |