Skip to content

Commit

Permalink
Merge pull request #127 from Sean-Der/main
Browse files Browse the repository at this point in the history
Implement peer_connection_add_ice_candidate
  • Loading branch information
sepfy authored Sep 16, 2024
2 parents c38e7e2 + 415e238 commit 3822c92
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions src/peer_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 7 additions & 0 deletions src/peer_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3822c92

Please sign in to comment.