0
0
Fork 0

Intial websocket server creation

This commit is contained in:
Oliver-Akins 2020-12-23 12:38:39 -07:00
parent 5b487b2530
commit 8e95c14b6a
2 changed files with 42 additions and 0 deletions

17
server/src/main.ts Normal file
View file

@ -0,0 +1,17 @@
import * as toml from "toml";
import { Logger } from "tslog";
import { readFileSync } from "fs";
import startWebsocket from "./websocket";
let conf: config = toml.parse(readFileSync(`server.toml`, `utf-8`));
export const log: Logger = new Logger({
displayFunctionName: false,
displayLoggerName: false,
displayFilePath: `hidden`,
displayLogLevel: true,
minLevel: conf.log.level,
name: conf.log.name,
});
startWebsocket(conf);

25
server/src/websocket.ts Normal file
View file

@ -0,0 +1,25 @@
import { log } from "./main";
import { Server, Socket } from "socket.io";
import CreateGame from "./events/CreateGame";
export default async (conf: config) => {
const io = new Server();
io.listen(conf.websocket.port, {
cors: {
origin: conf.webserver.hostname,
credentials: true,
}
})
io.on(`connection`, (socket: Socket) => {
log.debug(`Client connected with ID: ${socket.id}`);
socket.on(`CreateGame`, (data: CreateGame) => CreateGame(io, socket, data));
});
log.info(`Server started on port ${conf.websocket.port}`);
}