javascript - Electron desktopCapturer.getSources().then 不是函数
问题描述
在 Windows 10 Pro 版本 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>
该renderer.js
文件处理来自该浏览器窗口中的用户的交互,并尝试desktopCapturer
使用屏幕(整个屏幕)作为源来捕获用户的音频。
我按照电子文档上的文档进行操作,但出现错误desktopCapturer.getSources().then is not a function
这是renderer.js
文件
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)
}
我们的代码基本上是电子文档中包含的示例的直接复制/粘贴。我们错过了什么,我们得到了这个错误?
我知道 macOS 存在一个限制,您必须以不同的内容(而不是 navigator.mediaDevices.getUserMedia)创建流,但我认为该限制与我们面临的这个错误无关。
解决方案
推荐阅读
- php - wordpress 自定义模板从页面转换中读取数据
- postgresql - 使用不同的值多次调用函数
- scala - 高阶滤波函数
- batch-file - 需要将带有换行符的 Teradata 错误消息作为参数传递给 bat 文件
- java - Maven Surefire:(重新)加载类以在分叉中进行隔离测试
- android - 有没有办法在 jetpack-compose 中不使用 ConstraintLayout 来实现 Dimension.fillToConstraints 行为?
- amazon-web-services - 使用命令行从 AWS S3 存储桶中获取数据
- flutter - flutter pdf查看器本机库无法加载
- elasticsearch - 如何用循环替换if?
- service-worker - Chrome 不使用工作箱为服务人员提供页面