updated protocols
This commit is contained in:
parent
7283e3f6f9
commit
531a32a5a5
37 changed files with 682 additions and 650 deletions
|
|
@ -1,37 +1,28 @@
|
|||
|
||||
|
||||
|
||||
|
||||
// import useAudio from "@/audio";
|
||||
import Messages from "./messages";
|
||||
import { getProfile } from "./store";
|
||||
import UIState from "@/uiState";
|
||||
import { config } from "@/config";
|
||||
import useWebsockets from "./composables/useWebsockets";
|
||||
import {config} from "@/config";
|
||||
import { ipcEmit } from "@/composables/useEmitter";
|
||||
import { backgroundMitt, ipcEmit } from "@/composables/useEmitter";
|
||||
|
||||
/* start and stop audio functionality */
|
||||
// const { initAudio, closeAudio } = useAudio();
|
||||
// UI state
|
||||
let uiState = new UIState()
|
||||
|
||||
let messages: Messages;
|
||||
// let audio = new Audio();
|
||||
|
||||
|
||||
const onMessageCallback = (payload: string) => {
|
||||
|
||||
const message = JSON.parse(payload);
|
||||
|
||||
if (message === "CLOSE_AUTH_FAIL") {
|
||||
console.log("deauthenticating");
|
||||
if (payload === "CLOSE_AUTH_FAIL") {
|
||||
backgroundMitt.emit("close-auth-fail");
|
||||
return
|
||||
}
|
||||
|
||||
else if (message.header === "init") {
|
||||
messages = new Messages(message.body);
|
||||
}
|
||||
const message = JSON.parse(payload) as ClientProtocol;
|
||||
|
||||
else {
|
||||
if (messages) {
|
||||
messages.update(message.body);
|
||||
}
|
||||
}
|
||||
if (message.header === "init") {
|
||||
uiState.set(message.body as Init);
|
||||
} else uiState.update(message.body as Update);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -39,17 +30,6 @@ const connectionStatusCallback = (status: string) => {
|
|||
ipcEmit('set-connection-status', status);
|
||||
}
|
||||
|
||||
|
||||
export const updateAppState = (): void => {
|
||||
const profile = getProfile();
|
||||
|
||||
ipcEmit("set-profile", profile);
|
||||
|
||||
if (messages)
|
||||
messages.emit();
|
||||
|
||||
}
|
||||
|
||||
const statusOptions = {
|
||||
openMessage: "Connected",
|
||||
pongMessage: "Nominal",
|
||||
|
|
@ -63,14 +43,13 @@ const { connect, send, close } = useWebsockets(
|
|||
statusOptions
|
||||
);
|
||||
|
||||
/* send a message to the platform */
|
||||
export function sendMessage<Message>(message: Message): void {
|
||||
|
||||
/* socket send */
|
||||
send(message);
|
||||
|
||||
export const updateAppUI = (): void => {
|
||||
uiState.emit();
|
||||
}
|
||||
|
||||
export function sendMessage<Message>(message: Raw | Request): void {
|
||||
send(message);
|
||||
}
|
||||
|
||||
/* launch a new session (the main process for authenticated users) */
|
||||
export function launchSession(platformKey: string) {
|
||||
|
|
@ -78,16 +57,15 @@ export function launchSession(platformKey: string) {
|
|||
/* connect to the platform */
|
||||
connect(config.PLATFORM_URL, platformKey);
|
||||
|
||||
/* initialize the audio streams */
|
||||
// initAudio();
|
||||
// initialize the audio streams
|
||||
// audio.record();
|
||||
|
||||
}
|
||||
|
||||
|
||||
export function endSession() {
|
||||
|
||||
// closeAudio();
|
||||
|
||||
close();
|
||||
|
||||
uiState.reset();
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue