beginnings of refactor
This commit is contained in:
parent
ac8f338d75
commit
3b5da6124f
63 changed files with 1697 additions and 2656 deletions
64
src/session.ts
Normal file
64
src/session.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
|
||||
|
||||
|
||||
|
||||
import useAudio from "@/audio";
|
||||
import { loadState, saveState, emitState } from "@/state";
|
||||
|
||||
/* start and stop audio functionality */
|
||||
const { initAudio, closeAudio } = useAudio();
|
||||
|
||||
/**
|
||||
* Controls for interfacing with the platform.
|
||||
* Takes an onMessage callback which we define below.
|
||||
*/
|
||||
const { connect, send, close } = usePlatform((message: Message) => {
|
||||
|
||||
/* add the message to the state */
|
||||
addMessage(message);
|
||||
|
||||
/* push the message to the browser */
|
||||
if (win) emit("new-message", message);
|
||||
|
||||
});
|
||||
|
||||
/* send a message to the platform */
|
||||
export function sendMessage(message: Message) {
|
||||
|
||||
/* add the message to the state */
|
||||
addMessage(message);
|
||||
|
||||
/* push the message to the browser */
|
||||
if (win) emit("new-message", message);
|
||||
|
||||
/* socket send */
|
||||
send(message);
|
||||
|
||||
}
|
||||
|
||||
/* launch a new session (the main process for authenticated users) */
|
||||
export function launchSession(profile: Profile) {
|
||||
|
||||
/* load any previously saved state for that user */
|
||||
loadState(profile);
|
||||
|
||||
/* connect to the platform */
|
||||
connect(profile);
|
||||
|
||||
/* initialize the audio streams */
|
||||
// initAudio();
|
||||
|
||||
/* finally we can push state to browser */
|
||||
if (win) emitState();
|
||||
|
||||
}
|
||||
|
||||
export function endSession() {
|
||||
|
||||
closeAudioStreams();
|
||||
|
||||
closeSocket();
|
||||
|
||||
state.clear();
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue