mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-11 10:56:38 +00:00
sendrecv: Implement remote-offerer option for JS example
Now you can check the "Remote offerer" checkbox in the JS example to force the peer to send the SDP offer. This involved implementing support for receiving the OFFER_REQUEST message in the C example. As a side-effect of this, the C example will no longer send OFFER_REQUEST automatically when the --our-id option is passed. It will only do so when the --remote-offerer option is explicitly passed. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-examples/-/merge_requests/31>
This commit is contained in:
parent
28aa23dc20
commit
f8cbae9d6e
3 changed files with 29 additions and 6 deletions
|
@ -285,11 +285,12 @@ on_offer_created (GstPromise * promise, gpointer user_data)
|
||||||
static void
|
static void
|
||||||
on_negotiation_needed (GstElement * element, gpointer user_data)
|
on_negotiation_needed (GstElement * element, gpointer user_data)
|
||||||
{
|
{
|
||||||
|
gboolean create_offer = GPOINTER_TO_INT (user_data);
|
||||||
app_state = PEER_CALL_NEGOTIATING;
|
app_state = PEER_CALL_NEGOTIATING;
|
||||||
|
|
||||||
if (remote_is_offerer || our_id) {
|
if (remote_is_offerer) {
|
||||||
soup_websocket_connection_send_text (ws_conn, "OFFER_REQUEST");
|
soup_websocket_connection_send_text (ws_conn, "OFFER_REQUEST");
|
||||||
} else {
|
} else if (create_offer) {
|
||||||
GstPromise *promise =
|
GstPromise *promise =
|
||||||
gst_promise_new_with_change_func (on_offer_created, NULL, NULL);
|
gst_promise_new_with_change_func (on_offer_created, NULL, NULL);
|
||||||
g_signal_emit_by_name (webrtc1, "create-offer", NULL, promise);
|
g_signal_emit_by_name (webrtc1, "create-offer", NULL, promise);
|
||||||
|
@ -372,7 +373,7 @@ on_ice_gathering_state_notify (GstElement * webrtcbin, GParamSpec * pspec,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
start_pipeline (void)
|
start_pipeline (gboolean create_offer)
|
||||||
{
|
{
|
||||||
GstStateChangeReturn ret;
|
GstStateChangeReturn ret;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
@ -397,7 +398,7 @@ start_pipeline (void)
|
||||||
/* This is the gstwebrtc entry point where we create the offer and so on. It
|
/* This is the gstwebrtc entry point where we create the offer and so on. It
|
||||||
* will be called when the pipeline goes to PLAYING. */
|
* will be called when the pipeline goes to PLAYING. */
|
||||||
g_signal_connect (webrtc1, "on-negotiation-needed",
|
g_signal_connect (webrtc1, "on-negotiation-needed",
|
||||||
G_CALLBACK (on_negotiation_needed), NULL);
|
G_CALLBACK (on_negotiation_needed), GINT_TO_POINTER (create_offer));
|
||||||
/* We need to transmit this ICE candidate to the browser via the websockets
|
/* We need to transmit this ICE candidate to the browser via the websockets
|
||||||
* signalling server. Incoming ice candidates from the browser need to be
|
* signalling server. Incoming ice candidates from the browser need to be
|
||||||
* added by us too, see on_server_message() */
|
* added by us too, see on_server_message() */
|
||||||
|
@ -601,7 +602,17 @@ on_server_message (SoupWebsocketConnection * conn, SoupWebsocketDataType type,
|
||||||
|
|
||||||
app_state = PEER_CONNECTED;
|
app_state = PEER_CONNECTED;
|
||||||
/* Start negotiation (exchange SDP and ICE candidates) */
|
/* Start negotiation (exchange SDP and ICE candidates) */
|
||||||
if (!start_pipeline ())
|
if (!start_pipeline (TRUE))
|
||||||
|
cleanup_and_quit_loop ("ERROR: failed to start pipeline",
|
||||||
|
PEER_CALL_ERROR);
|
||||||
|
} else if (g_strcmp0 (text, "OFFER_REQUEST") == 0) {
|
||||||
|
if (app_state != SERVER_REGISTERED) {
|
||||||
|
gst_printerr ("Received OFFER_REQUEST at a strange time, ignoring\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
gst_print ("Received OFFER_REQUEST, sending offer\n");
|
||||||
|
/* Peer wants us to start negotiation (exchange SDP and ICE candidates) */
|
||||||
|
if (!start_pipeline (TRUE))
|
||||||
cleanup_and_quit_loop ("ERROR: failed to start pipeline",
|
cleanup_and_quit_loop ("ERROR: failed to start pipeline",
|
||||||
PEER_CALL_ERROR);
|
PEER_CALL_ERROR);
|
||||||
} else if (g_str_has_prefix (text, "ERROR")) {
|
} else if (g_str_has_prefix (text, "ERROR")) {
|
||||||
|
@ -645,7 +656,7 @@ on_server_message (SoupWebsocketConnection * conn, SoupWebsocketDataType type,
|
||||||
/* If peer connection wasn't made yet and we are expecting peer will
|
/* If peer connection wasn't made yet and we are expecting peer will
|
||||||
* connect to us, launch pipeline at this moment */
|
* connect to us, launch pipeline at this moment */
|
||||||
if (!webrtc1 && our_id) {
|
if (!webrtc1 && our_id) {
|
||||||
if (!start_pipeline ()) {
|
if (!start_pipeline (FALSE)) {
|
||||||
cleanup_and_quit_loop ("ERROR: failed to start pipeline",
|
cleanup_and_quit_loop ("ERROR: failed to start pipeline",
|
||||||
PEER_CALL_ERROR);
|
PEER_CALL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
<label for="peer-connect">Enter peer id</label>
|
<label for="peer-connect">Enter peer id</label>
|
||||||
<input id="peer-connect" type="text" name="text">
|
<input id="peer-connect" type="text" name="text">
|
||||||
<input id="peer-connect-button" onclick="onConnectClicked();" type="button" value="Connect">
|
<input id="peer-connect-button" onclick="onConnectClicked();" type="button" value="Connect">
|
||||||
|
<!-- Request the peer to send the offer by sending the OFFER_REQUEST message.
|
||||||
|
Same as the --remote-offerer flag in the sendrecv C example -->
|
||||||
|
<input id="remote-offerer" type="checkbox" autocomplete="off"><span>Remote offerer</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>Our id is <b id="peer-id">unknown</b></div>
|
<div>Our id is <b id="peer-id">unknown</b></div>
|
||||||
|
|
|
@ -29,6 +29,10 @@ function setConnectButtonState(value) {
|
||||||
document.getElementById("peer-connect-button").value = value;
|
document.getElementById("peer-connect-button").value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wantRemoteOfferer() {
|
||||||
|
return document.getElementById("remote-offerer").checked;
|
||||||
|
}
|
||||||
|
|
||||||
function onConnectClicked() {
|
function onConnectClicked() {
|
||||||
if (document.getElementById("peer-connect-button").value == "Disconnect") {
|
if (document.getElementById("peer-connect-button").value == "Disconnect") {
|
||||||
resetState();
|
resetState();
|
||||||
|
@ -137,6 +141,11 @@ function onServerMessage(event) {
|
||||||
return;
|
return;
|
||||||
case "SESSION_OK":
|
case "SESSION_OK":
|
||||||
setStatus("Starting negotiation");
|
setStatus("Starting negotiation");
|
||||||
|
if (wantRemoteOfferer()) {
|
||||||
|
ws_conn.send("OFFER_REQUEST");
|
||||||
|
setStatus("Sent OFFER_REQUEST, waiting for offer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!peer_connection)
|
if (!peer_connection)
|
||||||
createCall(null).then (generateOffer);
|
createCall(null).then (generateOffer);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue