start working on websocket stuff
This commit is contained in:
30
src/index.ts
30
src/index.ts
@ -1,7 +1,9 @@
|
||||
import Database from "./database/database";
|
||||
import Scanner from "./scanner/scanner";
|
||||
import ServerManager from "./server/serverManager";
|
||||
import { formatTimestamp } from "./utils/timeUtils";
|
||||
import WebsocketServer from "./websocket/websocket";
|
||||
|
||||
import Config from "../data/config.json";
|
||||
|
||||
/**
|
||||
* The database instance.
|
||||
@ -16,14 +18,18 @@ export const serverManager = new ServerManager();
|
||||
// The scanner is responsible for scanning all servers
|
||||
new Scanner();
|
||||
|
||||
serverManager.getServers().forEach((server) => {
|
||||
const record = database.getRecord(server.getID());
|
||||
if (!record) {
|
||||
return;
|
||||
}
|
||||
console.log(
|
||||
`Record for "${server.getName()}": ${record.playerCount} (${formatTimestamp(
|
||||
record.timestamp
|
||||
)})`
|
||||
);
|
||||
});
|
||||
// The websocket server is responsible for
|
||||
// sending data to the client in real time
|
||||
new WebsocketServer(Config.websocket.port);
|
||||
|
||||
// serverManager.getServers().forEach((server) => {
|
||||
// const record = database.getRecord(server.getID());
|
||||
// if (!record) {
|
||||
// return;
|
||||
// }
|
||||
// console.log(
|
||||
// `Record for "${server.getName()}": ${record.playerCount} (${formatTimestamp(
|
||||
// record.timestamp
|
||||
// )})`
|
||||
// );
|
||||
// });
|
||||
|
17
src/websocket/websocket.ts
Normal file
17
src/websocket/websocket.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Server } from "socket.io";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
export default class WebsocketServer {
|
||||
private server: Server;
|
||||
|
||||
constructor(port: number) {
|
||||
logger.info(`Starting websocket server on port ${port}`);
|
||||
this.server = new Server(port);
|
||||
|
||||
this.server.on("connection", (socket) => {
|
||||
logger.info("ws: Client connected");
|
||||
|
||||
// todo: send ping data to client
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user