small bug fix with async socket

This commit is contained in:
Zoe
2023-04-24 20:42:33 -05:00
parent 54cd5b8654
commit a7c91b382a
3 changed files with 10 additions and 12 deletions

View File

@@ -235,7 +235,7 @@ export default {
if (!conversationDiv) throw new Error('wtf'); if (!conversationDiv) throw new Error('wtf');
conversationDiv.scrollTo(0, conversationDiv.scrollHeight); conversationDiv.scrollTo(0, conversationDiv.scrollHeight);
}, },
typing(event: KeyboardEvent) { async typing(event: KeyboardEvent) {
const { $io } = useNuxtApp(); const { $io } = useNuxtApp();
const specialKeys = [ const specialKeys = [
@@ -252,7 +252,7 @@ export default {
return; return;
} }
$io.emit('typing', this.channel.id); (await $io).emit('typing', this.channel.id);
}, },
mouseEnter() { mouseEnter() {
document.body.addEventListener('keydown', this.keyPressed, false); document.body.addEventListener('keydown', this.keyPressed, false);
@@ -344,14 +344,14 @@ export default {
this.search.show = false; this.search.show = false;
this.$refs.messageBox.focus(); this.$refs.messageBox.focus();
}, },
listenToWebsocket(conversationDiv: HTMLElement) { async listenToWebsocket(conversationDiv: HTMLElement) {
const { $io } = useNuxtApp(); let { $io } = useNuxtApp();
$io.removeAllListeners(); (await $io).removeAllListeners();
$io.on(`message-${this.channel.id}`, (ev: { message: IMessage, deleted?: boolean }) => { (await $io).on(`message-${this.channel.id}`, (ev: { message: IMessage, deleted?: boolean }) => {
let { message, deleted } = ev; let { message, deleted } = ev;
if (deleted) { if (deleted) {
useActiveStore().removeMessage(message.id); useActiveStore().removeMessage(message.id);
return; return;
@@ -384,7 +384,7 @@ export default {
}); });
let timeout: NodeJS.Timeout; let timeout: NodeJS.Timeout;
$io.on(`typing-${this.channel.id}`, (ev: string) => { (await $io).on(`typing-${this.channel.id}`, (ev: string) => {
if (ev === this.user?.username) return; if (ev === this.user?.username) return;
clearTimeout(timeout); clearTimeout(timeout);
timeout = setTimeout(() => { timeout = setTimeout(() => {

View File

@@ -75,10 +75,10 @@ export default {
} }
}; };
}, },
mounted() { async mounted() {
const { $io } = useNuxtApp(); const { $io } = useNuxtApp();
$io.on(`addChannel-${this.server.id}`, (ev) => { (await $io).on(`addChannel-${this.server.id}`, (ev) => {
const newChannel = ev as IChannel; const newChannel = ev as IChannel;
useServerStore().addChannel(this.server.id, newChannel); useServerStore().addChannel(this.server.id, newChannel);
}); });

View File

@@ -12,8 +12,6 @@ export default defineEventHandler(({ node }) => {
global.io.on('connection', async (socket: Socket) => { global.io.on('connection', async (socket: Socket) => {
const token = socket.handshake.auth.token; const token = socket.handshake.auth.token;
console.log(token);
if (!token) { if (!token) {
socket.disconnect(); socket.disconnect();
return; return;