From 7c5fbf1aca25791d25e76bffbf389fbdaf884389 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sun, 1 Apr 2018 01:07:51 +0530 Subject: [PATCH] sendrecv/js: custom getUserMedia constraints The html page now contains a text area in which the default constraints will be added and can be edited. Closes https://github.com/centricular/gstwebrtc-demos/issues/11 --- webrtc/sendrecv/js/index.html | 5 +++++ webrtc/sendrecv/js/webrtc.js | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/webrtc/sendrecv/js/index.html b/webrtc/sendrecv/js/index.html index 1744715265..f52cd507ec 100644 --- a/webrtc/sendrecv/js/index.html +++ b/webrtc/sendrecv/js/index.html @@ -25,5 +25,10 @@
Status: unknown
Our id is unknown
+
+
+
getUserMedia constraints being used:
+
+
diff --git a/webrtc/sendrecv/js/webrtc.js b/webrtc/sendrecv/js/webrtc.js index a8386578d8..6c86c84570 100644 --- a/webrtc/sendrecv/js/webrtc.js +++ b/webrtc/sendrecv/js/webrtc.js @@ -15,6 +15,8 @@ var peer_id; // Override with your own STUN servers if you want var rtc_configuration = {iceServers: [{urls: "stun:stun.services.mozilla.com"}, {urls: "stun:stun.l.google.com:19302"}]}; +// The default constraints that will be attempted. Can be overriden by the user. +var default_constraints = {video: true, audio: true}; var connect_attempts = 0; var peer_connection; @@ -155,7 +157,9 @@ function onServerError(event) { } function getLocalStream() { - var constraints = {video: true, audio: true}; + var textarea = document.getElementById('constraints'); + var constraints = JSON.parse(textarea.value); + console.log(JSON.stringify(constraints)); // Add local stream if (navigator.mediaDevices.getUserMedia) { @@ -171,6 +175,10 @@ function websocketServerConnect() { setError("Too many connection attempts, aborting. Refresh page to try again"); return; } + // Populate constraints + var textarea = document.getElementById('constraints'); + if (textarea.value == '') + textarea.value = JSON.stringify(default_constraints); // Fetch the peer id to use peer_id = peer_id || getOurId(); ws_server = ws_server;