Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
move handle_ice_candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredh committed Aug 6, 2022
1 parent db023b7 commit 92435ed
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
30 changes: 1 addition & 29 deletions src/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,34 +236,6 @@ static int handle_post_sdp(struct session *sess, const struct http_msg *msg)
}


static int handle_ice_candidate(struct session *sess, const struct odict *od)
{
const char *cand, *mid;
struct pl pl_cand;
char *cand2 = NULL;
int err;

cand = odict_string(od, "candidate");
mid = odict_string(od, "sdpMid");
if (!cand || !mid) {
warning("demo: candidate: missing 'candidate' or 'mid'\n");
return EPROTO;
}

err = re_regex(cand, str_len(cand), "candidate:[^]+", &pl_cand);
if (err)
return err;

pl_strdup(&cand2, &pl_cand);

peerconnection_add_ice_candidate(sess->pc, cand2, mid);

mem_deref(cand2);

return 0;
}


static void handle_get(struct http_conn *conn, const struct pl *path)
{
const char *ext, *mime;
Expand Down Expand Up @@ -391,7 +363,7 @@ static void http_req_handler(struct http_conn *conn,
goto out;
}

handle_ice_candidate(sess, od);
session_handle_ice_candidate(sess, od);

/* sync reply */
http_reply(conn, 204, "No Content",
Expand Down
2 changes: 2 additions & 0 deletions src/demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ struct session {

struct session *session_lookup(const struct list *sessl,
const struct http_msg *msg);
int session_handle_ice_candidate(struct session *sess,
const struct odict *od);
void session_close(struct session *sess, int err);


Expand Down
28 changes: 28 additions & 0 deletions src/sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,34 @@ struct session *session_lookup(const struct list *sessl,
}


int session_handle_ice_candidate(struct session *sess, const struct odict *od)
{
const char *cand, *mid;
struct pl pl_cand;
char *cand2 = NULL;
int err;

cand = odict_string(od, "candidate");
mid = odict_string(od, "sdpMid");
if (!cand || !mid) {
warning("demo: candidate: missing 'candidate' or 'mid'\n");
return EPROTO;
}

err = re_regex(cand, str_len(cand), "candidate:[^]+", &pl_cand);
if (err)
return err;

pl_strdup(&cand2, &pl_cand);

peerconnection_add_ice_candidate(sess->pc, cand2, mid);

mem_deref(cand2);

return 0;
}


void session_close(struct session *sess, int err)
{
if (err)
Expand Down

0 comments on commit 92435ed

Please sign in to comment.