desktopCapturer

    进程: Renderer

    下面的示例演示如何从标题为 Electron 的桌面窗口捕获视频:

    要从整个桌面同时捕获音频和视频, 传递给 [navigator.mediaDevices.getUserMedia] 的约束必须包括 chromeMediaSource: ' desktop ', 同时用于 audiovideo, 但不应包括 chromeMediaSourceId 约束。

    1. const constraints = {
    2. chromeMediaSource: 'desktop'
    3. }
    4. },
    5. video: {
    6. mandatory: {
    7. }
    8. }
    9. }

    desktopCapturer 模块有以下方法:

    • 对象
      • 类型String[]-列出要捕获的桌面源类型的字符串数组, 可用类型为 screenwindow
      • fetchWindowIcons Boolean (可选) - 设置为true以便启用获取窗口图标。 默认值为false。 当值为false时,源的appIcon属性返回null。 Same if a source has the type screen.

    Note Capturing the screen contents requires user consent on macOS 10.15 Catalina or higher, which can detected by [systemPreferences.getMediaAccessStatus].

    注意事项

    由于存在基本限制,因此navigator.mediaDevices.getUserMedia 无法在macOS上进行音频捕获,因此要访问系统音频的应用程序需要一个签名内核拓展. Chromium, and by extension Electron, does not provide this.