working protocols
This commit is contained in:
parent
dd91a9ae9e
commit
a791f973dc
8 changed files with 114 additions and 109 deletions
|
|
@ -1,10 +1,9 @@
|
||||||
|
|
||||||
import { postAuth, postLogin, postLogout } from "@/api/account";
|
import { postAuth, postLogin, postLogout } from "@/api/account";
|
||||||
import { endSession, launchSession } from "@/session";
|
import { endSession, launchSession } from "@/session";
|
||||||
import { getToken, setToken, setProfile, getProfile, clearStore } from "./store";
|
import { getToken, setToken, setProfile, clearStore } from "./store";
|
||||||
import { parseAuthRes } from "./auth";
|
import { parseAuthRes } from "./auth";
|
||||||
import { ipcEmit } from "@/composables/useEmitter";
|
import { ipcEmit } from "@/composables/useEmitter";
|
||||||
import { messages } from "@/messages";
|
|
||||||
|
|
||||||
export const accountAuth = async (): Promise<Error | AuthState> => {
|
export const accountAuth = async (): Promise<Error | AuthState> => {
|
||||||
|
|
||||||
|
|
@ -84,13 +83,4 @@ export const accountLogout = async (): Promise<Error | void> => {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateAppState = (): void => {
|
|
||||||
|
|
||||||
const profile = getProfile();
|
|
||||||
|
|
||||||
ipcEmit("set-profile", profile);
|
|
||||||
|
|
||||||
ipcEmit("init-messages", messages)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
import { IpcListener } from "@/composables/useIpcMain"
|
import { IpcListener } from "@/composables/useIpcMain"
|
||||||
import { sendMessage } from '@/session';
|
import { sendMessage } from '@/session';
|
||||||
import { collect } from "@/audio";
|
import { collect } from "@/audio";
|
||||||
import { updateAppState } from "@/account";
|
import { updateAppState } from "@/session";
|
||||||
import { onNavBar } from "@/window";
|
import { onNavBar } from "@/window";
|
||||||
|
|
||||||
const CLIENT_MESSAGE_CHANNEL = "post-session-send"
|
const CLIENT_MESSAGE_CHANNEL = "post-session-send"
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import initIpcMain from "@/ipc/index";
|
import initIpcMain from "@/ipc/index";
|
||||||
import { accountAuth, updateAppState } from "./account";
|
import { accountAuth } from "./account";
|
||||||
import { launchSession } from "./session";
|
import { launchSession, updateAppState } from "./session";
|
||||||
import createWindow from "./window";
|
import createWindow from "./window";
|
||||||
|
|
||||||
let authState: AuthState | null;
|
let authState: AuthState | null;
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,67 @@
|
||||||
import { ipcEmit } from "@/composables/useEmitter";
|
import { ipcEmit } from "@/composables/useEmitter";
|
||||||
|
|
||||||
export let messages: Message[] = [];
|
export default class Messages {
|
||||||
|
|
||||||
export const setMessages = (init: {messages: Message[]}) => {
|
messages: Message[];
|
||||||
console.log("setMessages", init);
|
|
||||||
messages = init.messages;
|
|
||||||
ipcEmit("init-messages", messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const newMessage = (message: Message) => {
|
constructor(messages: Message[]) {
|
||||||
console.log("newMessage", message);
|
console.log(messages);
|
||||||
messages.push(message);
|
this.messages = messages;
|
||||||
ipcEmit("add-message", message);
|
this.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
export const annotateMessage = (annotation: Annotation) => {
|
emit() {
|
||||||
console.log("annotateMessage", annotation);
|
ipcEmit("init-messages", this.messages);
|
||||||
|
}
|
||||||
|
|
||||||
for (let i in messages) {
|
update(update: Update) {
|
||||||
|
|
||||||
if (messages[i].uid == annotation.uid) {
|
if (update.name === "add") {
|
||||||
|
this.messages.push(update.data as Message);
|
||||||
|
ipcEmit("add-message", update.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (update.name === "annotate") {
|
||||||
|
this._annotate(update.data as Annotation);
|
||||||
|
ipcEmit("update-message", update.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
this._delete(update.data as string);
|
||||||
|
ipcEmit("delete-message", update.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_annotate(annotation: Annotation) {
|
||||||
|
|
||||||
|
for (let i in this.messages) {
|
||||||
|
|
||||||
|
if (this.messages[i].uid == annotation.uid) {
|
||||||
|
|
||||||
|
if (annotation.name == "content") {
|
||||||
|
this.messages[i].content = annotation.data as string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (annotation.name == "context") {
|
||||||
|
this.messages[i].context = annotation.data as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
ipcEmit("update-message", annotation);
|
||||||
|
|
||||||
if (annotation.data.hasOwnProperty("content")) {
|
|
||||||
const data = annotation.data as ContentData;
|
|
||||||
messages[i].content = data.content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (annotation.data.hasOwnProperty("context")) {
|
|
||||||
const data = annotation.data as ContextData;
|
|
||||||
messages[i].context = data.context;
|
|
||||||
}
|
|
||||||
|
|
||||||
ipcEmit("update-message", annotation);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_delete(uid: string) {
|
||||||
|
for (var i = 0; i < this.messages.length; i++) {
|
||||||
|
if (this.messages[i].uid === uid) {
|
||||||
|
this.messages.splice(i, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,7 @@ import { IpcRendererListener } from "./composables/useIpcRend"
|
||||||
* Shared state imports
|
* Shared state imports
|
||||||
* */
|
* */
|
||||||
import { setProfile } from "./shared/profile";
|
import { setProfile } from "./shared/profile";
|
||||||
import { setMessages, addMessage, updateMessage } from "./shared/messages";
|
import { setMessages, addMessage, updateMessage, deleteMessage } from "./shared/messages";
|
||||||
import { setConnectionStatus } from "./shared/connectionStatus";
|
import { setConnectionStatus } from "./shared/connectionStatus";
|
||||||
|
|
||||||
const SET_PROFILE_CHANNEL = "set-profile";
|
const SET_PROFILE_CHANNEL = "set-profile";
|
||||||
|
|
@ -12,6 +12,7 @@ const SET_PROFILE_CHANNEL = "set-profile";
|
||||||
const INIT_MESSAGES_CHANNEL = "init-messages";
|
const INIT_MESSAGES_CHANNEL = "init-messages";
|
||||||
const ADD_MESSAGE_CHANNEL = "add-message";
|
const ADD_MESSAGE_CHANNEL = "add-message";
|
||||||
const UPDATE_MESSAGE_CHANNEL = "update-message";
|
const UPDATE_MESSAGE_CHANNEL = "update-message";
|
||||||
|
const DELETE_MESSAGE_CHANNEL = "delete-message";
|
||||||
const CONNECTION_STATUS_CHANNEL = "set-connection-status";
|
const CONNECTION_STATUS_CHANNEL = "set-connection-status";
|
||||||
|
|
||||||
export const setProfileListener = new IpcRendererListener({
|
export const setProfileListener = new IpcRendererListener({
|
||||||
|
|
@ -35,6 +36,11 @@ export const updateMessagesListener = new IpcRendererListener({
|
||||||
listenerCallback: updateMessage
|
listenerCallback: updateMessage
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const deleteMessagesListener = new IpcRendererListener({
|
||||||
|
channel: DELETE_MESSAGE_CHANNEL,
|
||||||
|
listenerCallback: deleteMessage
|
||||||
|
});
|
||||||
|
|
||||||
export const connectionStatusListener = new IpcRendererListener({
|
export const connectionStatusListener = new IpcRendererListener({
|
||||||
channel: CONNECTION_STATUS_CHANNEL,
|
channel: CONNECTION_STATUS_CHANNEL,
|
||||||
listenerCallback: setConnectionStatus
|
listenerCallback: setConnectionStatus
|
||||||
|
|
|
||||||
|
|
@ -5,55 +5,46 @@ import useScroll from "@/render/composables/useScroll";
|
||||||
export const messages: Ref<Array<Message>> = ref([]);
|
export const messages: Ref<Array<Message>> = ref([]);
|
||||||
|
|
||||||
export const setMessages: IpcListenerCallback<Array<Message>> = (payload) => {
|
export const setMessages: IpcListenerCallback<Array<Message>> = (payload) => {
|
||||||
console.log("setMessages", payload);
|
|
||||||
messages.value = payload as Array<Message>;
|
messages.value = payload as Array<Message>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const addMessage: IpcListenerCallback<Message> = (payload) => {
|
export const addMessage: IpcListenerCallback<Message> = (payload) => {
|
||||||
console.log("addMessage", payload);
|
|
||||||
messages.value.push(payload as Message);
|
messages.value.push(payload as Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateMessage: IpcListenerCallback<Annotation> = (payload) => {
|
export const updateMessage: IpcListenerCallback<Annotation> = (payload) => {
|
||||||
console.log("updateMessage", payload);
|
|
||||||
const annotation = payload as Annotation;
|
const annotation = payload as Annotation;
|
||||||
|
|
||||||
/* find the target message */
|
for (let i in messages.value) {
|
||||||
let targetMessage = messages.value.filter((m: Message) => {
|
|
||||||
return m.uid === annotation.uid;
|
|
||||||
})[0];
|
|
||||||
|
|
||||||
if (targetMessage) {
|
if (messages.value[i].uid == annotation.uid) {
|
||||||
|
|
||||||
/* update the content (add a new bubble) */
|
if (annotation.name == "content") {
|
||||||
if (annotation.data.hasOwnProperty("content")) {
|
messages.value[i].content = annotation.data as string[];
|
||||||
const data = annotation.data as ContentData;
|
}
|
||||||
targetMessage.content = data.content;
|
|
||||||
}
|
if (annotation.name == "context") {
|
||||||
|
messages.value[i].context = annotation.data as string;
|
||||||
|
}
|
||||||
|
|
||||||
/* and/or update the context */
|
|
||||||
if (annotation.data.hasOwnProperty("context")) {
|
|
||||||
const data = annotation.data as ContextData;
|
|
||||||
targetMessage.context = data.context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// messages.value = [
|
export const deleteMessage: IpcListenerCallback<string> = (payload) => {
|
||||||
// {
|
const uid = payload as string;
|
||||||
// content: ["Welcome Andrew"],
|
|
||||||
// context: "Crimata",
|
for (var i = 0; i < messages.value.length; i++) {
|
||||||
// modifier: "ai",
|
if (messages.value[i].uid === uid) {
|
||||||
// uid: "b5dd3d1b-cef0-4057-aa0f-c72e5c4cd67d"
|
messages.value.splice(i, 1);
|
||||||
// },
|
break;
|
||||||
// {
|
}
|
||||||
// content: ["show contacts"],
|
}
|
||||||
// context: "false",
|
|
||||||
// modifier: "client",
|
}
|
||||||
// uid: "ee2819a3-1125-4881-9942-ca5b3d0ad502"
|
|
||||||
// }]
|
|
||||||
|
|
||||||
// setTimeout(() => {
|
// setTimeout(() => {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,52 +3,34 @@
|
||||||
|
|
||||||
|
|
||||||
// import useAudio from "@/audio";
|
// import useAudio from "@/audio";
|
||||||
import { setMessages, newMessage, annotateMessage } from "./messages";
|
import Messages from "./messages";
|
||||||
|
import { getProfile } from "./store";
|
||||||
import useWebsockets from "./composables/useWebsockets";
|
import useWebsockets from "./composables/useWebsockets";
|
||||||
import {config} from "@/config";
|
import {config} from "@/config";
|
||||||
|
import { ipcEmit } from "@/composables/useEmitter";
|
||||||
|
|
||||||
/* start and stop audio functionality */
|
/* start and stop audio functionality */
|
||||||
// const { initAudio, closeAudio } = useAudio();
|
// const { initAudio, closeAudio } = useAudio();
|
||||||
|
|
||||||
const isInitMessage = (object: any): object is Message[] => {
|
let messages: Messages;
|
||||||
return 'messages' in object;
|
|
||||||
};
|
|
||||||
|
|
||||||
const isNewMessage = (object: any): object is Message => {
|
|
||||||
return 'content' in object;
|
|
||||||
};
|
|
||||||
|
|
||||||
const isAnnotation = (object: any): object is Annotation => {
|
|
||||||
return 'uid' in object;
|
|
||||||
};
|
|
||||||
|
|
||||||
const deauthenticate = (): void => {
|
|
||||||
console.log('deauthenticating')
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Controls for interfacing with the platform.
|
|
||||||
* Takes an onMessage callback which we define below.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const onMessageCallback = (payload: string) => {
|
const onMessageCallback = (payload: string) => {
|
||||||
|
|
||||||
const message = JSON.parse(payload);
|
const message = JSON.parse(payload);
|
||||||
|
|
||||||
if (message === "CLOSE_AUTH_FAIL") {
|
if (message === "CLOSE_AUTH_FAIL") {
|
||||||
deauthenticate();
|
console.log("deauthenticating");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (isInitMessage(message)) {
|
else if (message.header === "init") {
|
||||||
setMessages(message);
|
messages = new Messages(message.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (isNewMessage(message)) {
|
else {
|
||||||
newMessage(message);
|
if (messages) {
|
||||||
}
|
messages.update(message.body);
|
||||||
|
}
|
||||||
else if (isAnnotation(message)) {
|
|
||||||
annotateMessage(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -57,6 +39,17 @@ const connectionStatusCallback = (status: string) => {
|
||||||
ipcEmit('set-connection-status', status);
|
ipcEmit('set-connection-status', status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const updateAppState = (): void => {
|
||||||
|
const profile = getProfile();
|
||||||
|
|
||||||
|
ipcEmit("set-profile", profile);
|
||||||
|
|
||||||
|
if (messages)
|
||||||
|
messages.emit();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const statusOptions = {
|
const statusOptions = {
|
||||||
openMessage: "Connected",
|
openMessage: "Connected",
|
||||||
pongMessage: "Nominal",
|
pongMessage: "Nominal",
|
||||||
|
|
|
||||||
16
src/types.ts
16
src/types.ts
|
|
@ -1,4 +1,9 @@
|
||||||
|
|
||||||
|
interface Update {
|
||||||
|
name: string;
|
||||||
|
data: Message[] | Message | Annotation | string;
|
||||||
|
}
|
||||||
|
|
||||||
interface Message {
|
interface Message {
|
||||||
modifier: string;
|
modifier: string;
|
||||||
content: string[];
|
content: string[];
|
||||||
|
|
@ -6,16 +11,9 @@ interface Message {
|
||||||
uid: string;
|
uid: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ContentData {
|
|
||||||
content: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ContextData {
|
|
||||||
context: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Annotation {
|
interface Annotation {
|
||||||
data: ContentData | ContextData;
|
name: string;
|
||||||
|
data: string | string[];
|
||||||
uid: string;
|
uid: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue