node.js - 如何在 Electron App 中进行屏幕共享?
问题描述
我正在尝试使用 Electron、React 和 TypeScript 在 LAN 环境中构建两个用于屏幕共享的应用程序。一个应用程序将捕获屏幕流并进行 UDP 广播,另一个将在多个设备上运行的应用程序将接收流并显示它。我查看了desktopCapturer
Electron 提供的 API,但运行此代码示例时出现错误:
desktopCapturer
.getSources({ types: ["window", "screen"] })
.then(async (sources) => {
for (const source of sources) {
if (source.name === "Entire Screen") {
const displayMediaOptions = {
video: {
cursor: "always",
mandatory: {
chromeMediaSource: "desktop",
chromeMediaSourceId: source.id,
maxWidth: 800,
maxHeight: 700,
},
},
audio: false,
};
try {
const stream = await navigator.mediaDevices.getUserMedia(
displayMediaOptions
);
handleStream(stream);
} catch (e) {
handleError(e);
}
return;
}
}
});
错误是:
Argument of type '{ video: { cursor: string; mandatory: { chromeMediaSource: string; chromeMediaSourceId: string; maxWidth: number; maxHeight: number; }; }; audio: boolean; }' is not assignable to parameter of type 'MediaStreamConstraints'.
Types of property 'video' are incompatible.
Type '{ cursor: string; mandatory: { chromeMediaSource: string; chromeMediaSourceId: string; maxWidth: number; maxHeight: number; }; }' is not assignable to type 'boolean | MediaTrackConstraints'.
Type '{ cursor: string; mandatory: { chromeMediaSource: string; chromeMediaSourceId: string; maxWidth: number; maxHeight: number; }; }' has no properties in common with type 'MediaTrackConstraints'.ts(2345)
我查看了一下MediaTrackConstraints
,发现它不支持该mandatory
属性。我还发现 WebRTC 可能会有所帮助,但不知道它是否可以在没有任何服务器支持的 LAN 环境中工作?
所以我想知道这个问题是否有任何解决方法,或者我可以使用哪些其他技术在本地网络中进行屏幕共享?
解决方案
推荐阅读
- jquery - 哪种推荐人政策最安全?
- python - 如何使用代码在 R 或 Python 中求解矩阵方程 PAP^T=I
- apache-spark - 将数据从 pyspark 保存到 HBase 时出错
- python - Python 中 .JSON 文件转换和 CSV 操作的问题
- laravel - Laravel Sanctum 身份验证路线仅在生产中显示未经身份验证
- r - 使用 R 计算坐标列表到参考坐标的距离
- reactjs - 通过“单元格”选项更改数据时反应表无法过滤
- r - R有针织问题
- database - 用 B-tree 优化 AVLTree
- angular - NG8003:错误 NG8003:没有找到 exportAs 'ngForm' 的指令