32 lines
871 B
JavaScript
32 lines
871 B
JavaScript
import { WebSocketServer } from 'ws';
|
|
import { setupWSConnection } from './utils.js'
|
|
|
|
// Create a WebSocket server
|
|
const WS_PORT = 8080;
|
|
const wss = new WebSocketServer({ port: WS_PORT });
|
|
|
|
console.log('WebSocket server is running on ws://localhost:' + String(WS_PORT));
|
|
|
|
// Connection event handler
|
|
wss.on('connection', setupWSConnection);
|
|
/*
|
|
wss.on('connection', (ws) => {
|
|
console.log('Client connected');
|
|
|
|
// Message event handler
|
|
ws.on('message', (message) => {
|
|
let msg_str = String(message);
|
|
console.log("Received: " + msg_str);
|
|
|
|
// If this is a text or state message (no Yjs logic) - echo the message back to the client
|
|
if (msg_str.startsWith("TEXT_MESSAGE") | msg_str.startsWith("STATE_MESSAGE")) {
|
|
ws.send(msg_str);
|
|
}
|
|
});
|
|
|
|
// Close event handler
|
|
ws.on('close', () => {
|
|
console.log('Client disconnected');
|
|
});
|
|
});*/
|