sendrecv/js: custom getUserMedia constraints
authorNirbheek Chauhan <nirbheek@centricular.com>
Sat, 31 Mar 2018 19:37:51 +0000 (01:07 +0530)
committerNirbheek Chauhan <nirbheek@centricular.com>
Sat, 31 Mar 2018 19:40:22 +0000 (01:10 +0530)
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
webrtc/sendrecv/js/webrtc.js

index 1744715..f52cd50 100644 (file)
     <div><video id="stream" autoplay>Your browser doesn't support video</video></div>
     <div>Status: <span id="status">unknown</span></div>
     <div>Our id is <b id="peer-id">unknown</b></div>
+    <br/>
+    <div>
+      <div>getUserMedia constraints being used:</div>
+      <div><textarea id="constraints" cols=40 rows=4></textarea></div>
+    </div>
   </body>
 </html>
index a838657..6c86c84 100644 (file)
@@ -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;