ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
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.

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.

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 58 of file ice_selected_pair.cpp.

59 {
60 if (!pc) {
61 return ERROR_INVALID_PARAM;
62 }
63
64 try {
65 // Get the libdatachannel peer connection ID using helper function
66 int rtc_id = webrtc_get_rtc_id(pc);
67 if (rtc_id < 0) {
68 return ERROR_INVALID_PARAM;
69 }
70
71 // Query selected candidate pair from libdatachannel
72 // Note: This requires libdatachannel to have the selected candidate pair available
73 char local_buf[512];
74 char remote_buf[512];
75
76 // Try to get the selected local candidate
77 if (rtcGetSelectedCandidatePair(rtc_id, local_buf, sizeof(local_buf), remote_buf, sizeof(remote_buf)) < 0) {
78 // No pair selected yet, or error accessing it
79 return ERROR_INVALID_STATE;
80 }
81
82 // Parse local candidate if requested
83 if (local_candidate) {
84 std::string local_str(local_buf);
85 asciichat_error_t err = parse_datachannel_candidate(local_str, local_candidate);
86 if (err != ASCIICHAT_OK) {
87 return err;
88 }
89 }
90
91 // Parse remote candidate if requested
92 if (remote_candidate) {
93 std::string remote_str(remote_buf);
94 asciichat_error_t err = parse_datachannel_candidate(remote_str, remote_candidate);
95 if (err != ASCIICHAT_OK) {
96 return err;
97 }
98 }
99
100 return ASCIICHAT_OK;
101
102 } catch (const std::exception &e) {
103 return ERROR_NETWORK;
104 } catch (...) {
105 return ERROR_NETWORK;
106 }
107}
int webrtc_get_rtc_id(webrtc_peer_connection_t *pc)
Get the internal libdatachannel peer connection ID.

References webrtc_get_rtc_id().

Referenced by ice_get_selected_pair().