forked from steveseguin/electroncapture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.js
54 lines (45 loc) · 1.53 KB
/
preload.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
const { ipcRenderer } = require('electron')
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type])
}
})
window.addEventListener('message', ({ data }) => {
ipcRenderer.send('postMessage', data)
})
ipcRenderer.on('postMessage', (event, ...args) => {
try{
if ("mic" in args[0]) { // this should work for the director's mic mute button as well. Needs to be manually enabled the first time still tho.
if (args[0].mic === true) { // unmute
session.muted = false; // set
toggleMute(true); // apply
} else if (args[0].mic === false) { // mute
session.muted = true; // set
toggleMute(true); // apply
} else if (args[0].mic === "toggle") { // toggle
toggleMute();
}
}
if ("getDeviceList" in args[0]) {
return enumerateDevices().then(function(deviceInfos) {
deviceInfos = JSON.parse(JSON.stringify(deviceInfos));
return ipcRenderer.send('deviceList', deviceInfos);
}).catch(console.error);;
}
if ("changeVideoDevice" in args[0]) {
changeVideoDeviceById(args[0].changeVideoDevice);
}
if ("changeAudioDevice" in args[0]) {
changeAudioDeviceById(args[0].changeAudioDevice);
}
if ("changeAudioOutputDevice" in args[0]) {
changeAudioOutputDeviceById(args[0].changeAudioOutputDevice);
}
}catch(e){
console.error(e);
}
})