recording timer, bux fixes, simplified emitter
This commit is contained in:
parent
ccb07d594b
commit
7de0555856
5 changed files with 30 additions and 16 deletions
21
src/audio.js
21
src/audio.js
|
|
@ -12,6 +12,8 @@ let outputDevice;
|
|||
let setWriteId;
|
||||
let setStreamsId;
|
||||
|
||||
let autoStopId; /* keep track of recording time */
|
||||
|
||||
let playbackId; /* UID of the message being played */
|
||||
|
||||
const streamState = { rec: false, pb: false };
|
||||
|
|
@ -24,7 +26,7 @@ backgroundMitt.on("data", (int16Arr) => {
|
|||
|
||||
backgroundMitt.on("write", (int16Arr) => {
|
||||
clearTimeout(setWriteId);
|
||||
setWriteId = setTimeout(() => setPlaybackStatus(false), 500);
|
||||
setWriteId = setTimeout(setPlaybackStatus.prototype.bind(null, false), 500);
|
||||
});
|
||||
|
||||
function setStreams()
|
||||
|
|
@ -47,8 +49,21 @@ function setStreams()
|
|||
}
|
||||
}
|
||||
|
||||
function startRecording()
|
||||
{
|
||||
setRecordingStatus(true);
|
||||
|
||||
/* 15s recording time limit */
|
||||
autoStopId = setTimeout(stopRecording, 15000);
|
||||
}
|
||||
|
||||
function stopRecording()
|
||||
{
|
||||
if (autoStopId)
|
||||
{
|
||||
clearTimeout(autoStopId);
|
||||
}
|
||||
|
||||
setRecordingStatus(false);
|
||||
|
||||
sendMessage({
|
||||
|
|
@ -65,7 +80,7 @@ function initAudio()
|
|||
setStreamsId = setInterval(setStreams, 2000);
|
||||
|
||||
const res = globalShortcut.register('CommandOrControl+Return', () => {
|
||||
streamState.rec ? stopRecording() : setRecordingStatus(true);
|
||||
streamState.rec ? stopRecording() : startRecording();
|
||||
});
|
||||
|
||||
if (!res) throw new Error("Failed to register recording shortcut");
|
||||
|
|
@ -103,6 +118,8 @@ function setRecordingStatus(status)
|
|||
|
||||
function setPlaybackStatus(status)
|
||||
{
|
||||
console.log("Setting playback status: ", status);
|
||||
|
||||
streamState.pb = status;
|
||||
ipcEmit("playback", playbackId, status);
|
||||
updateTray("playback", status);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ const Context =
|
|||
Vue.onMounted(() => {
|
||||
window.mainApi.on("playback", (id, status) => {
|
||||
if (id === props.id) {
|
||||
console.log(id, status);
|
||||
playback.value = status;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ function handleMessage()
|
|||
new Notification({title: message.context, body: message.content[message.content.length - 1]}).show();
|
||||
}
|
||||
|
||||
if (message.audio) playback(message.audio, message.id);
|
||||
|
||||
ipcEmit("ui-update", message);
|
||||
|
||||
if (message.audio) playback(message.audio, message.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
const EventEmitter = require('events');
|
||||
const EventEmitter = require("events");
|
||||
|
||||
class BackgroundMitt extends EventEmitter { }
|
||||
const backgroundMitt = new BackgroundMitt();
|
||||
const backgroundMitt = new EventEmitter();
|
||||
|
||||
const ipcEmit = (channel, payload) =>
|
||||
const ipcEmit = (channel, ...args) =>
|
||||
{
|
||||
backgroundMitt.emit('ipc-renderer', {
|
||||
channel,
|
||||
payload
|
||||
});
|
||||
backgroundMitt.emit("ipc-renderer", channel, ...args);
|
||||
};
|
||||
|
||||
module.exports.backgroundMitt = backgroundMitt;
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ function createWin()
|
|||
|
||||
.on("closed", () => {
|
||||
store.set("focus", false);
|
||||
backgroundMitt.removeAllListeners("ipc-renderer");
|
||||
win = null;
|
||||
})
|
||||
|
||||
|
|
@ -63,9 +62,10 @@ function createWin()
|
|||
|
||||
win.webContents.on("did-finish-load", () => {
|
||||
|
||||
/* Gateway to the frontend */
|
||||
backgroundMitt.on("ipc-renderer", (e) => {
|
||||
win.webContents.send(e.channel, e.payload);
|
||||
backgroundMitt.removeAllListeners("ipc-renderer");
|
||||
|
||||
backgroundMitt.on("ipc-renderer", (channel, ...args) => {
|
||||
win.webContents.send(channel, ...args);
|
||||
});
|
||||
|
||||
win.webContents.send("set-account", store.get("account"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue