From: riqo Date: Sat, 22 May 2021 20:02:49 +0000 (-0500) Subject: remove auth from sesssion X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=fe954f296050ad8bef363d58fa5b66c4260fecf6;p=mime-chat remove auth from sesssion --- diff --git a/src/App.vue b/src/App.vue index 320b62f..86d1007 100644 --- a/src/App.vue +++ b/src/App.vue @@ -41,6 +41,7 @@ import Messenger from "@/components/messenger.vue"; import Login from "@/components/login.vue"; export default defineComponent({ + components: { Splash, Messenger, @@ -72,7 +73,8 @@ export default defineComponent({ } // Set profile and newMessages. - profile.value = payload.message.profile; + // profile.value = payload.message.profile; + profile.value = true; newMessages.value = payload.message.newMessages; ready.value = true; diff --git a/src/background/init.ts b/src/background/init.ts index a17716c..5150d9f 100644 --- a/src/background/init.ts +++ b/src/background/init.ts @@ -3,7 +3,7 @@ import { app, dialog } from "electron"; import { createWindow } from './window'; -import { initSession } from './session'; +import { initSession, updateState } from './session'; import { initAudioIO, stopStream } from './audio'; import { backgroundMitt } from '@/modules/emitter'; @@ -15,7 +15,7 @@ backgroundMitt.on('window-active', (state: boolean) => { }); // Auto updating. -const { autoUpdater } = require('electron-updater') +const { autoUpdater } = require('electron-updater'); autoUpdater.requestHeaders = { 'PRIVATE-TOKEN': 'mvvgWYwWnot4bisiQMh_' } autoUpdater.on('update-available', (info: any) => { @@ -38,6 +38,13 @@ autoUpdater.on('update-downloaded', (info: any) => { }) + +interface Profile { + crimataId: string; + alias: string; + initials: string; +} + // Run when electron app is initialized. async function main() { console.log("MAIN:Initializing Electron App.") @@ -45,6 +52,17 @@ async function main() { // Must wait til window is created. await createWindow(); + // authenticate against business backend + const auth = async (crimataId: string): Promise => { + updateState({key: "", profile: { + crimataId: "", + alias: "", + initials: "" + }}); + return null + }; + auth(''); + // Instantiate socket session with crimata-platorm. initSession(); diff --git a/src/background/session.ts b/src/background/session.ts index 35773c8..0a8b91d 100644 --- a/src/background/session.ts +++ b/src/background/session.ts @@ -1,10 +1,10 @@ /* * Creates a websocket session with Crimata Servers. - * - * Connects to Servers and attempts key authentication. Server will respond - * with key and user profile. We send the profile to the browser. We also - * resend this information on new broser window. We then serve as a - * communication interface between the window and the servers. It will + * + * Connects to Servers and attempts key authentication. Server will respond + * with key and user profile. We send the profile to the browser. We also + * resend this information on new broser window. We then serve as a + * communication interface between the window and the servers. It will * automatically try to reconnect on websocket disconnect. */ @@ -16,7 +16,7 @@ import useWebSockets from "@/modules/websockets"; import { play } from "./audio"; import { renderMessage } from "@/modules/message"; -import { AuthProtocol, SessionState, Profile } from "@/types"; +import { AuthProtocol, SessionState, Profile } from "@/types"; let win = true; @@ -27,7 +27,7 @@ let state: SessionState; let profile: Profile | boolean; // Called when server sends auth message. -const updateState = (res: AuthProtocol) => { +export const updateState = (res: AuthProtocol) => { console.log("SESS:Auth message received: \n" + ` key: ${res.key}\n` + ` alias: ${res.profile}`) @@ -71,12 +71,10 @@ const onMessage = (data: string) => { let message = JSON.parse(data) // AuthProtocol message. - if (message.hasOwnProperty("key")) { - updateState(message) - } + updateState(message) // Standard message. - else if (message.content) { + if (message.content) { // Convert to render message message = renderMessage( @@ -93,7 +91,7 @@ const onMessage = (data: string) => { } ipcEmit("render-message", message) } - + else { console.log("SESS:No window: saving message.") state.newMessages.push(message); @@ -110,14 +108,14 @@ const onMessage = (data: string) => { // When socket connects, we update state. const onOpen = () => { - console.log(`SESS:Sending key: ${state.key}`) + // console.log(`SESS:Sending key: ${state.key}`) if (state) { - sendMessage({ - "key": state.key, - "usr": false, - "pwd": false - }) + // sendMessage({ + // "key": state.key, + // "usr": false, + // "pwd": false + // }) } } @@ -128,12 +126,15 @@ const { createSocket, sendMessage } = useWebSockets(onMessage, onOpen); const onClientMessage = (_event: IpcMainEvent, payload: any) => { console.log("New client message") - const success = sendMessage(payload) + if (payload.hasOwnProperty("key")) { + return + } + const success = sendMessage(payload); if (!success) { - console.log("Unable to send message: ", payload) + console.log("Unable to send message: ", payload); } - + } // Call this to initialize session with Crimata servers. diff --git a/src/components/messenger.vue b/src/components/messenger.vue index edc50a1..f5512a9 100644 --- a/src/components/messenger.vue +++ b/src/components/messenger.vue @@ -6,9 +6,9 @@
-
@@ -48,25 +48,24 @@ export default defineComponent({ // Load the message history. if (crimataId === window.localStorage.getItem("last_usr")) { - prepMessageView(props.newMessages) + prepMessageView(props.newMessages); } else { - messages.value.clear() + messages.value.clear(); } // New content listeners. emitter.on('self-message', (message) => updateMessageView(message)); window.ipcRenderer.on("render-message", (_e: any, payload: any) => { - updateMessageView(payload.message) + updateMessageView(payload.message); }); // Save the usr for next time. - window.localStorage.setItem("last_usr", crimataId) + window.localStorage.setItem("last_usr", crimataId); }); onUnmounted(() => { window.ipcRenderer.removeAllListeners("render-message"); - window.ipcRenderer.removeAllListeners("annotate-message"); emitter.all.clear(); });