Created
July 14, 2022 02:39
-
-
Save dkzeanah/4c4e5e67558b8975350db81b86dbfd56 to your computer and use it in GitHub Desktop.
a test
This file contains hidden or 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>Document</title> | |
</head> | |
<body> | |
<video></video> | |
</body> | |
</html> |
This file contains hidden or 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') | |
const path = require('path') | |
app.whenReady().then(() => { | |
const mainWindow = new BrowserWindow({ | |
height: 600, | |
width: 600, | |
webPreferences: { | |
nodeIntegration: false, // default in Electron >= 5 | |
contextIsolation: true, // default in Electron >= 12 | |
preload: path.join(__dirname, 'preload.js') | |
} | |
}) | |
mainWindow.loadFile('index.html') | |
}) |
This file contains hidden or 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
{ | |
"name": "chilly-rest-approve-m6yuf", | |
"productName": "chilly-rest-approve-m6yuf", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "admin", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron": "19.0.6" | |
} | |
} |
This file contains hidden or 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. | |
// | |
function startCapture () { | |
desktopCapturer.getSources({ | |
types: ['window', 'screen'] | |
}).then(async sources => { | |
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() | |
} | |
window.addEventListener('DOMContentLoaded', () => { | |
startCapture() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment