sendrecv: Fix SDP message format

The format is {'sdp': {'sdp': <sdp>, 'type': <sdptype>}}

The multiparty-sendrecv demo already uses this format.
This commit is contained in:
Nirbheek Chauhan 2018-03-23 11:36:40 +05:30
parent 2b82525bb0
commit 20cf2503ee
2 changed files with 18 additions and 11 deletions

View file

@ -447,7 +447,7 @@ on_server_message (SoupWebsocketConnection * conn, SoupWebsocketDataType type,
/* Look for JSON messages containing SDP and ICE candidates */ /* Look for JSON messages containing SDP and ICE candidates */
} else { } else {
JsonNode *root; JsonNode *root;
JsonObject *object; JsonObject *object, *child;
JsonParser *parser = json_parser_new (); JsonParser *parser = json_parser_new ();
if (!json_parser_load_from_data (parser, text, -1, NULL)) { if (!json_parser_load_from_data (parser, text, -1, NULL)) {
g_printerr ("Unknown message '%s', ignoring", text); g_printerr ("Unknown message '%s', ignoring", text);
@ -466,20 +466,27 @@ on_server_message (SoupWebsocketConnection * conn, SoupWebsocketDataType type,
/* Check type of JSON message */ /* Check type of JSON message */
if (json_object_has_member (object, "sdp")) { if (json_object_has_member (object, "sdp")) {
int ret; int ret;
const gchar *text;
GstSDPMessage *sdp; GstSDPMessage *sdp;
const gchar *text, *sdptype;
GstWebRTCSessionDescription *answer; GstWebRTCSessionDescription *answer;
g_assert_cmphex (app_state, ==, PEER_CALL_NEGOTIATING); g_assert_cmphex (app_state, ==, PEER_CALL_NEGOTIATING);
g_assert_true (json_object_has_member (object, "type")); child = json_object_get_object_member (object, "sdp");
if (!json_object_has_member (child, "type")) {
cleanup_and_quit_loop ("ERROR: received SDP without 'type'",
PEER_CALL_ERROR);
goto out;
}
sdptype = json_object_get_string_member (child, "type");
/* In this example, we always create the offer and receive one answer. /* In this example, we always create the offer and receive one answer.
* See tests/examples/webrtcbidirectional.c in gst-plugins-bad for how to * See tests/examples/webrtcbidirectional.c in gst-plugins-bad for how to
* handle offers from peers and reply with answers using webrtcbin. */ * handle offers from peers and reply with answers using webrtcbin. */
g_assert_cmpstr (json_object_get_string_member (object, "type"), ==, g_assert_cmpstr (sdptype, ==, "answer");
"answer");
text = json_object_get_string_member (object, "sdp"); text = json_object_get_string_member (child, "sdp");
g_print ("Received answer:\n%s\n", text); g_print ("Received answer:\n%s\n", text);
@ -504,13 +511,12 @@ on_server_message (SoupWebsocketConnection * conn, SoupWebsocketDataType type,
app_state = PEER_CALL_STARTED; app_state = PEER_CALL_STARTED;
} else if (json_object_has_member (object, "ice")) { } else if (json_object_has_member (object, "ice")) {
JsonObject *ice;
const gchar *candidate; const gchar *candidate;
gint sdpmlineindex; gint sdpmlineindex;
ice = json_object_get_object_member (object, "ice"); child = json_object_get_object_member (object, "ice");
candidate = json_object_get_string_member (ice, "candidate"); candidate = json_object_get_string_member (child, "candidate");
sdpmlineindex = json_object_get_int_member (ice, "sdpMLineIndex"); sdpmlineindex = json_object_get_int_member (child, "sdpMLineIndex");
/* Add ice candidate sent by remote peer */ /* Add ice candidate sent by remote peer */
g_signal_emit_by_name (webrtc1, "add-ice-candidate", sdpmlineindex, g_signal_emit_by_name (webrtc1, "add-ice-candidate", sdpmlineindex,

View file

@ -63,7 +63,8 @@ function onLocalDescription(desc) {
console.log("Got local description: " + JSON.stringify(desc)); console.log("Got local description: " + JSON.stringify(desc));
peer_connection.setLocalDescription(desc).then(function() { peer_connection.setLocalDescription(desc).then(function() {
setStatus("Sending SDP answer"); setStatus("Sending SDP answer");
ws_conn.send(JSON.stringify(peer_connection.localDescription)); sdp = {'sdp': peer_connection.localDescription}
ws_conn.send(JSON.stringify(sdp));
}); });
} }