ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
ice_selected_pair.cpp File Reference

C++ implementation for retrieving selected ICE candidate pair. More...

Go to the source code of this file.

Macros

#define NETWORK_WEBRTC_ICE_SELECTED_PAIR_LOCAL_BUFFER_SIZE   512
#define NETWORK_WEBRTC_ICE_SELECTED_PAIR_REMOTE_BUFFER_SIZE   512

Functions

asciichat_error_t ice_get_selected_pair_impl (webrtc_peer_connection_t *pc, ice_candidate_t *local_candidate, ice_candidate_t *remote_candidate)
 Get selected ICE candidate pair (C++ implementation).

Detailed Description

C++ implementation for retrieving selected ICE candidate pair.

Uses libdatachannel's C++ API to access selected candidate pair information which is not exposed in the C API.

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

Definition in file ice_selected_pair.cpp.

Macro Definition Documentation

◆ NETWORK_WEBRTC_ICE_SELECTED_PAIR_LOCAL_BUFFER_SIZE

#define NETWORK_WEBRTC_ICE_SELECTED_PAIR_LOCAL_BUFFER_SIZE   512

Definition at line 14 of file ice_selected_pair.cpp.

Referenced by ice_get_selected_pair_impl().

◆ NETWORK_WEBRTC_ICE_SELECTED_PAIR_REMOTE_BUFFER_SIZE

#define NETWORK_WEBRTC_ICE_SELECTED_PAIR_REMOTE_BUFFER_SIZE   512

Definition at line 15 of file ice_selected_pair.cpp.

Referenced by ice_get_selected_pair_impl().

Function Documentation

◆ ice_get_selected_pair_impl()

asciichat_error_t ice_get_selected_pair_impl ( webrtc_peer_connection_t * pc,
ice_candidate_t * local_candidate,
ice_candidate_t * remote_candidate )

Get selected ICE candidate pair (C++ implementation).

This function uses libdatachannel's C++ API to retrieve the selected candidate pair, which is not available in the C API.

Definition at line 62 of file ice_selected_pair.cpp.

62 {
63 if (!pc) {
65 }
66
67 try {
68 // Get the libdatachannel peer connection ID using helper function
69 int rtc_id = webrtc_get_rtc_id(pc);
70 if (rtc_id < 0) {
72 }
73
74 // Query selected candidate pair from libdatachannel
75 // Note: This requires libdatachannel to have the selected candidate pair available
78
79 // Try to get the selected local candidate
80 if (rtcGetSelectedCandidatePair(rtc_id, local_buf, sizeof(local_buf), remote_buf, sizeof(remote_buf)) < 0) {
81 // No pair selected yet, or error accessing it
83 }
84
85 // Parse local candidate if requested
86 if (local_candidate) {
87 std::string local_str(local_buf);
88 asciichat_error_t err = parse_datachannel_candidate(local_str, local_candidate);
89 if (err != ASCIICHAT_OK) {
90 return err;
91 }
92 }
93
94 // Parse remote candidate if requested
95 if (remote_candidate) {
96 std::string remote_str(remote_buf);
97 asciichat_error_t err = parse_datachannel_candidate(remote_str, remote_candidate);
98 if (err != ASCIICHAT_OK) {
99 return err;
100 }
101 }
102
103 return ASCIICHAT_OK;
104
105 } catch (const std::exception &) {
106 return ERROR_NETWORK;
107 } catch (...) {
108 return ERROR_NETWORK;
109 }
110}
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ERROR_INVALID_STATE
@ ERROR_NETWORK
Definition error_codes.h:77
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
int webrtc_get_rtc_id(webrtc_peer_connection_t *pc)
Get the internal libdatachannel peer connection ID.
#define NETWORK_WEBRTC_ICE_SELECTED_PAIR_REMOTE_BUFFER_SIZE
#define NETWORK_WEBRTC_ICE_SELECTED_PAIR_LOCAL_BUFFER_SIZE

References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, ERROR_NETWORK, NETWORK_WEBRTC_ICE_SELECTED_PAIR_LOCAL_BUFFER_SIZE, NETWORK_WEBRTC_ICE_SELECTED_PAIR_REMOTE_BUFFER_SIZE, and webrtc_get_rtc_id().

Referenced by ice_get_selected_pair().