Electron desktopCapturer 模块
desktopCapturer 模块可用来获取可用资源,这个资源可通过 getUserMedia 捕获得到. // 在渲染进程中.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'); } 当调用 navigator.webkitGetUserMedia 时创建一个约束对象,如果使用 desktopCapturer 的资源,必须设置 chromeMediaSource 为 "desktop" ,并且 audio 为 false. 如果你想捕获整个桌面的 audio 和 video,你可以设置 chromeMediaSource 为 "screen" ,和 audio 为 true. 当使用这个方法的时候,不可以指定一个 chromeMediaSourceId. 方法desktopCapturer 模块有如下方法: desktopCapturer.getSources(options, callback)
发起一个请求,获取所有桌面资源,当请求完成的时候使用 callback(error, sources) 调用 callback . sources 是一个 Source 对象数组, 每个 Source 表示了一个捕获的屏幕或单独窗口,并且有如下属性 :
注意: 不能保证 source.thumbnail 的 size 和 options 中的 thumnbailSize 一直一致. 它也取决于屏幕或窗口的缩放比例. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |