+/* eslint @typescript-eslint/no-var-requires: "off" */
+
+"use strict";
+
+// where the audio goes
+let buffer: ArrayBuffer[] = [];
+
+// place audio data in buffer
+export function collect (chunk: ArrayBuffer) {
+ buffer.push(chunk);
+}
+
+// return audio and clear buffer
+export function flush () {
+ const bufferCopy = buffer;
+ buffer = [];
+ return bufferCopy;
+}
+
+// import { backgroundMitt } from '@/modules/emitter';
+// const portAudio = require('naudiodon');
+
+// // Audio in and out stream objects.
+// let ai: typeof portAudio.AudioIO | boolean = false;
+// let ao: typeof portAudio.AudioIO | boolean = false;
+
+// // Whether activly recording.
+// let record = false;
+
+// const audioContainer = {
+// input: '',
+// }
+
+// const audioOptions = {
+// channelCount: 1,
+// sampleFormat: 16,
+// sampleRate: 16000,
+// deviceId: -1,
+// closeOnError: false,
+// }
+
+// export const toggleRecord = (): void => { record = !record };
+
+
+// export const fetchAudioInput = (): Promise<Error | string> => (
+
+// new Promise((resolve, reject) => {
+
+// try {
+// resolve(audioContainer.input);
+// toggleRecord();
+// } catch (e) {
+// reject(new Error('Failed to fetch the audio.'))
+// }
+
+// })
+// )
+
+
+// // Main audio function run by run.ts module.
+// export function initAudioIO(): void {
+// console.log("AUDIO:Starting io streams.")
+
+// if (!ai) {
+
+// // Initialize and start input stream.
+// ai = new portAudio.AudioIO({ inOptions: audioOptions });
+// ai.setEncoding("hex");
+// ai.start();
+
+// // On each data chunk...
+// ai.on('data', (chunk: string) => {
+
+// // If recording, we capture the data.
+// if (record) {
+// console.log('AUDIO:Recording...')
+// audioContainer.input += chunk;
+// }
+
+// // Else, we don't capture and also clear audioContainer.
+// else {
+// if (audioContainer.input.length) {
+// audioContainer.input = "";
+// }
+// }
+
+// });
+// }
+
+// if (!ao) {
+
+// // Initialize and start input stream.
+// ao = new portAudio.AudioIO({ outOptions: audioOptions });
+// ao.start();
+
+// }
+// }
+
+
+// // ---Audio playback--------------------------------------------
+
+// // Split Buffer into an array of len-sized Buffers.
+// function bufSplit(buf: Buffer, len: number): Array<Buffer> {
+// const chunks = [];
+// let i = 0;
+// let L = len;
+
+// while(i < buf.byteLength) {
+// chunks.push(buf.slice(i, L));
+// i = L;
+// L += len;
+// }
+
+// return chunks;
+// }
+
+// // Audio playback.
+// export function play(input: string): void {
+
+// // Format the audio.
+// const audio = bufSplit(
+// Buffer.from(input as string, 'hex'),
+// 8192
+// );
+
+// // Called on end of write.
+// const callback = () => {
+
+// // We stop audio playback anim.
+// backgroundMitt.emit('ipc-renderer', {
+// endpoint: 'stop-playback-anim'
+// });
+
+// }
+
+// write();
+
+// // Iterate through audio array and write buffers to portAudio writable.
+// function write() {
+// let chunk: Buffer;
+// let ok = true;
+// let i = 0;
+
+// do {
+// chunk = audio[i];
+// if (i === audio.length - 1) {
+// // write last chunk.
+// ao.write(chunk, null, callback);
+// } else {
+// // check for backpreassure.
+// ok = ao.write(chunk, null);
+// }
+// i++;
+// } while (i < audio.length && ok);
+
+// if (i < audio.length) {
+// // Had to stop early!
+// // Write some more once it drains.
+// ao.once('drain', write);
+// }
+// }
+// }
+
+// // -------------------------------------------------------------
+
+// // Get's called on window close.
+// export async function stopStream() {
+// console.log("AUDIO:Stopping audio stream.")
+// if (ai) {
+// try {
+// await ai.quit()
+// } catch(e){
+// console.log('AUDIO: Failed to shutdown audio input.');
+// throw e;
+// }
+// }
+// if (ao) {
+// try {
+// await ao.quit()
+// } catch(e){
+// console.log('AUDIO: Failed to shutdown audio output.');
+// throw e;
+// }
+// }
+// }
+
+
+++ /dev/null
-/* eslint @typescript-eslint/no-var-requires: "off" */
-
-"use strict";
-
-// where the audio goes
-let buffer: ArrayBuffer[] = [];
-
-// place audio data in buffer
-export function collect (chunk: ArrayBuffer) {
- buffer.push(chunk);
-}
-
-// return audio and clear buffer
-export function flush () {
- const bufferCopy = buffer;
- buffer = [];
- return bufferCopy;
-}
-
-// import { backgroundMitt } from '@/modules/emitter';
-// const portAudio = require('naudiodon');
-
-// // Audio in and out stream objects.
-// let ai: typeof portAudio.AudioIO | boolean = false;
-// let ao: typeof portAudio.AudioIO | boolean = false;
-
-// // Whether activly recording.
-// let record = false;
-
-// const audioContainer = {
-// input: '',
-// }
-
-// const audioOptions = {
-// channelCount: 1,
-// sampleFormat: 16,
-// sampleRate: 16000,
-// deviceId: -1,
-// closeOnError: false,
-// }
-
-// export const toggleRecord = (): void => { record = !record };
-
-
-// export const fetchAudioInput = (): Promise<Error | string> => (
-
-// new Promise((resolve, reject) => {
-
-// try {
-// resolve(audioContainer.input);
-// toggleRecord();
-// } catch (e) {
-// reject(new Error('Failed to fetch the audio.'))
-// }
-
-// })
-// )
-
-
-// // Main audio function run by run.ts module.
-// export function initAudioIO(): void {
-// console.log("AUDIO:Starting io streams.")
-
-// if (!ai) {
-
-// // Initialize and start input stream.
-// ai = new portAudio.AudioIO({ inOptions: audioOptions });
-// ai.setEncoding("hex");
-// ai.start();
-
-// // On each data chunk...
-// ai.on('data', (chunk: string) => {
-
-// // If recording, we capture the data.
-// if (record) {
-// console.log('AUDIO:Recording...')
-// audioContainer.input += chunk;
-// }
-
-// // Else, we don't capture and also clear audioContainer.
-// else {
-// if (audioContainer.input.length) {
-// audioContainer.input = "";
-// }
-// }
-
-// });
-// }
-
-// if (!ao) {
-
-// // Initialize and start input stream.
-// ao = new portAudio.AudioIO({ outOptions: audioOptions });
-// ao.start();
-
-// }
-// }
-
-
-// // ---Audio playback--------------------------------------------
-
-// // Split Buffer into an array of len-sized Buffers.
-// function bufSplit(buf: Buffer, len: number): Array<Buffer> {
-// const chunks = [];
-// let i = 0;
-// let L = len;
-
-// while(i < buf.byteLength) {
-// chunks.push(buf.slice(i, L));
-// i = L;
-// L += len;
-// }
-
-// return chunks;
-// }
-
-// // Audio playback.
-// export function play(input: string): void {
-
-// // Format the audio.
-// const audio = bufSplit(
-// Buffer.from(input as string, 'hex'),
-// 8192
-// );
-
-// // Called on end of write.
-// const callback = () => {
-
-// // We stop audio playback anim.
-// backgroundMitt.emit('ipc-renderer', {
-// endpoint: 'stop-playback-anim'
-// });
-
-// }
-
-// write();
-
-// // Iterate through audio array and write buffers to portAudio writable.
-// function write() {
-// let chunk: Buffer;
-// let ok = true;
-// let i = 0;
-
-// do {
-// chunk = audio[i];
-// if (i === audio.length - 1) {
-// // write last chunk.
-// ao.write(chunk, null, callback);
-// } else {
-// // check for backpreassure.
-// ok = ao.write(chunk, null);
-// }
-// i++;
-// } while (i < audio.length && ok);
-
-// if (i < audio.length) {
-// // Had to stop early!
-// // Write some more once it drains.
-// ao.once('drain', write);
-// }
-// }
-// }
-
-// // -------------------------------------------------------------
-
-// // Get's called on window close.
-// export async function stopStream() {
-// console.log("AUDIO:Stopping audio stream.")
-// if (ai) {
-// try {
-// await ai.quit()
-// } catch(e){
-// console.log('AUDIO: Failed to shutdown audio input.');
-// throw e;
-// }
-// }
-// if (ao) {
-// try {
-// await ao.quit()
-// } catch(e){
-// console.log('AUDIO: Failed to shutdown audio output.');
-// throw e;
-// }
-// }
-// }
-
-
import { ref } from 'vue';
import useScroll from "@/render/composables/scroll";
-const canvas = ref();
+const messagesRef = ref();
/* seed the canvas with messages */
const seedCanvas = (messages: Message[]) => {
- canvas.value = messages;
+ messagesRef.value = messages;
}
const addMessage = (message: Message) => {
- canvas.value.push(message);
+ messagesRef.value.push(message);
}
const updateMessage = (message: Message) => {
- let target_message = canvas.value.filter((m: Message) => {
+ let target_message = messagesRef.value.filter((m: Message) => {
return m.uid = message.uid;
})[0];
const { updateScrollRef, adjustScroll } = useScroll("messenger");
return {
- canvas,
+ messagesRef,
seedCanvas,
addMessage,
updateMessage
};
-}
\ No newline at end of file
+}
<!-- List of message bubbles. -->
<div id="messenger">
<Bubble
- v-for="message in messages"
+ v-for="message in messagesRef"
:text="message.text"
:context="message.context"
- :child
:key="message[0]"
/>
</div>
import Message from "@/render/components/message.vue";
import InputItem from "@/render/components/inputItem.vue";
import Settings from "@/render/components/settings.vue";
-import useMessages from "@/render/composables/messages";
+import useMessages from "./controllers/messenger.control";
export default defineComponent({
name: "Messenger",
setup(props) {
// Handle messages in view.
- const { messages, updateMessageView } = useMessages();
+ const { messagesRef, updateMessageView } = useMessages();
onMounted(() => {
/* seed messages */
window.ipcRenderer.on("init-messages", (e_: any, payload: any) => {
- seedMessages(payload.messages);
+ // seedMessages(payload.messages);
});
/* add a new message */
window.ipcRenderer.on("add-message", (_e: any, payload: any) => {
- addMessage(payload.message);
+ // addMessage(payload.message);
});
/* update an existing message */
window.ipcRenderer.on("update-message", (_e: any, payload: any) => {
- updateMessage(payload.message);
+ // updateMessage(payload.message);
});
});
});
return {
- messages
+ messagesRef
};
},
import { useIpc } from "@/modules/ipc";
import { logoutRequest } from '@/modules/message';
import { useProfile } from "@/modules/auth"
- import { invokeLogout } from "@/ipcRend/account";
+ import { invokeLogout } from "@/render/ipc";
export default defineComponent({
name: "Settings",
--- /dev/null
+
+// src/main.ts
+
+import App from "./App.vue";
+
+import mitt from "mitt";
+import { createApp } from "vue";
+
+
+// Handle events.
+const emitter = mitt();
+
+const app = createApp(App)
+
+app.provide("mitt", emitter)
+app.mount("#app");