mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-02 06:31:08 +00:00
sendrecv/js: Implement state handling for Connect button
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-examples/-/merge_requests/31>
This commit is contained in:
parent
eb89cd01ba
commit
2892a8b206
2 changed files with 13 additions and 1 deletions
|
@ -30,7 +30,7 @@
|
||||||
<div>
|
<div>
|
||||||
<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">
|
||||||
<button onclick="onConnectClicked();">Connect</button>
|
<input id="peer-connect-button" onclick="onConnectClicked();" type="button" value="Connect">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>Our id is <b id="peer-id">unknown</b></div>
|
<div>Our id is <b id="peer-id">unknown</b></div>
|
||||||
|
|
|
@ -25,7 +25,16 @@ var ws_conn;
|
||||||
// Promise for local stream after constraints are approved by the user
|
// Promise for local stream after constraints are approved by the user
|
||||||
var local_stream_promise;
|
var local_stream_promise;
|
||||||
|
|
||||||
|
function setConnectButtonState(value) {
|
||||||
|
document.getElementById("peer-connect-button").value = value;
|
||||||
|
}
|
||||||
|
|
||||||
function onConnectClicked() {
|
function onConnectClicked() {
|
||||||
|
if (document.getElementById("peer-connect-button").value == "Disconnect") {
|
||||||
|
resetState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var id = document.getElementById("peer-connect").value;
|
var id = document.getElementById("peer-connect").value;
|
||||||
if (id == "") {
|
if (id == "") {
|
||||||
alert("Peer id must be filled out");
|
alert("Peer id must be filled out");
|
||||||
|
@ -33,6 +42,7 @@ function onConnectClicked() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ws_conn.send("SESSION " + id);
|
ws_conn.send("SESSION " + id);
|
||||||
|
setConnectButtonState("Disconnect");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOurId() {
|
function getOurId() {
|
||||||
|
@ -237,6 +247,7 @@ function websocketServerConnect() {
|
||||||
document.getElementById("peer-id").textContent = peer_id;
|
document.getElementById("peer-id").textContent = peer_id;
|
||||||
ws_conn.send('HELLO ' + peer_id);
|
ws_conn.send('HELLO ' + peer_id);
|
||||||
setStatus("Registering with server");
|
setStatus("Registering with server");
|
||||||
|
setConnectButtonState("Connect");
|
||||||
});
|
});
|
||||||
ws_conn.addEventListener('error', onServerError);
|
ws_conn.addEventListener('error', onServerError);
|
||||||
ws_conn.addEventListener('message', onServerMessage);
|
ws_conn.addEventListener('message', onServerMessage);
|
||||||
|
@ -327,5 +338,6 @@ function createCall(msg) {
|
||||||
if (msg != null)
|
if (msg != null)
|
||||||
setStatus("Created peer connection for call, waiting for SDP");
|
setStatus("Created peer connection for call, waiting for SDP");
|
||||||
|
|
||||||
|
setConnectButtonState("Disconnect");
|
||||||
return local_stream_promise;
|
return local_stream_promise;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue