ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
webrtc.c File Reference

WebRTC P2P signaling for discovery mode failover. More...

Go to the source code of this file.

Functions

webrtc_signaling_callbacks_t discovery_webrtc_get_direct_signaling_callbacks (acip_transport_t *tcp_transport, const uint8_t session_id[16], const uint8_t participant_id[16])
 Create signaling callbacks for direct peer-to-peer connection during failover.
 
void discovery_webrtc_set_tcp_transport (acip_transport_t *transport)
 Set the TCP transport for direct peer-to-peer signaling.
 
void discovery_webrtc_set_session_context (const uint8_t session_id[16], const uint8_t participant_id[16])
 Set session and participant IDs for direct signaling.
 
void discovery_webrtc_cleanup_transport (void)
 Cleanup and release the direct peer-to-peer transport.
 

Detailed Description

WebRTC P2P signaling for discovery mode failover.

Implements direct peer-to-peer SDP/ICE exchange for discovery mode migration. Unlike client mode (which uses ACDS relay), failover uses direct TCP connections to send WebRTC signaling messages.

Definition in file src/discovery/webrtc.c.

Function Documentation

◆ discovery_webrtc_cleanup_transport()

void discovery_webrtc_cleanup_transport ( void  )

Cleanup and release the direct peer-to-peer transport.

Clears the TCP transport used for direct signaling. Called on migration completion or when the P2P connection is torn down.

Note
Actual transport cleanup (closing connections, freeing resources) should be done by caller before calling this.
Thread-safe.

Definition at line 291 of file src/discovery/webrtc.c.

291 {
292 ensure_mutex_initialized();
293 mutex_lock(&g_webrtc_mutex);
294
295 g_tcp_transport = NULL;
296 g_session_context.is_set = false;
297
298 mutex_unlock(&g_webrtc_mutex);
299}

◆ discovery_webrtc_get_direct_signaling_callbacks()

webrtc_signaling_callbacks_t discovery_webrtc_get_direct_signaling_callbacks ( acip_transport_t *  tcp_transport,
const uint8_t  session_id[16],
const uint8_t  participant_id[16] 
)

Create signaling callbacks for direct peer-to-peer connection during failover.

Returns callbacks that send SDP/ICE directly over TCP to the peer (not through ACDS). Used when participants reconnect to a new host after migration.

Parameters
tcp_transportTCP transport connected to the new host
session_idSession UUID (16 bytes, copied)
participant_idLocal participant UUID (16 bytes, copied)
Returns
Signaling callbacks for use with peer manager
Note
The returned structure points to static callbacks and is valid for program lifetime.
TCP transport must be connected and valid when callbacks are invoked.
Set tcp_transport to NULL to disable the callbacks.

Definition at line 244 of file src/discovery/webrtc.c.

246 {
247 ensure_mutex_initialized();
248 mutex_lock(&g_webrtc_mutex);
249
250 g_tcp_transport = tcp_transport;
251
252 if (session_id && participant_id) {
253 memcpy(g_session_context.session_id, session_id, 16);
254 memcpy(g_session_context.participant_id, participant_id, 16);
255 g_session_context.is_set = true;
256 }
257
258 mutex_unlock(&g_webrtc_mutex);
259
260 webrtc_signaling_callbacks_t callbacks = {
261 .send_sdp = discovery_send_sdp,
262 .send_ice = discovery_send_ice,
263 .user_data = NULL, // Unused - we use global state
264 };
265
266 return callbacks;
267}
uint8_t session_id[16]
uint8_t participant_id[16]

References participant_id, and session_id.

◆ discovery_webrtc_set_session_context()

void discovery_webrtc_set_session_context ( const uint8_t  session_id[16],
const uint8_t  participant_id[16] 
)

Set session and participant IDs for direct signaling.

Configures the session context used when sending SDP/ICE messages directly. Must be called before peer manager generates any local descriptions.

Parameters
session_idSession UUID (16 bytes, copied)
participant_idLocal participant UUID (16 bytes, copied)
Note
Callbacks will fail with ERROR_INVALID_STATE if IDs are not set.

Definition at line 276 of file src/discovery/webrtc.c.

276 {
277 ensure_mutex_initialized();
278 mutex_lock(&g_webrtc_mutex);
279
280 if (session_id && participant_id) {
281 memcpy(g_session_context.session_id, session_id, 16);
282 memcpy(g_session_context.participant_id, participant_id, 16);
283 g_session_context.is_set = true;
284 } else {
285 g_session_context.is_set = false;
286 }
287
288 mutex_unlock(&g_webrtc_mutex);
289}

References participant_id, and session_id.

◆ discovery_webrtc_set_tcp_transport()

void discovery_webrtc_set_tcp_transport ( acip_transport_t *  transport)

Set the TCP transport for direct peer-to-peer signaling.

Configures the transport that will be used to send SDP/ICE messages directly to the peer (bypassing ACDS). Must be called before peer manager generates any local descriptions.

Parameters
transportTCP transport to new host (NULL to disable)
Note
This is separate from the ACDS transport used in client mode.
Callbacks will fail with ERROR_INVALID_STATE if transport is NULL.

Definition at line 269 of file src/discovery/webrtc.c.

269 {
270 ensure_mutex_initialized();
271 mutex_lock(&g_webrtc_mutex);
272 g_tcp_transport = transport;
273 mutex_unlock(&g_webrtc_mutex);
274}

Variable Documentation

◆ is_set

bool is_set

Definition at line 49 of file src/discovery/webrtc.c.

◆ participant_id

uint8_t participant_id[16]

◆ session_id

uint8_t session_id[16]