discord-sandboxed/renderer.js
2019-10-14 17:35:25 -07:00

39 lines
1.3 KiB
JavaScript

const { ipcRenderer } = require('electron')
onload = () => {
const webview = document.querySelector('webview')
ipcRenderer.send('asynchronous-message', 'DOMready')
webview.addEventListener('console-message', (e) => {
if (e.message === "Constructed RTCPeerConnection") {
console.log("Connected to server")
ipcRenderer.send('asynchronous-message', 'connected')
}
if (e.message === "Close RTCPeerConnection") {
console.log("Disconnected from server")
ipcRenderer.send('asynchronous-message', 'disconnected')
}
})
ipcRenderer.on('ping', (event, msg) => {
if (msg === 'mic-open'){
console.log("talking")
webview.sendInputEvent({keyCode: 'Backspace', type: 'keyDown'});
webview.sendInputEvent({keyCode: 'Backspace', type: 'char'});
}
if (msg === 'mic-closed'){
console.log("not talking")
webview.sendInputEvent({keyCode: 'Backspace', type: 'keyUp'});
webview.sendInputEvent({keyCode: 'Backspace', type: 'char'});
}
})
ipcRenderer.on('devMode', (event, msg) => {
console.log(`Dev Mode: ${msg}`)
if (msg === true) {
webview.openDevTools()
}
})
}