-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
57 lines (48 loc) · 1.35 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const { desktopCapturer } = require('electron');
const ipc = require('electron').ipcRenderer
const video = document.querySelector('video');
const canvas = document.querySelector('canvas');
window.onload = function () {
getVideoSources()
}
async function getVideoSources() {
const inputSources = await desktopCapturer.getSources({
types: ['window', 'screen']
});
inputSources.map(source => {
if (source.name === 'Entire Screen' || source.name === 'Screen 1') {
selectSource(source)
}
})
}
async function selectSource(source) {
const constraints = {
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: source.id,
}
}
};
const stream = await navigator.mediaDevices.getUserMedia(constraints);
video.srcObject = stream;
video.play()
}
function resizeCanvas() {
var vW = video.getBoundingClientRect().width
var vH = video.getBoundingClientRect().height
var vT = video.getBoundingClientRect().top
var vL = video.getBoundingClientRect().left
canvas.style.width = vW + "px";
canvas.style.height = vH + "px";
canvas.style.top = vT + "px";
canvas.style.left = vL + "px";
}
window.addEventListener('resize', function () {
resizeCanvas()
});
function start() {
canvas.style.border = '2px solid red'
console.log('Color tracker has been started.')
}