打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
electron 屏幕捕捉 屏幕截图

desktopCapturer

The desktopCapturer module can be used to get available sources that can be used to be captured with getUserMedia.

// In the renderer process.var desktopCapturer = require('electron').desktopCapturer;desktopCapturer.getSources({types: ['window', 'screen']}, function(error, sources) {  if (error) throw error;  for (var i = 0; i < sources.length; ++i) {    if (sources[i].name == "Electron") {      navigator.webkitGetUserMedia({        audio: false,        video: {          mandatory: {            chromeMediaSource: 'desktop',            chromeMediaSourceId: sources[i].id,            minWidth: 1280,            maxWidth: 1280,            minHeight: 720,            maxHeight: 720          }        }      }, gotStream, getUserMediaError);      return;    }  }});function gotStream(stream) {  document.querySelector('video').src = URL.createObjectURL(stream);}function getUserMediaError(e) {  console.log('getUserMediaError');}

When creating a constraints object for the navigator.webkitGetUserMedia call, if you are using a source fromdesktopCapturer your chromeMediaSource must be set to "desktop" and your audio must be set to false.

If you wish to capture the audio and video from the entire desktop you can set chromeMediaSource to "screen" and audio totrue. When using this method you cannot specify a chromeMediaSourceId.

Methods

The desktopCapturer module has the following methods:

desktopCapturer.getSources(options, callback)

  • options Object
    • types Array - An array of String that lists the types of desktop sources to be captured, available types are screen andwindow.
    • thumbnailSize Object (optional) - The suggested size that thumbnail should be scaled, it is {width: 150, height: 150} by default.
  • callback Function

Starts a request to get all desktop sources, callback will be called with callback(error, sources) when the request is completed.

The sources is an array of Source objects, each Source represents a captured screen or individual window, and has following properties:

  • id String - The id of the captured window or screen used in navigator.webkitGetUserMedia. The format looks likewindow:XX or screen:XX where XX is a random generated number.
  • name String - The described name of the capturing screen or window. If the source is a screen, the name will be Entire Screen or Screen <index>; if it is a window, the name will be the window's title.
  • thumbnail NativeImage - A thumbnail image.

Note: There is no guarantee that the size of source.thumbnail is always the same as the thumnbailSize in options. It also depends on the scale of the screen or window.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
JS获取当前对象大小以及屏幕分辨率等
获取各种浏览器可见窗口大小
js获取屏幕(设备)宽高
求一个main主程序
改造一下 BeanUtils,优雅的实现 List 数据拷贝
自动识别手机访问脚本
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服