Created
August 22, 2018 03:09
-
-
Save felixrieseberg/8552668cfd3cc32758a2b0a066e7c2fa to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Hi</title> | |
</head> | |
<body> | |
<video></video> | |
<script> | |
require('./renderer.js') | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Access information about media sources that can be used to capture audio | |
// and video from the desktop using the navigator.mediaDevices.getUserMedia API. | |
// | |
// For more info, see: | |
// https://electronjs.org/docs/api/desktop-capturer | |
const { app, BrowserWindow } = require('electron') | |
let mainWindow = null | |
app.on('ready', () => { | |
mainWindow = new BrowserWindow({ height: 600, width: 600 }) | |
mainWindow.loadFile('index.html') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { desktopCapturer } = require('electron') | |
// The following example shows how to capture video from | |
// the screen. It also grabs each window, so you could | |
// just grab video from a single window. | |
// | |
desktopCapturer.getSources({ | |
types: ['window', 'screen'] | |
}, (error, sources) => { | |
if (error) throw error | |
for (let i = 0; i < sources.length; ++i) { | |
console.log(sources[i]) | |
if (sources[i].id.startsWith('screen')) { | |
navigator.mediaDevices.getUserMedia({ | |
audio: false, | |
video: { | |
mandatory: { | |
chromeMediaSource: 'desktop', | |
chromeMediaSourceId: sources[i].id, | |
minWidth: 1280, | |
maxWidth: 1280, | |
minHeight: 720, | |
maxHeight: 720 | |
} | |
} | |
}).then((stream) => handleStream(stream)) | |
.catch((error) => console.log(error)) | |
} | |
} | |
}) | |
function handleStream (stream) { | |
const video = document.querySelector('video') | |
video.srcObject = stream | |
video.onloadedmetadata = (e) => video.play() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment