summaryrefslogtreecommitdiff
path: root/example/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'example/main.c')
-rw-r--r--example/main.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/example/main.c b/example/main.c
index 6223898..33ef4bb 100644
--- a/example/main.c
+++ b/example/main.c
@@ -17,9 +17,9 @@ static bool matches(const char *json, jsmntok_t *tok, const char *s) {
}
// Parses ICE candidate from stringified JSON
-struct ice_candidate_t parse_ice_candidate(const char *s)
+struct trtc_ice_candidate_t parse_ice_candidate(const char *s)
{
- struct ice_candidate_t c = { 0 };
+ struct trtc_ice_candidate_t c = { 0 };
int i, r;
jsmn_parser p;
@@ -60,7 +60,7 @@ struct ice_candidate_t parse_ice_candidate(const char *s)
}
// (callback) Called for each discovered local ICE candidate
-int on_ice_candidate(const struct ice_candidate_t c, void *arg) {
+int on_ice_candidate(const struct trtc_ice_candidate_t c, void *arg) {
// send ice candidate over signaling channel
printf("{"
"\"candidate\":\"%s\","
@@ -78,7 +78,7 @@ int main(int argc, char **argv)
setvbuf(stdout, NULL, _IONBF, 0);
// create peer connection
- struct configuration_t cfg = {
+ struct trtc_config_t cfg = {
.ice_servers = {
{
.urls = {
@@ -87,25 +87,29 @@ int main(int argc, char **argv)
}
}
};
- struct peerconn_t* pc = rtc_peer_connection(cfg);
-
- printf("alert! starting\n");
+ struct trtc_peerconn_t* pc = trtc_peer_connection(cfg);
while (true) {
int n;
- char *m = NULL;
- size_t len = 0;
+ char *msg = NULL;
+ size_t msglen = 0;
- if (n = getline(&m, &len, stdin), -1 == n) {
+ if (n = getline(&msg, &msglen, stdin), -1 == n) {
return -1;
}
- struct ice_candidate_t c = parse_ice_candidate(m);
-
- on_ice_candidate(c, NULL);
+ if (strstr(msg, "\"sdp\"")) {
+ // got offer. send answer.
+ printf("{\"sdp\":\"%s\",\"type\":\"answer\"}\n", trtc_create_answer(pc));
+ } else if (strstr(msg, "\"candidate\"")) {
+ struct trtc_ice_candidate_t c = parse_ice_candidate(msg);
+ on_ice_candidate(c, NULL);
+ trtc_add_ice_candidate(pc, c);
+ } else {
+ printf("unrecognized signaling message\n");
+ }
- add_ice_candidate(pc, c);
}
return 0;