MSAgent-Chat/server/src/index.ts

24 lines
588 B
TypeScript
Raw Normal View History

2024-07-01 23:34:28 -04:00
import Fastify from 'fastify';
import FastifyWS from '@fastify/websocket';
import { Client } from './client.js';
2024-07-02 00:30:10 -04:00
import { MSAgentChatRoom } from './room.js';
2024-07-01 23:34:28 -04:00
const app = Fastify({
logger: true,
});
app.register(FastifyWS);
2024-07-02 00:30:10 -04:00
let room = new MSAgentChatRoom();
2024-07-01 23:34:28 -04:00
app.get("/socket", {websocket: true}, (socket, req) => {
2024-07-02 00:30:10 -04:00
let client = new Client(socket, room);
room.addClient(client);
2024-07-01 23:34:28 -04:00
});
let port;
if (process.argv.length < 3 || isNaN(port = parseInt(process.argv[2]))) {
console.error("Usage: index.js [port]");
process.exit(1);
}
app.listen({host: "127.0.0.1", port});