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

Client-side WebRTC signaling callback implementations. More...

Go to the source code of this file.

Functions

webrtc_signaling_callbacks_t webrtc_get_signaling_callbacks (void)
 Get signaling callbacks for WebRTC peer manager.
 
void webrtc_set_acds_transport (acip_transport_t *transport)
 Set the ACDS transport for signaling callbacks.
 
void webrtc_set_session_context (const uint8_t session_id[16], const uint8_t participant_id[16])
 Set session and participant IDs for signaling.
 
void webrtc_set_transport (acip_transport_t *transport)
 Set the WebRTC data channel transport.
 
acip_transport_t * webrtc_get_transport (void)
 Get the current WebRTC data channel transport.
 
void webrtc_cleanup_transport (void)
 Cleanup and release the WebRTC data channel transport.
 

Detailed Description

Client-side WebRTC signaling callback implementations.

Provides callback functions for sending SDP/ICE via ACDS when the peer manager generates local descriptions and candidates. These callbacks bridge the peer manager to the ACDS TCP connection.

INTEGRATION POINTS:

  • webrtc_peer_manager: Calls these callbacks when generating local SDP/ICE
  • ACDS connection: These callbacks send ACIP packets via ACDS TCP transport
  • client/main.c: Initializes peer manager with these callbacks

LIFECYCLE:

  1. Client joins ACDS session (gets session_id, participant_id)
  2. Client initializes peer manager with these callbacks
  3. Peer manager generates local SDP/ICE
  4. Callbacks send SDP/ICE to ACDS server for relay to remote peers
  5. ACDS relays messages to target participants
Author
Zachary Fogg me@zf.nosp@m.o.gg
Date
January 2026

Definition in file client/webrtc.h.

Function Documentation

◆ webrtc_cleanup_transport()

void webrtc_cleanup_transport ( void  )

Cleanup and release the WebRTC data channel transport.

Clears the WebRTC transport. Called on disconnect or fallback.

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

Closes and releases the WebRTC transport. Called when disconnecting or falling back to a different transport type.

Note
This is a convenience function that sets transport to NULL
Actual transport cleanup (closing sockets, freeing peer manager) should be done by the caller before calling this

Definition at line 365 of file src/client/webrtc.c.

365 {
366 ensure_mutex_initialized();
367 mutex_lock(&g_signaling_mutex);
368
369 if (g_webrtc_transport) {
370 log_debug("Cleaning up WebRTC data channel transport");
371 g_webrtc_transport = NULL;
372 }
373
374 mutex_unlock(&g_signaling_mutex);
375}

◆ webrtc_get_signaling_callbacks()

webrtc_signaling_callbacks_t webrtc_get_signaling_callbacks ( void  )

Get signaling callbacks for WebRTC peer manager.

Returns a structure containing callback functions that send SDP/ICE via the ACDS TCP connection. The callbacks are stateless - they use the global ACDS transport to send signaling messages.

Returns
Signaling callbacks structure (valid until program exit)
Note
The returned structure points to static callbacks, safe to use for the lifetime of the peer manager.
Callbacks will fail if ACDS connection is not active.

Definition at line 265 of file src/client/webrtc.c.

265 {
266 ensure_mutex_initialized();
267
268 webrtc_signaling_callbacks_t callbacks = {
269 .send_sdp = client_send_sdp, .send_ice = client_send_ice, .user_data = NULL};
270
271 return callbacks;
272}

◆ webrtc_get_transport()

acip_transport_t * webrtc_get_transport ( void  )

Get the current WebRTC data channel transport.

Retrieves the active WebRTC transport for peer-to-peer communication.

Returns
Current WebRTC transport pointer (NULL if not set)
Note
Thread-safe - uses internal mutex protection
Pointer is valid only until webrtc_set_transport(NULL) is called

Retrieves the active WebRTC transport for peer-to-peer communication.

Returns
Current WebRTC transport pointer (NULL if not set)
Note
Caller must not free the returned pointer
Pointer is valid only until webrtc_set_transport(NULL) is called

Definition at line 344 of file src/client/webrtc.c.

344 {
345 ensure_mutex_initialized();
346 mutex_lock(&g_signaling_mutex);
347
348 acip_transport_t *transport = g_webrtc_transport;
349
350 mutex_unlock(&g_signaling_mutex);
351
352 return transport;
353}

◆ webrtc_set_acds_transport()

void webrtc_set_acds_transport ( acip_transport_t *  transport)

Set the ACDS transport for signaling callbacks.

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

Parameters
transportACDS TCP transport (NULL to clear)
Note
This is called automatically when connecting to ACDS.
Callbacks will fail with ERROR_INVALID_STATE if transport is NULL.

Definition at line 274 of file src/client/webrtc.c.

274 {
275 ensure_mutex_initialized();
276 mutex_lock(&g_signaling_mutex);
277
278 g_acds_transport = transport;
279
280 if (transport) {
281 log_debug("ACDS transport set for WebRTC signaling");
282 } else {
283 log_debug("ACDS transport cleared for WebRTC signaling");
284 }
285
286 mutex_unlock(&g_signaling_mutex);
287}

◆ webrtc_set_session_context()

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

Set session and participant IDs for signaling.

Configures the session context used when sending SDP/ICE messages. Must be called after successful ACDS session join.

Parameters
session_idSession UUID (16 bytes, copied)
participant_idLocal participant UUID (16 bytes, copied)
Note
This is called automatically when joining ACDS session.
Callbacks will fail with ERROR_INVALID_STATE if IDs are not set.

Definition at line 289 of file src/client/webrtc.c.

289 {
290 if (!session_id || !participant_id) {
291 log_error("Invalid session context parameters");
292 return;
293 }
294
295 ensure_mutex_initialized();
296 mutex_lock(&g_signaling_mutex);
297
298 memcpy(g_session_context.session_id, session_id, 16);
299 memcpy(g_session_context.participant_id, participant_id, 16);
300 g_session_context.is_set = true;
301
302 log_info("Session context set for WebRTC signaling (session=%.8s..., participant=%.8s...)", (const char *)session_id,
303 (const char *)participant_id);
304
305 mutex_unlock(&g_signaling_mutex);
306}
uint8_t session_id[16]
uint8_t participant_id[16]

References participant_id, and session_id.

◆ webrtc_set_transport()

void webrtc_set_transport ( acip_transport_t *  transport)

Set the WebRTC data channel transport.

Stores the active WebRTC transport for peer-to-peer communication. Separate from ACDS signaling transport.

Parameters
transportWebRTC transport (NULL to clear)
Note
Thread-safe - uses internal mutex protection

Stores the active WebRTC transport that will be used for peer-to-peer communication. This is different from the ACDS signaling transport - it's the actual data channel.

Parameters
transportWebRTC transport (NULL to clear)
Note
Called when WebRTC connection is established or when falling back to TCP
If NULL is passed, the transport is cleared (e.g., on disconnect)

Definition at line 319 of file src/client/webrtc.c.

319 {
320 ensure_mutex_initialized();
321 mutex_lock(&g_signaling_mutex);
322
323 g_webrtc_transport = transport;
324
325 if (transport) {
326 log_debug("WebRTC data channel transport set");
327 } else {
328 log_debug("WebRTC data channel transport cleared");
329 }
330
331 mutex_unlock(&g_signaling_mutex);
332}