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');
conversationDiv.scrollTo(0, conversationDiv.scrollHeight);
},
typing(event: KeyboardEvent) {
async typing(event: KeyboardEvent) {
const { $io } = useNuxtApp();
const specialKeys = [
@@ -252,7 +252,7 @@ export default {
return;
}
$io.emit('typing', this.channel.id);
(await $io).emit('typing', this.channel.id);
},
mouseEnter() {
document.body.addEventListener('keydown', this.keyPressed, false);
@@ -344,12 +344,12 @@ export default {
this.search.show = false;
this.$refs.messageBox.focus();
},
listenToWebsocket(conversationDiv: HTMLElement) {
const { $io } = useNuxtApp();
async listenToWebsocket(conversationDiv: HTMLElement) {
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;
if (deleted) {
@@ -384,7 +384,7 @@ export default {
});
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;
clearTimeout(timeout);
timeout = setTimeout(() => {

View File

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

View File

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