webrtc/js: Support pressing "enter" to connect

I press "enter" every time which doesn't work and then I click
"Connect", so let's fix that.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5045>
This commit is contained in:
Nirbheek Chauhan 2023-07-17 10:16:48 +05:30 committed by GStreamer Marge Bot
parent 5a3b31108d
commit 80603746af
2 changed files with 11 additions and 2 deletions

View file

@ -29,10 +29,10 @@
<br/> <br/>
<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" onkeypress="onTextKeyPress();" required>
<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. <!-- Request the peer to send the offer by sending the OFFER_REQUEST message.
Same as the --remote-offerer flag in the sendrecv C example --> Same as the --remote-offerer flag in the sendrecv C example -->
<input id="remote-offerer" type="checkbox" autocomplete="off"><span>Remote offerer</span> <input id="remote-offerer" type="checkbox" autocomplete="off"><span>Remote offerer</span>
</div> </div>

View file

@ -49,6 +49,15 @@ function onConnectClicked() {
setConnectButtonState("Disconnect"); setConnectButtonState("Disconnect");
} }
function onTextKeyPress(e) {
e = e ? e : window.event;
if (e.code == "Enter") {
onConnectClicked();
return false;
}
return true;
}
function getOurId() { function getOurId() {
return Math.floor(Math.random() * (9000 - 10) + 10).toString(); return Math.floor(Math.random() * (9000 - 10) + 10).toString();
} }