-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
86 lines (70 loc) · 2.17 KB
/
index.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
body,
html,
.container {
margin: 0;
width: 100vw;
height: 100vh;
-webkit-app-region: drag;
}
video {
width: 100%;
height: 100%;
object-fit: cover;
-webkit-app-region: drag;
transition: opacity 0.2s ease-in-out;
}
</style>
</head>
<body>
<div class="container">
<video id="preview" autoplay="true"></video>
</div>
</body>
<script>
const electron = require('electron');
const {ipcRenderer} = electron;
electron.remote.getCurrentWindow().setIgnoreMouseEvents(true, {forward: true});
const video = document.querySelector('#preview');
ipcRenderer.on('data', (_, {videoDeviceName, hoverOpacity, borderRadius}) => {
const css = `
video {
border-radius: ${borderRadius};
}
video:hover {
opacity: ${hoverOpacity};
}
`;
const style = document.createElement('style');
style.appendChild(document.createTextNode(css));
document.querySelector('head').appendChild(style);
navigator.mediaDevices.enumerateDevices().then(devices => {
const videoDevices = devices.filter(d => d.kind === 'videoinput');
const [defaultDevice] = videoDevices;
const device = (
videoDeviceName && videoDevices.find(d => d.label.includes(videoDeviceName))
) || defaultDevice;
if (!device) {
ipcRenderer.send('kap-camera-mount');
return;
}
const {deviceId} = device;
navigator.mediaDevices.getUserMedia({video: {deviceId}}).then(stream => {
video.srcObject = stream;
ipcRenderer.send('kap-camera-mount');
}).catch(() => ipcRenderer.send('kap-camera-mount'));
}).catch(() => ipcRenderer.send('kap-camera-mount'));
})
video.addEventListener('mouseenter', event => {
if (event.metaKey) {
electron.remote.getCurrentWindow().setIgnoreMouseEvents(false);
} else {
electron.remote.getCurrentWindow().setIgnoreMouseEvents(true, {forward: true});
}
});
</script>
</html>