【发布时间】:2018-06-10 02:29:02
【问题描述】:
我正在尝试让屏幕流式传输到我的 Angular 5 Electron 应用程序。我使用的是 Electron 提供的 desktopCapturer。这是我的代码:
loadCurrentScreensource() {
desktopCapturer.getSources({
types: [
'window',
'screen'
]
}, (error, sources) => {
if (error) {
throw error;
}
console.log('Finding screen: ' + this.selectedScreenSource);
console.log(sources);
for (let i = 0; i < sources.length; ++i) {
if (sources[i].id === this.selectedScreenSource.id) {
console.log('Found screen');
const constraints = {
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: sources[i].id,
minWidth: 1280,
maxWidth: 1280,
minHeight: 720,
maxHeight: 720
}
}
};
navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => this.handleStream(stream))
.catch((e) => this.handleError(e));
return;
}
}
}
);
}
根据文档here,我需要使用约束的强制部分来获得正确的流。但是,TypeScript 给我一个错误,即属性“视频”的类型不兼容。如果我输入以下限制条件,有时我会收到我的网络摄像头流:
{ width: 1280, height: 720 }
mozzilla.org 的文档从未提及强制部分,所以我想我忽略了一些导入或某些东西让 getUserMedia 接受我的约束。要么,或者 getUserMedia 已更改,但文档没有?
我在这里做错了什么?
[编辑]
此外,MediaTrackConstraints 的文档没有强制属性,也没有 chromeMediaSourceId 属性。然而,这与 Electron 链接到的文档相同。
[edit2]
我找到了我之前忽略的deviceId 约束。当我使用以下约束时,我仍然得到网络摄像头流。
video: {
width: 1280,
height: 720,
deviceId: this.selectedScreenSource.id
}
【问题讨论】:
标签: angular typescript electron