From b6ec0312d5ec29fa32d552bb2a172b64aa260f0b Mon Sep 17 00:00:00 2001 From: April Hall Date: Thu, 6 Feb 2025 23:54:32 -0500 Subject: [PATCH] fix: Update prodServer.ts to match websocketConfig.ts --- prodServer.ts | 10 ++++++++-- src/lib/functions/websocketConfig.ts | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/prodServer.ts b/prodServer.ts index 122b7d9..e66c47b 100644 --- a/prodServer.ts +++ b/prodServer.ts @@ -18,14 +18,20 @@ io.on('connection', async (socket) => { if (msg.content !== '') { console.log(`\x1b[35m[ws:kit]\x1b[0m message from ${socket.id}: ${msg.content}`); // Store the message in the database - await db.sendMessage('000', msg.content, msg.id, uuidv4()); + await db.sendMessage(msg.channel, msg.content, msg.id, uuidv4()); io!.emit('message', { user: msg.id, message: msg.content, - imageSrc: 'https://www.arithefirst.com/images/pfp.png', + imageSrc: `https://api.dicebear.com/9.x/identicon/svg?seed=${msg.id}`, + channel: msg.channel, }); } }); + + // Runs on client disconnect + socket.on('disconnect', () => { + console.log(`\x1b[35m[ws:kit]\x1b[0m client disconnected (${socket.id})`); + }); }); app.use((req, res, next) => { diff --git a/src/lib/functions/websocketConfig.ts b/src/lib/functions/websocketConfig.ts index ab2f4bf..538e644 100644 --- a/src/lib/functions/websocketConfig.ts +++ b/src/lib/functions/websocketConfig.ts @@ -2,7 +2,7 @@ import { Server as SocketIOServer } from 'socket.io'; import type { HttpServer } from 'vite'; // Don't try to replace with $lib alias. Since this // file gets loaded as a vite plugin, it will crash -import { db } from '$lib/server/db'; +import { db } from '../server/db'; import { v4 as uuidv4 } from 'uuid'; let io: SocketIOServer | undefined;