ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
webrtc.c 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.

Implements the send_sdp and send_ice callbacks that the peer manager uses to transmit local SDP/ICE to remote peers via ACDS.

PACKET CONSTRUCTION:

Both callbacks construct ACIP packets following the wire format:

  • Fixed header (acip_webrtc_sdp_t or acip_webrtc_ice_t)
  • Variable payload (SDP string or ICE candidate+mid)

THREAD SAFETY:

Callbacks use mutex protection for accessing shared state (ACDS transport, session context). Safe to call from peer manager threads.

Author
Zachary Fogg me@zf.nosp@m.o.gg
Date
January 2026

Definition in file src/client/webrtc.c.

Function Documentation

◆ webrtc_cleanup_transport()

void webrtc_cleanup_transport ( void  )

Cleanup and release the WebRTC data channel transport.

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 360 of file src/client/webrtc.c.

360 {
361 ensure_mutex_initialized();
362 mutex_lock(&g_signaling_mutex);
363
364 if (g_webrtc_transport) {
365 log_debug("Cleaning up WebRTC data channel transport");
366 g_webrtc_transport = NULL;
367 }
368
369 mutex_unlock(&g_signaling_mutex);
370}
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:548
#define mutex_lock(mutex)
Lock a mutex (with debug tracking in debug builds)
#define mutex_unlock(mutex)
Unlock a mutex (with debug tracking in debug builds)

References log_debug, mutex_lock, and mutex_unlock.

◆ 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 260 of file src/client/webrtc.c.

260 {
261 ensure_mutex_initialized();
262
263 webrtc_signaling_callbacks_t callbacks = {
264 .send_sdp = client_send_sdp, .send_ice = client_send_ice, .user_data = NULL};
265
266 return callbacks;
267}
Signaling callbacks for sending SDP/ICE.
webrtc_send_sdp_callback_t send_sdp
Send SDP via ACDS.

References webrtc_signaling_callbacks_t::send_sdp.

◆ 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
Caller must not free the returned pointer
Pointer is valid only until webrtc_set_transport(NULL) is called

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

339 {
340 ensure_mutex_initialized();
341 mutex_lock(&g_signaling_mutex);
342
343 acip_transport_t *transport = g_webrtc_transport;
344
345 mutex_unlock(&g_signaling_mutex);
346
347 return transport;
348}
Transport instance structure.
Definition transport.h:214

References mutex_lock, and mutex_unlock.

◆ 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 269 of file src/client/webrtc.c.

269 {
270 ensure_mutex_initialized();
271 mutex_lock(&g_signaling_mutex);
272
273 g_acds_transport = transport;
274
275 if (transport) {
276 log_debug("ACDS transport set for WebRTC signaling");
277 } else {
278 log_debug("ACDS transport cleared for WebRTC signaling");
279 }
280
281 mutex_unlock(&g_signaling_mutex);
282}

References log_debug, mutex_lock, and mutex_unlock.

◆ 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 284 of file src/client/webrtc.c.

284 {
285 if (!session_id || !participant_id) {
286 log_error("Invalid session context parameters");
287 return;
288 }
289
290 ensure_mutex_initialized();
291 mutex_lock(&g_signaling_mutex);
292
293 memcpy(g_session_context.session_id, session_id, 16);
294 memcpy(g_session_context.participant_id, participant_id, 16);
295 g_session_context.is_set = true;
296
297 log_info("Session context set for WebRTC signaling (session=%.8s..., participant=%.8s...)", (const char *)session_id,
298 (const char *)participant_id);
299
300 mutex_unlock(&g_signaling_mutex);
301}
#define log_error(...)
Log an ERROR message.
Definition log/log.h:587
#define log_info(...)
Log an INFO message.
Definition log/log.h:561
uint8_t session_id[16]
uint8_t participant_id[16]

References log_error, log_info, mutex_lock, mutex_unlock, 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 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 314 of file src/client/webrtc.c.

314 {
315 ensure_mutex_initialized();
316 mutex_lock(&g_signaling_mutex);
317
318 g_webrtc_transport = transport;
319
320 if (transport) {
321 log_debug("WebRTC data channel transport set");
322 } else {
323 log_debug("WebRTC data channel transport cleared");
324 }
325
326 mutex_unlock(&g_signaling_mutex);
327}

References log_debug, mutex_lock, and mutex_unlock.

Variable Documentation

◆ is_set

bool is_set

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

Referenced by options_config_validate().

◆ participant_id

◆ session_id