applyConstraints(), getConstratints() doesn't work on Windows


#1

Electron v2.0.4
OS: Windows 10.

getConstraints() returns an empty object, and applyConstraints() doesn’t seem to be doing anything on a video track. Same code works fine with the same camera on Ubuntu 16.04, and Raspbian (latest build) on same version of Electron.

Is it not supported on Windows or am I missing/doing something wrong here?

Thanks in advance for help.

Code to create the app:

package.json:

{
  "name": "webrtc",
  "version": "1.0.1",
  "description": "WebRTC",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "devDependencies": {
    "electron": "latest"
  }
}

index.html:

    <!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>Camera Test</title>
</head>

<body>
  <div>
    <video id="video" playsinline autoplay width=100%></video>
  </div>
</body>

<script src="getCamera.js"></script>
</html>

getCamera.js:

"use strict";

const video = document.getElementById("video");
var constraints = window.constraints = {
  audio: false,
  video: {
    width: {ideal: 1280},
    height: {ideal: 720},
  },
};

navigator.mediaDevices.getUserMedia(constraints).then(videoSetup).catch(errorHandling);

function videoSetup(stream)
{
  const track = stream.getVideoTracks()[0];
  console.log("Device: " + track.label);
  window.stream = stream;
  video.srcObject = stream;
  setTimeout(function(){
    // track.applyConstraints({video: {width: 1920, height: 1080}});
    var capabilities = track.getCapabilities();
    console.log("Capabilities: " + JSON.stringify(capabilities));
  }, 2000);
}

function errorHandling(error)
{
  console.log("Error: " + error);
}

main.js:

"use strict";

const electron = require("electron");
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;

const path = require("path");
const url = require("url");

let mainWindow;

function createWindow()
{
  mainWindow = new BrowserWindow({width: 1920, height: 1080});
  mainWindow.loadURL(url.format({
    pathname: path.join(__dirname, "index.html"),
    protocol: "file:",
    slashes: true
  }));

  mainWindow.webContents.openDevTools();

  mainWindow.on("closed", function(){
    mainWindow = null
  });
}

app.on("ready", createWindow);

app.on("window-all-closed", function(){
  app.quit();
});

app.on("activate", function(){
  if(mainWindow == null)
  {
    createWindow()
  }
});