trying to fix freeze bug
This commit is contained in:
parent
4a2bb7cb52
commit
c0b71a4a6f
7 changed files with 100 additions and 66 deletions
|
|
@ -4,8 +4,8 @@ import WebSocket from 'ws';
|
|||
import { backgroundMitt } from './emitter';
|
||||
import { ipcMain } from "electron";
|
||||
import { play } from './audio';
|
||||
import { UserCreds, ClientMessage } from "@/types/message/index";
|
||||
import { clientMessage } from '@/modules/message';
|
||||
import { UserCreds, ClientMessage, RenderMessage, Annotation } from "@/types/message/index";
|
||||
import { clientMessage, initRenderMessageFromString } from '@/modules/message';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
const ip = 'ws://127.0.0.1';
|
||||
|
|
@ -15,7 +15,7 @@ let socket: WebSocket;
|
|||
let success = false;
|
||||
let auth = false;
|
||||
|
||||
const onAuthSession = async (_event, payload: string | UserCreds | null): Promise<string> => {
|
||||
const onAuthSession = async (e: any, payload: string | UserCreds | null): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
console.log('authenticating...');
|
||||
|
|
@ -43,40 +43,43 @@ const onAuthSession = async (_event, payload: string | UserCreds | null): Promis
|
|||
});
|
||||
};
|
||||
|
||||
const onMessage = (message: string): void => {
|
||||
const onMessage = (message_str: string): void => {
|
||||
|
||||
while (!auth) {
|
||||
backgroundMitt.emit('auth-res', message);
|
||||
backgroundMitt.emit('auth-res', message_str);
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse the message.
|
||||
const m = JSON.parse(message);
|
||||
// Decode the message.
|
||||
const m = JSON.parse(message_str)
|
||||
let message: RenderMessage | Annotation;
|
||||
|
||||
// check to see if this is a Render Message.
|
||||
// Check to see if this is a Render Message.
|
||||
if (m.content) {
|
||||
message = initRenderMessageFromString(message_str)
|
||||
|
||||
// If there is audio, play it.
|
||||
if (m.content.audio) {
|
||||
// Play audio if any.
|
||||
if (message.content.audio) {
|
||||
const audioBytes = Buffer.from(m.content.audio as string, 'hex');
|
||||
m.content.audio = true;
|
||||
play(audioBytes);
|
||||
} else {
|
||||
m.content.audio = false;
|
||||
}
|
||||
|
||||
// if there is no unique id, add it.
|
||||
if(!m.uid) m.uid = uuidv4();
|
||||
}
|
||||
|
||||
else {
|
||||
message = m // Annotation
|
||||
}
|
||||
|
||||
// Send it to the frontend.
|
||||
backgroundMitt.emit('ipc-renderer', {
|
||||
endpoint: 'render-message',
|
||||
message: m
|
||||
message: message
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
const onClientMessage = (_event, payload: ClientMessage): void => {
|
||||
const onClientMessage = (e: any, payload: ClientMessage): void => {
|
||||
console.log('sending message');
|
||||
socket.send(JSON.stringify(payload));
|
||||
}
|
||||
|
|
@ -150,8 +153,7 @@ export function initSession(): void {
|
|||
}
|
||||
|
||||
|
||||
export function sendAudio(content: string, uid: string): void {
|
||||
const m = clientMessage("", content, uid);
|
||||
export function sendAudio(audio: string, uid: string): void {
|
||||
const m = clientMessage("", audio, uid);
|
||||
socket.send(JSON.stringify(m));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue