From 6c229fee0fa1bc3ba4ed7309a00e8e1df18b0694 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Fri, 25 Mar 2016 23:23:57 +0100 Subject: [PATCH] Update desktop-capturer module --- .../github-electron-renderer-tests.ts | 35 +++++++++++++++++++ .../github-electron.desktop-capturer.d.ts | 32 +++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/github-electron/github-electron-renderer-tests.ts b/github-electron/github-electron-renderer-tests.ts index 6ec4d0b2f..d995f4933 100644 --- a/github-electron/github-electron-renderer-tests.ts +++ b/github-electron/github-electron-renderer-tests.ts @@ -100,6 +100,41 @@ crashReporter.start({ autoSubmit: true }); +// desktopCapturer +// https://github.com/atom/electron/blob/master/docs/api/desktop-capturer.md + +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 as any).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: any) { + (document.querySelector('video') as HTMLVideoElement).src = URL.createObjectURL(stream); +} + +function getUserMediaError(error: Error) { + console.log('getUserMediaError', error); +} + // nativeImage // https://github.com/atom/electron/blob/master/docs/api/native-image.md diff --git a/github-electron/github-electron.desktop-capturer.d.ts b/github-electron/github-electron.desktop-capturer.d.ts index 900c4a4db..d938a1ed0 100644 --- a/github-electron/github-electron.desktop-capturer.d.ts +++ b/github-electron/github-electron.desktop-capturer.d.ts @@ -6,13 +6,29 @@ /// declare namespace Electron { - + /** + * The desktopCapturer module can be used to get available sources + * that can be used to be captured with getUserMedia. + */ interface DesktopCapturer { + /** + * Starts a request to get all desktop sources. + * + * 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. + */ getSources(options: any, callback: (error: Error, sources: DesktopCapturerSource[]) => any): void; } interface DesktopCapturerOptions { - types?: string[]; + /** + * The types of desktop sources to be captured. + */ + types?: ('screen' | 'window')[]; + /** + * The suggested size that thumbnail should be scaled. + * Default: {width: 150, height: 150} + */ thumbnailSize?: { width: number; height: number; @@ -20,8 +36,20 @@ declare namespace Electron { } interface DesktopCapturerSource { + /** + * The id of the captured window or screen used in navigator.webkitGetUserMedia. + * The format looks like window:XX or screen:XX where XX is a random generated number. + */ id: string; + /** + * The described name of the capturing screen or window. + * If the source is a screen, the name will be Entire Screen or Screen ; + * if it is a window, the name will be the window’s title. + */ name: string; + /** + * A thumbnail image. + */ thumbnail: NativeImage; } }