connect/disconnect test
This commit is contained in:
parent
08bbc24504
commit
e72ed16b63
27
main.js
27
main.js
@ -1,5 +1,5 @@
|
|||||||
// Modules to control application life and create native browser window
|
// Modules to control application life and create native browser window
|
||||||
const {app, BrowserWindow, ipcRenderer} = require('electron')
|
const {app, BrowserWindow, ipcMain} = require('electron')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// Keep a global reference of the window object, if you don't, the window will
|
||||||
@ -62,6 +62,7 @@ const win = require('win-audio')
|
|||||||
const microphone = win.mic
|
const microphone = win.mic
|
||||||
|
|
||||||
let isTalking = false
|
let isTalking = false
|
||||||
|
let isConnected = false
|
||||||
|
|
||||||
// Resolves the promise after 2 seconds
|
// Resolves the promise after 2 seconds
|
||||||
function muteDelay() {
|
function muteDelay() {
|
||||||
@ -74,6 +75,7 @@ function muteDelay() {
|
|||||||
|
|
||||||
// Globally mutes the Mic
|
// Globally mutes the Mic
|
||||||
function muteMic() {
|
function muteMic() {
|
||||||
|
if (isConnected === true) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (isTalking === false) {
|
if (isTalking === false) {
|
||||||
muteDelay().then(val => {
|
muteDelay().then(val => {
|
||||||
@ -88,9 +90,11 @@ function muteMic() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Globally unmutes the Mic
|
// Globally unmutes the Mic
|
||||||
function unmuteMic() {
|
function unmuteMic() {
|
||||||
|
if (isConnected === true) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.log("Talking")
|
console.log("Talking")
|
||||||
isTalking = true
|
isTalking = true
|
||||||
@ -100,16 +104,10 @@ function unmuteMic() {
|
|||||||
return resolve(true)
|
return resolve(true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app.on('ready', event => {
|
app.on('ready', event => {
|
||||||
ioHook.start();
|
ioHook.start();
|
||||||
|
|
||||||
console.log("Init Finished")
|
|
||||||
|
|
||||||
console.log("Muted")
|
|
||||||
microphone.mute();
|
|
||||||
mainWindow.webContents.send('ping', 'mic-closed')
|
|
||||||
mainWindow.setTitle("MUTED")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ioHook.on('mousedown', event => {
|
ioHook.on('mousedown', event => {
|
||||||
@ -124,3 +122,16 @@ ioHook.on('mouseup', event => {
|
|||||||
muteMic()
|
muteMic()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on('asynchronous-message', (event, arg) => {
|
||||||
|
if (arg === 'connected') {
|
||||||
|
isConnected = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === 'disconnected') {
|
||||||
|
isConnected = false
|
||||||
|
isTalking = false
|
||||||
|
microphone.unmute(); // Unmute mic
|
||||||
|
}
|
||||||
|
console.log(arg)
|
||||||
|
})
|
||||||
|
11
renderer.js
11
renderer.js
@ -1,20 +1,25 @@
|
|||||||
const unMuteSound = new Audio('./assets/unmute.mp3')
|
const unMuteSound = new Audio('./assets/unmute.mp3')
|
||||||
const muteSound = new Audio('./assets/mute.mp3')
|
const muteSound = new Audio('./assets/mute.mp3')
|
||||||
const ipc = require('electron').ipcRenderer;
|
|
||||||
|
const { ipcRenderer } = require('electron')
|
||||||
|
|
||||||
onload = () => {
|
onload = () => {
|
||||||
const webview = document.querySelector('webview')
|
const webview = document.querySelector('webview')
|
||||||
webview.openDevTools()
|
webview.openDevTools()
|
||||||
webview.addEventListener('console-message', (e) => {
|
webview.addEventListener('console-message', (e) => {
|
||||||
console.log('D: ', e.message)
|
if (e.message === "Constructed RTCPeerConnection") {
|
||||||
|
console.log("Connected to server")
|
||||||
|
ipcRenderer.send('asynchronous-message', 'connected')
|
||||||
|
}
|
||||||
|
|
||||||
if (e.message === "Close RTCPeerConnection") {
|
if (e.message === "Close RTCPeerConnection") {
|
||||||
console.log("Disconnected from server")
|
console.log("Disconnected from server")
|
||||||
|
ipcRenderer.send('asynchronous-message', 'disconnected')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
require('electron').ipcRenderer.on('ping', (event, message) => {
|
ipcRenderer.on('ping', (event, message) => {
|
||||||
if (message === 'mic-open'){
|
if (message === 'mic-open'){
|
||||||
console.log("mic is open")
|
console.log("mic is open")
|
||||||
unMuteSound.play()
|
unMuteSound.play()
|
||||||
|
Loading…
Reference in New Issue
Block a user