summaryrefslogtreecommitdiff
path: root/example/main.c
diff options
context:
space:
mode:
authorChris Hiszpanski <chris.hiszpanski@verkada.com>2022-05-21 15:25:35 -0700
committerChris Hiszpanski <chris.hiszpanski@verkada.com>2022-05-21 15:45:26 -0700
commit97261b79b20e4e53ef3a5b7a37d1ffb0b5665bcb (patch)
tree809099efc2ac9ccfb440776eda5c63b6a1970931 /example/main.c
parent12df87e791ee6e468df31a6c468595b8c124a2b4 (diff)
* Added trtc_ prefixes
* Split into tinyrtc.c/h * Sending answer * Answer validates
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;