-
-
Save nornagon/925744c7c67347d67c5b29e91c31e37e 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> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
<video id="video" autoplay playsinline></video> | |
<script> | |
document.addEventListener('DOMContentLoaded', async () => { | |
const { ipcRenderer } = require('electron'); | |
const sourceId = ipcRenderer.sendSync('get-media-source-id') | |
const stream = await navigator.mediaDevices.getUserMedia({ | |
video: { | |
mandatory: { | |
chromeMediaSource: 'desktop', | |
chromeMediaSourceId: sourceId, | |
maxWidth: Math.min(screen.width, 1280), | |
maxHeight: Math.min(screen.height, 720), | |
}, | |
}, | |
audio: false, | |
}); | |
const video = document.getElementById('video'); | |
video.srcObject = stream; | |
}) | |
</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
// Modules to control application life and create native browser window | |
const {app, BrowserWindow, ipcMain} = require('electron') | |
ipcMain.on('get-media-source-id', (e) => { | |
e.returnValue = BrowserWindow.fromWebContents(e.sender).getMediaSourceId(); | |
}) | |
function createWindow () { | |
// Create the browser window. | |
const mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
nodeIntegration: true, | |
contextIsolation: false, | |
} | |
}) | |
mainWindow.loadFile('index.html') | |
} | |
app.whenReady().then(createWindow) |
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
// Empty |
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
// Empty |
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
/* Empty */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment