17#include <ascii-chat/network/webrtc/ice.h>
18#include <ascii-chat/network/webrtc/webrtc.h>
22#undef ERROR_INVALID_STATE
23#undef ERROR_INVALID_PARAM
25#include <ascii-chat/common/error_codes.h>
33static asciichat_error_t parse_datachannel_candidate(
const std::string &candidate_str, ice_candidate_t *candidate) {
35 return ERROR_INVALID_PARAM;
39 std::string line = candidate_str;
40 const char *prefix =
"candidate:";
41 size_t prefix_len = strlen(prefix);
42 if (line.compare(0, prefix_len, prefix) == 0) {
43 line = line.substr(prefix_len);
59 ice_candidate_t *remote_candidate) {
61 return ERROR_INVALID_PARAM;
68 return ERROR_INVALID_PARAM;
77 if (rtcGetSelectedCandidatePair(rtc_id, local_buf,
sizeof(local_buf), remote_buf,
sizeof(remote_buf)) < 0) {
79 return ERROR_INVALID_STATE;
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) {
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) {
102 }
catch (
const std::exception &e) {
103 return ERROR_NETWORK;
105 return ERROR_NETWORK;
asciichat_error_t ice_parse_candidate(const char *line, ice_candidate_t *candidate)
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)
int webrtc_get_rtc_id(webrtc_peer_connection_t *pc)
Get the internal libdatachannel peer connection ID.