sendrecv/js: Add an UI for connecting to specified peer id

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-examples/-/merge_requests/28>
This commit is contained in:
Seungha Yang 2020-11-27 18:16:52 +09:00
parent 9e83c09be6
commit 85aeda42fe
2 changed files with 22 additions and 0 deletions

View file

@ -26,6 +26,13 @@
<div><video id="stream" autoplay playsinline>Your browser doesn't support video</video></div>
<div>Status: <span id="status">unknown</span></div>
<div><textarea id="text" cols=40 rows=4></textarea></div>
<br/>
<div>
<label for="peer-connect">Enter peer id</label>
<input id="peer-connect" type="text" name="text">
<button onclick="onConnectClicked();">Connect</button>
</div>
<div>Our id is <b id="peer-id">unknown</b></div>
<br/>
<div>

View file

@ -25,6 +25,16 @@ var ws_conn;
// Promise for local stream after constraints are approved by the user
var local_stream_promise;
function onConnectClicked() {
var id = document.getElementById("peer-connect").value;
if (id == "") {
alert("Peer id must be filled out");
return;
}
ws_conn.send("SESSION " + id);
}
function getOurId() {
return Math.floor(Math.random() * (9000 - 10) + 10).toString();
}
@ -115,6 +125,11 @@ function onServerMessage(event) {
case "HELLO":
setStatus("Registered with server, waiting for call");
return;
case "SESSION_OK":
setStatus("Starting negotiation");
if (!peer_connection)
createCall(null).then (generateOffer);
return;
default:
if (event.data.startsWith("ERROR")) {
handleIncomingError(event.data);