Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Electron desktopCapturer.getSources()。则不是函数_Javascript_Node.js_Windows_Electron_Getusermedia - Fatal编程技术网

Javascript Electron desktopCapturer.getSources()。则不是函数

Javascript Electron desktopCapturer.getSources()。则不是函数,javascript,node.js,windows,electron,getusermedia,Javascript,Node.js,Windows,Electron,Getusermedia,在Windows10Pro版本1809上开发电子应用程序。我们的应用程序有一个浏览器窗口,当用户点击热键组合时,该窗口将呈现。浏览器窗口调用“renderer.js” <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Audio Visualizer</title> </head> <body>

在Windows10Pro版本1809上开发电子应用程序。我们的应用程序有一个浏览器窗口,当用户点击热键组合时,该窗口将呈现。浏览器窗口调用“renderer.js”

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Audio Visualizer</title>
  </head>
  <body>

    <!-- Content -->

    <script>
      require('./renderer.js')
    </script>
  </body>
</html>
我们的代码基本上是电子文档中示例的直接复制/粘贴。我们得到这个错误时遗漏了什么


我知道macOS有一个限制,您必须在不同的what(而不是navigator.mediaDevices.getUserMedia)中创建流,但我认为这个限制与我们面临的错误无关。

您使用的是什么版本的Electron和Node?正如Cory所指出的,文档显示了最新的文档,但您可能使用的是较旧的Electron版本,它还不支持promise版本的
getSources
是的,谢谢。我忽略了这一点。您使用的是什么版本的Electron和Node?正如Cory所指出的,文档显示了最新的文档,但您可能使用的是较旧的Electron版本,它还不支持promise版本的
getSources
是的,谢谢。我忽略了这一点。
desktopCapturer.getSources({ types: ['window', 'screen'] }).then(async sources => {
  for (const source of sources) {
    if (source.name === 'Electron') {
      try {
        const stream = await navigator.mediaDevices.getUserMedia({
          audio: {
            mandatory: {
             chromeMediaSource: 'desktop',
             chromeMediaSourceId: source.id 
            }
          },
          video: false
        })
        handleStream(stream)
      } catch (e) {
        handleError(e)
      }
      return
    }
  }
})

function handleStream (stream) {
  // create audio context and show audio visulaizaio
}

function handleError (e) {
  console.log(e)
}