applyConstraints(),getCapabilities()在Windows版Electron上不起作用

时间:2018-07-10 21:41:42

标签: electron webrtc

无法在基于电子(v2.0.4) getCapabilities(), applyConstraints()来获取或应用任何约束。 >对于 Windows 。 getCapabilities()返回一个空对象。

但是,我能够使用相同的相机,相同版本的Electron在Ubuntu 16.04和Raspbian上获得并应用约束。当我直接在Windows的chrome上运行index.html时,它也可以正常工作。

Electron for Windows尚不支持它,或者我正在丢失某些东西吗?

要运行该应用程序,请将以下文件放在目录中,在该目录中运行 npm install npm start

package.json

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

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()
      }
    });

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);
    }

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>

在Electron Windows上 getCapabilities()的输出:功能:{}

在Chrome Windows / Ubuntu / Raspbian上 getCapabilities()的输出:

功能:{“ aspectRatio”:{“ max”:2304,“ min”:0.0006510416666666666},“亮度”:{},“ colorTemperature”:{},“对比度”:{},“ deviceId”:“ b054cbcea100ef88ffbe463a2caee133a5fd10b11915d0e2c5a230fdbf4776b9“,” exposureCompensation“:{},” exposureMode“:[” continuous“,” manual“],” faceingMode“:[],” frameRate“:{” max“:6min240325927高度”:{“最大”:1536,“最小”:1},“饱和度”:{},“清晰度”:{},“白色平衡模式”:[“连续”,“手动”],“宽度”:{ “ max”:2304,“ min”:1},“ zoom”:{}}

1 个答案:

答案 0 :(得分:1)

electron 2.0.4基于Chrome 61(请检查navigator.userAgent),它没有对Chrome 66中附带的getCapabilities进行有意义的实现。据我所记得,即使版本发布,Chrome 63中附带的约束也适用笔记不提。