ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
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_twebrtc_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 350 of file src/client/webrtc.c.

350 {
351 ensure_mutex_initialized();
352 mutex_lock(&g_signaling_mutex);
353
354 if (g_webrtc_transport) {
355 log_debug("Cleaning up WebRTC data channel transport");
356 g_webrtc_transport = NULL;
357 }
358
359 mutex_unlock(&g_signaling_mutex);
360}
#define log_debug(...)
Log a DEBUG message.
#define mutex_lock(mutex)
Lock a mutex (with debug tracking in debug builds)
Definition mutex.h:140
#define mutex_unlock(mutex)
Unlock a mutex (with debug tracking in debug builds)
Definition mutex.h:175

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

250 {
251 ensure_mutex_initialized();
252
253 webrtc_signaling_callbacks_t callbacks = {
254 .send_sdp = client_send_sdp, .send_ice = client_send_ice, .user_data = NULL};
255
256 return callbacks;
257}
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 329 of file src/client/webrtc.c.

329 {
330 ensure_mutex_initialized();
331 mutex_lock(&g_signaling_mutex);
332
333 acip_transport_t *transport = g_webrtc_transport;
334
335 mutex_unlock(&g_signaling_mutex);
336
337 return transport;
338}
Transport instance structure.
Definition transport.h:169

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

259 {
260 ensure_mutex_initialized();
261 mutex_lock(&g_signaling_mutex);
262
263 g_acds_transport = transport;
264
265 if (transport) {
266 log_debug("ACDS transport set for WebRTC signaling");
267 } else {
268 log_debug("ACDS transport cleared for WebRTC signaling");
269 }
270
271 mutex_unlock(&g_signaling_mutex);
272}

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

274 {
275 if (!session_id || !participant_id) {
276 log_error("Invalid session context parameters");
277 return;
278 }
279
280 ensure_mutex_initialized();
281 mutex_lock(&g_signaling_mutex);
282
283 memcpy(g_session_context.session_id, session_id, 16);
284 memcpy(g_session_context.participant_id, participant_id, 16);
285 g_session_context.is_set = true;
286
287 log_info("Session context set for WebRTC signaling (session=%.8s..., participant=%.8s...)", (const char *)session_id,
288 (const char *)participant_id);
289
290 mutex_unlock(&g_signaling_mutex);
291}
#define log_error(...)
Log an ERROR message.
#define log_info(...)
Log an INFO message.
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 304 of file src/client/webrtc.c.

304 {
305 ensure_mutex_initialized();
306 mutex_lock(&g_signaling_mutex);
307
308 g_webrtc_transport = transport;
309
310 if (transport) {
311 log_debug("WebRTC data channel transport set");
312 } else {
313 log_debug("WebRTC data channel transport cleared");
314 }
315
316 mutex_unlock(&g_signaling_mutex);
317}

References log_debug, mutex_lock, and mutex_unlock.

Variable Documentation

◆ is_set

bool is_set

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

Referenced by options_config_validate().

◆ participant_id

uint8_t participant_id[16]

◆ session_id