summaryrefslogtreecommitdiff
path: root/example/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'example/main.c')
-rw-r--r--example/main.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/example/main.c b/example/main.c
index 33ef4bb..e850a40 100644
--- a/example/main.c
+++ b/example/main.c
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <unistd.h>
#include "jsmn.h"
@@ -60,7 +61,7 @@ struct trtc_ice_candidate_t parse_ice_candidate(const char *s)
}
// (callback) Called for each discovered local ICE candidate
-int on_ice_candidate(const struct trtc_ice_candidate_t c, void *arg) {
+void on_ice_candidate(const struct trtc_ice_candidate_t c, void *arg) {
// send ice candidate over signaling channel
printf("{"
"\"candidate\":\"%s\","
@@ -68,15 +69,18 @@ int on_ice_candidate(const struct trtc_ice_candidate_t c, void *arg) {
"\"sdpMid\":\"%s\","
"\"usernameFragment\":null"
"}\n", c.candidate, c.sdp_mline_index, c.sdp_mid);
-
- return 0;
}
int main(int argc, char **argv)
{
+ openlog(NULL, LOG_PERROR, LOG_USER);
+
// disable stdout buffering to ensure signaling messages send immediately
setvbuf(stdout, NULL, _IONBF, 0);
+ // initialize tinyrtc library
+ trtc_init();
+
// create peer connection
struct trtc_config_t cfg = {
.ice_servers = {
@@ -88,6 +92,12 @@ int main(int argc, char **argv)
}
};
struct trtc_peerconn_t* pc = trtc_peer_connection(cfg);
+ if (!pc) {
+ syslog(LOG_ERR, "trtc_peer_connection() failed");
+ return -1;
+ }
+
+ trtc_set_on_ice_candidate(pc, on_ice_candidate, NULL);
while (true) {
int n;
@@ -96,21 +106,32 @@ int main(int argc, char **argv)
if (n = getline(&msg, &msglen, stdin), -1 == n) {
+ syslog(LOG_ERR, "%m");
return -1;
}
+ // case: sdp offer
if (strstr(msg, "\"sdp\"")) {
- // got offer. send answer.
- printf("{\"sdp\":\"%s\",\"type\":\"answer\"}\n", trtc_create_answer(pc));
+ // XXX trtc_set_remote_description(pc, offer);
+ const char *answer = trtc_create_answer(pc);
+
+ /* send SDP answer via stdout signaling channel */
+ printf("{\"sdp\":\"%s\",\"type\":\"answer\"}\n", answer);
+
+ trtc_set_local_description(pc, answer);
+
+ // case: ice candidate
} 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);
+
+ // case: error
} else {
printf("unrecognized signaling message\n");
}
-
}
+
+ syslog(LOG_ERR, "terminating");
return 0;
}