feat: Colored [ws:kit] kit logging
This commit is contained in:
parent
0efb8d7c31
commit
9c8d0b6cb0
@ -2,7 +2,7 @@ import { handler } from './build/handler.js';
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import { createServer } from 'http';
|
import { createServer } from 'http';
|
||||||
import { Server } from 'socket.io';
|
import { Server } from 'socket.io';
|
||||||
import { client, createChannel, storeMessage } from './src/lib/server/db';
|
import { db } from './src/lib/server/db';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@ -11,15 +11,14 @@ const io = new Server(server);
|
|||||||
|
|
||||||
io.on('connection', async (socket) => {
|
io.on('connection', async (socket) => {
|
||||||
// Runs on client connection
|
// Runs on client connection
|
||||||
console.log(`[ws:kit] client connected (${socket.id})`);
|
console.log(`\x1b[35m[ws:kit]\x1b[0m client connected (${socket.id})`);
|
||||||
// Runs on message received
|
// Runs on message received
|
||||||
socket.on('message', async (msg) => {
|
socket.on('message', async (msg) => {
|
||||||
// If message not empty
|
// If message not empty
|
||||||
if (msg.content !== '') {
|
if (msg.content !== '') {
|
||||||
console.log(`[ws:kit] message from ${socket.id}: ${msg.content}`);
|
console.log(`\x1b[35m[ws:kit]\x1b[0m message from ${socket.id}: ${msg.content}`);
|
||||||
// Store the message in the database
|
// Store the message in the database
|
||||||
await createChannel(client, '000');
|
await db.sendMessage('000', msg.content, msg.id, uuidv4());
|
||||||
await storeMessage(client, '000', msg.content, msg.id, uuidv4());
|
|
||||||
io!.emit('message', {
|
io!.emit('message', {
|
||||||
user: msg.id,
|
user: msg.id,
|
||||||
message: msg.content,
|
message: msg.content,
|
||||||
|
@ -9,17 +9,17 @@ let io: SocketIOServer | undefined;
|
|||||||
|
|
||||||
export function startupSocketIOServer(httpServer: HttpServer | null) {
|
export function startupSocketIOServer(httpServer: HttpServer | null) {
|
||||||
if (io) return;
|
if (io) return;
|
||||||
console.log('[ws:kit] setup');
|
console.log('\x1b[35m[ws:kit]\x1b[0m setup');
|
||||||
io = new SocketIOServer(httpServer);
|
io = new SocketIOServer(httpServer);
|
||||||
|
|
||||||
io.on('connection', async (socket) => {
|
io.on('connection', async (socket) => {
|
||||||
// Runs on client connection
|
// Runs on client connection
|
||||||
console.log(`[ws:kit] client connected (${socket.id})`);
|
console.log(`\x1b[35m[ws:kit]\x1b[0m client connected (${socket.id})`);
|
||||||
// Runs on message received
|
// Runs on message received
|
||||||
socket.on('message', async (msg) => {
|
socket.on('message', async (msg) => {
|
||||||
// If message not empty
|
// If message not empty
|
||||||
if (msg.content !== '') {
|
if (msg.content !== '') {
|
||||||
console.log(`[ws:kit] message from ${socket.id}: ${msg.content}`);
|
console.log(`\x1b[35m[ws:kit]\x1b[0m message from ${socket.id}: ${msg.content}`);
|
||||||
// Store the message in the database
|
// Store the message in the database
|
||||||
await db.sendMessage('general', msg.content, msg.id, uuidv4());
|
await db.sendMessage('general', msg.content, msg.id, uuidv4());
|
||||||
io!.emit('message', {
|
io!.emit('message', {
|
||||||
@ -32,7 +32,7 @@ export function startupSocketIOServer(httpServer: HttpServer | null) {
|
|||||||
|
|
||||||
// Runs on client disconnect
|
// Runs on client disconnect
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', () => {
|
||||||
console.log(`[ws:kit] client disconnected (${socket.id})`);
|
console.log(`\x1b[35m[ws:kit]\x1b[0m client disconnected (${socket.id})`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user