# local env files
.env.local
.env.*.local
+.env
# Log files
npm-debug.log*
"animejs": "^3.2.0",
"axios": "^0.21.1",
"core-js": "^3.6.5",
+ "dotenv": "^10.0.0",
"electron-is-dev": "^2.0.0",
"electron-store": "^8.0.0",
"electron-updater": "^4.3.8",
export const fetchProfile = async(email: string, token: string) => (
await axios({
- url: "http://127.0.0.1:3010/api/account/profile",
+ url: "http://127.0.0.1:3000/api/account/profile",
headers: {
Cookie: `jwt=${token}`
},
"use strict";
-import { ipcMain } from "electron";
import { backgroundMitt } from '@/modules/emitter';
-
const portAudio = require('naudiodon');
// Audio in and out stream objects.
closeOnError: false,
}
-// Toggles record to true to begin capturing chunks.
-const onRecordingStart = (_event: any, _payload: any) => {
- console.log("AUDIO: Beginning audio capture.")
- record = true;
-}
+export const toggleRecord = (): void => { record = !record };
+
-// Returns recorded audio to frontend and sets record to false.
-const onRecordingEnd = async (_event: any, payload: any) => {
- console.log("AUDIO:Sending audio to browser.")
+export const fetchAudioInput = (): Promise<Error | string> => (
- return new Promise((resolve, reject) => {
+ new Promise((resolve, reject) => {
try {
resolve(audioContainer.input);
- record = false;
+ toggleRecord();
} catch (e) {
- reject()
+ reject(new Error('Failed to fetch the audio.'))
}
- });
-};
+ })
+)
// Main audio function run by run.ts module.
ao.start();
}
-
- // Listen to record.
- console.log("AUDIO:Adding recording listeners.")
-
- ipcMain.removeAllListeners("start-recording");
- ipcMain.on("start-recording", onRecordingStart);
-
- ipcMain.removeHandler("stop-recording");
- ipcMain.handle("stop-recording", onRecordingEnd);
}
"use strict";
-import { app, dialog, ipcMain, IpcMainInvokeEvent } from "electron";
+import { app, dialog } from "electron";
import { createWindow } from './window';
-import { initSession, onAppMounted } from './session';
-import { initAudioIO, stopStream } from './audio';
+import { stopStream } from './audio';
import { backgroundMitt } from '@/modules/emitter';
-import { initAccountListener } from "@/background/ipc/account";
+import useIpc from "@/background/ipc/index";
+const { autoUpdater } = require('electron-updater');
let win: boolean;
});
// Auto updating.
-const { autoUpdater } = require('electron-updater');
autoUpdater.requestHeaders = { 'PRIVATE-TOKEN': 'mvvgWYwWnot4bisiQMh_' }
autoUpdater.on('update-available', (info: any) => {
})
-const onSessionInit = (_event: IpcMainInvokeEvent, cid: string) => {
- // Instantiate socket session with crimata-platorm.
- initSession(cid);
-
- // Begin audio stream.
- initAudioIO();
-}
-
// Run when electron app is initialized.
async function main(): Promise<void> {
console.log("MAIN:Initializing Electron App.");
- // Attack browser window init listener.
- ipcMain.removeAllListeners("app-mounted");
- ipcMain.on("app-mounted", onAppMounted);
-
- ipcMain.removeAllListeners("init-session");
- ipcMain.on("init-session", onSessionInit);
-
- // handler user auth, login, and logout asynchrounously
- initAccountListener();
+ useIpc();
// Must wait til window is created.
await createWindow();
// On initial startup.
app.on("ready", () => {
- autoUpdater.checkForUpdates()
+ // autoUpdater.checkForUpdates()
main()
});
import { Profile } from "@/types";
import { submit, fetchProfile, logout } from "@/api/account";
-import { ipcMain } from "electron";
+import { ipcMain, IpcMainInvokeEvent } from "electron";
import { store } from "@/background/store";
};
-const onProfile = async (_event: any, _payload: string) => (
+const onProfile = async (_event: IpcMainInvokeEvent, _payload: string) => (
new Promise(async (resolve, reject) => {
+ console.log('[IPC]: user-profile');
// get jwt token and crimataId from store
const token = store.get('key');
)
-const onLogin = async (_event: any, payload: string) => (
+const onLogin = async (_event: IpcMainInvokeEvent, payload: string) => (
new Promise(async (resolve, reject) => {
+ console.log('[IPC]: user-login');
const account = JSON.parse(payload);
})
)
-const onLogout = async (_event: any, _payload: string) => (
+const onLogout = async (_event: IpcMainInvokeEvent, _payload: string) => (
new Promise(async (resolve, reject) => {
+ console.log('[IPC]: user-logout');
try {
// post logout to backend
)
-export const initAccountListener = () => {
+export default function useAccountListeners(): void {
ipcMain.removeHandler("user-profile");
ipcMain.handle("user-profile", onProfile);
--- /dev/null
+
+"use strict";
+
+import { ipcMain, IpcMainInvokeEvent, IpcMainEvent } from "electron";
+import { fetchAudioInput, toggleRecord } from "@/background/audio";
+
+
+// Toggles record to true to begin capturing chunks.
+const onRecordingStart = (
+ _event: IpcMainEvent,
+ _payload: null): void => {
+
+ console.log('[IPC]: start-recording');
+
+ toggleRecord();
+};
+
+
+// Returns recorded audio to frontend and sets record to false.
+const onRecordingStop = async (
+ _event: IpcMainInvokeEvent,
+ _payload: null
+): Promise<Error | string> => {
+
+ console.log('[IPC]: stop-recording');
+
+ return await fetchAudioInput()
+};
+
+
+export default function useAudioListeners(): void {
+
+ ipcMain.removeAllListeners("start-recording");
+ ipcMain.on("start-recording", onRecordingStart);
+
+ ipcMain.removeHandler("stop-recording");
+ ipcMain.handle("stop-recording", onRecordingStop);
+
+};
+
+"use strict";
+
+import useAccountListeners from "./account";
+import useSessionListeners from "./session";
+import useAudioListeners from "./audio";
+
+
+export default function useIpc(): void {
+
+ useAccountListeners();
+
+ useSessionListeners();
+
+ useAudioListeners();
+
+}
--- /dev/null
+
+"use strict";
+
+import { initSession, emitNewMessages, sendMessage } from '@/background/session';
+import { ipcMain, IpcMainInvokeEvent, IpcMainEvent } from "electron";
+import { initAudioIO } from "@/background/audio";
+
+
+// Instantiate socket session with crimata-platorm.
+const onSessionInit = (
+ _event: IpcMainInvokeEvent,
+ cid: string
+): void => {
+
+ console.log('[IPC]: init-session');
+
+ initSession(cid);
+
+ initAudioIO();
+}
+
+
+const onAppMounted = (
+ _event: IpcMainInvokeEvent,
+ _payload: any
+): void => {
+
+ console.log('[IPC]: app-mounted');
+
+ emitNewMessages()
+};
+
+
+// Handle messages from window/client.
+const onClientMessage = async (
+ _event: IpcMainEvent,
+ payload: Record<string, any>
+): Promise<void> => {
+
+ console.log('[IPC]: client-message');
+
+ sendMessage(payload);
+}
+
+
+export default function useSessionListeners(): void {
+
+ console.log('[IPC]: Init session listeners.');
+
+ // Attach listeners for frontend.
+ ipcMain.removeAllListeners("client-message");
+ ipcMain.on("client-message", onClientMessage);
+
+ // Attack browser window init listener.
+ ipcMain.removeAllListeners("app-mounted");
+ ipcMain.on("app-mounted", onAppMounted);
+
+ ipcMain.removeAllListeners("init-session");
+ ipcMain.on("init-session", onSessionInit);
+
+}
*/
import { backgroundMitt } from "@/modules/emitter";
-import { ipcEmit, loadState, saveToJson } from './helpers';
-import { ipcMain, IpcMainEvent, IpcMainInvokeEvent } from "electron";
+import { ipcEmit, loadState } from './helpers';
import useWebSockets from "./websockets";
// Info saved to json on quit (key, newMessages).
let state: SessionState;
-// Send state on new window.
-export const onAppMounted = (_event: IpcMainInvokeEvent, _payload: any) => {
-
- ipcEmit("update-state", {
- newMessages: state.newMessages,
- });
-
-}
// Calls appropriate endpoint for a server message.
-const onMessage = (data: string) => {
+const onMessage = (data: string): void => {
let message = JSON.parse(data);
console.log('received new message', message);
// Websockets module.
const { createSocket, send } = useWebSockets(onMessage);
-// Handle messages from window/client.
-const onClientMessage = async (_event: IpcMainEvent, payload: any): Promise<void> => {
- console.log("New client message")
- if (payload.hasOwnProperty("key")) {
- return
+export const emitNewMessages = (): void => {
+ if (state) {
+ ipcEmit("update-state", {
+ newMessages: state.newMessages,
+ });
}
+
+}
+
+
+export const sendMessage = (payload: Record<string, any>): void => {
try {
send(payload)
} catch(e) {
// Call this to initialize session with Crimata servers.
-export const initSession = (cid: string) => {
+export const initSession = (cid: string): void => {
console.log("SESS:Creating new session.")
// Load Json or createState.
// Open socket connection.
createSocket();
- // Attach listeners for frontend.
- ipcMain.removeAllListeners("client-message");
- ipcMain.on("client-message", onClientMessage);
-
// Keep win up-to-date.
backgroundMitt.on('window-active', (state: boolean) => {
win = state;
import axios, { AxiosRequestConfig } from 'axios';
-const baseURL = 'http://127.0.0.1:3010/api';
+const baseURL = 'http://127.0.0.1:3000/api';
interface Request {
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-5.1.0.tgz#3fbaf020bfd794884072ea26b1e9791d45a629f0"
integrity sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==
+dotenv@^10.0.0:
+ version "10.0.0"
+ resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
+ integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==
+
dotenv@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"