ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
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[SESSION_ID_SIZE], const uint8_t participant_id[SESSION_ID_SIZE])
 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 356 of file src/client/webrtc.c.

356 {
357 ensure_mutex_initialized();
358 mutex_lock(&g_signaling_mutex);
359
360 if (g_webrtc_transport) {
361 log_debug("Cleaning up WebRTC data channel transport");
362 g_webrtc_transport = NULL;
363 }
364
365 mutex_unlock(&g_signaling_mutex);
366}
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:589

References log_debug.

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

258 {
259 ensure_mutex_initialized();
260
261 webrtc_signaling_callbacks_t callbacks = {.send_sdp = client_send_sdp, .send_ice = client_send_ice, .user_data = NULL};
262
263 return callbacks;
264}
Hooks that deliver local SDP offers/answers and ICE candidates to ACDS.

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

335 {
336 ensure_mutex_initialized();
337 mutex_lock(&g_signaling_mutex);
338
339 acip_transport_t *transport = g_webrtc_transport;
340
341 mutex_unlock(&g_signaling_mutex);
342
343 return transport;
344}
struct acip_transport acip_transport_t
Forward declaration of ACIP transport.
Definition host.h:508

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

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

References log_debug.

◆ webrtc_set_session_context()

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

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

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

References log_error, log_info, participant_id, session_id, and SESSION_ID_SIZE.

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

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

References log_debug.

Variable Documentation

◆ is_set

bool is_set

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

◆ participant_id

◆ session_id