fix: Sync prodServer websocket config to dev mode config
This commit is contained in:
parent
611982b445
commit
6625f0194b
@ -2,26 +2,30 @@ 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 { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const server = createServer(app);
|
const server = createServer(app);
|
||||||
const io = new Server(server);
|
const io = new Server(server);
|
||||||
|
|
||||||
io.on('connection', (socket) => {
|
io.on('connection', async (socket) => {
|
||||||
// Runs on client connect
|
// Runs on client connect
|
||||||
console.log(`[ws:kit] client connected (${socket.id})`);
|
console.log(`[ws:kit] client connected (${socket.id})`);
|
||||||
io!.emit('message', `[ws] Hello from SvelteKit ${new Date().toLocaleString()} (${socket.id})`);
|
|
||||||
|
|
||||||
// Runs on message receive
|
// Runs on message receive
|
||||||
socket.on('message', (msg) => {
|
socket.on('message', async (msg) => {
|
||||||
console.log(`[ws:kit] message from ${socket.id}: ${msg}`);
|
// If message not empty
|
||||||
io!.emit('message', `[${socket.id}] ${msg}`);
|
if (msg.content !== '') {
|
||||||
});
|
console.log(`[ws:kit] message from ${socket.id}: ${msg.content}`);
|
||||||
|
// Store the message in the database
|
||||||
// Runs on client disconnect
|
await createChannel(client, '000');
|
||||||
socket.on('disconnect', () => {
|
await storeMessage(client, '000', msg.content, msg.id, uuidv4());
|
||||||
io!.emit('message', `client disconnected (${socket.id})`);
|
io!.emit('message', {
|
||||||
console.log(`[ws:kit] client disconnected (${socket.id})`);
|
user: msg.id,
|
||||||
|
message: msg.content,
|
||||||
|
imageSrc: 'https://www.arithefirst.com/images/pfp.png',
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user