2024-04-09 16:21:05 +05:30
|
|
|
import { WebSocketServer } from 'ws';
|
|
|
|
import { handleConnection } from './connectionManager';
|
|
|
|
import http from 'http';
|
2024-04-20 09:32:19 +05:30
|
|
|
import { getPort } from '../config';
|
2024-04-30 12:18:18 +05:30
|
|
|
import logger from '../utils/logger';
|
2024-04-09 16:21:05 +05:30
|
|
|
|
|
|
|
export const initServer = (
|
|
|
|
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
|
|
|
) => {
|
2024-04-20 09:32:19 +05:30
|
|
|
const port = getPort();
|
2024-04-09 16:21:05 +05:30
|
|
|
const wss = new WebSocketServer({ server });
|
|
|
|
|
|
|
|
wss.on('connection', (ws) => {
|
|
|
|
handleConnection(ws);
|
|
|
|
});
|
|
|
|
|
2024-04-30 12:18:18 +05:30
|
|
|
logger.info(`WebSocket server started on port ${port}`);
|
2024-04-09 16:21:05 +05:30
|
|
|
};
|