From 415e2384ff0cb3c98ef942a2a99085f9427b18a4 Mon Sep 17 00:00:00 2001 From: Stephan Rotolante Date: Wed, 11 Sep 2024 11:06:24 -0400 Subject: [PATCH] Implement peer_connection_add_ice_candidate Resolves #63 --- src/ice.c | 8 +++++++- src/peer_connection.c | 10 ++++++++++ src/peer_connection.h | 7 +++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ice.c b/src/ice.c index 77dfcde..a54ea57 100644 --- a/src/ice.c +++ b/src/ice.c @@ -79,10 +79,16 @@ void ice_candidate_to_description(IceCandidate* candidate, char* description, in } int ice_candidate_from_description(IceCandidate* candidate, char* description, char* end) { - char* split_start = description + strlen("a=candidate:"); + char* split_start = description; char* split_end = NULL; int index = 0; char buf[64]; + + if (strncmp("a=", split_start, strlen("a=")) == 0) { + split_start += strlen("a="); + } + split_start += strlen("candidate:"); + // a=candidate:448736988 1 udp 2122260223 172.17.0.1 49250 typ host generation 0 network-id 1 network-cost 50 // a=candidate:udpcandidate 1 udp 120 192.168.1.102 8000 typ host while ((split_end = strstr(split_start, " ")) != NULL && split_start < end) { diff --git a/src/peer_connection.c b/src/peer_connection.c index 45b6b4c..e68a354 100644 --- a/src/peer_connection.c +++ b/src/peer_connection.c @@ -557,3 +557,13 @@ char* peer_connection_lookup_sid_label(PeerConnection* pc, uint16_t sid) { } return NULL; // Not found } + +int peer_connection_add_ice_candidate(PeerConnection* pc, char* candidate) { + Agent* agent = &pc->agent; + if (ice_candidate_from_description(&agent->remote_candidates[agent->remote_candidates_count], candidate, candidate + strlen(candidate)) != 0) { + return -1; + } + + agent->remote_candidates_count++; + return 0; +} diff --git a/src/peer_connection.h b/src/peer_connection.h index ad0446c..d917884 100644 --- a/src/peer_connection.h +++ b/src/peer_connection.h @@ -144,6 +144,13 @@ int peer_connection_lookup_sid(PeerConnection* pc, const char* label, uint16_t* char* peer_connection_lookup_sid_label(PeerConnection* pc, uint16_t sid); +/** + * @brief adds a new remote candidate to the peer connection + * @param[in] peer connection + * @param[in] ice candidate + */ +int peer_connection_add_ice_candidate(PeerConnection* pc, char* ice_candidate); + #ifdef __cplusplus } #endif