Skip to content

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

is_connected: bool

Return True if the signaling WS is connected and subscribed.

session_id property

session_id: str | None

Return the current signaling session ID.

__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

connect async

connect() -> None

Connect to the signaling WebSocket and subscribe.

disconnect async

disconnect() -> None

Disconnect from the signaling WebSocket.

resubscribe async

resubscribe() -> None

Re-subscribe on the existing connection with a fresh token.

Sends a new subscribe message with a refreshed OAuth token on the current WebSocket connection, keeping the session alive without disconnecting. Mirrors WebsocketClient.resubscribe().

ensure_connected async

ensure_connected() -> None

Ensure the signaling WS is connected, reconnecting if needed.

send_offer async

send_offer(device_id: str, sdp: str, module_id: str | None = None) -> str

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_answer(sdp: str) -> None

Send an SDP answer (for incoming calls).

Uses the session state (session_id, tag_id, device_id, correlation_id) set by the most recent offer or ack.

Parameters:

Name Type Description Default
sdp str

The SDP answer string.

required

send_candidate async

send_candidate(candidate: str, sdp_m_line_index: int) -> None

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

send_terminate async

send_terminate() -> None

Terminate the current call session.

set_session_from_push

set_session_from_push(session_id: str, tag_id: str, correlation_id: str, device_id: str) -> None

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