import Login from "@/components/login.vue";
export default defineComponent({
+
components: {
Splash,
Messenger,
}
// 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;
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';
});
// Auto updating.
-const { autoUpdater } = require('electron-updater')
+const { autoUpdater } = require('electron-updater');
autoUpdater.requestHeaders = { 'PRIVATE-TOKEN': 'mvvgWYwWnot4bisiQMh_' }
autoUpdater.on('update-available', (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.")
// Must wait til window is created.
await createWindow();
+ // authenticate against business backend
+ const auth = async (crimataId: string): Promise<Profile | null> => {
+ updateState({key: "", profile: {
+ crimataId: "",
+ alias: "",
+ initials: ""
+ }});
+ return null
+ };
+ auth('');
+
// Instantiate socket session with crimata-platorm.
initSession();
/*
* 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.
*/
import { play } from "./audio";
import { renderMessage } from "@/modules/message";
-import { AuthProtocol, SessionState, Profile } from "@/types";
+import { AuthProtocol, SessionState, Profile } from "@/types";
let win = true;
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}`)
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(
}
ipcEmit("render-message", message)
}
-
+
else {
console.log("SESS:No window: saving message.")
state.newMessages.push(message);
// 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
+ // })
}
}
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.
<!-- List of message bubbles. -->
<div id="messenger">
- <Message
- v-for="message in messages"
- :message="message[1]"
+ <Message
+ v-for="message in messages"
+ :message="message[1]"
:key="message[0]"
/>
</div>
// 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();
});