This commit is contained in:
pb-coding 2023-09-23 18:39:31 +02:00
parent 51c0c6cb1f
commit 2971b4c086
5 changed files with 17 additions and 13 deletions

6
.env
View file

@ -1,2 +1,6 @@
PORT=3001 PORT=3001
ENVIRONMENT=local ENVIRONMENT=dev
FRONTEND_URL=https://skyjo.voltvector.org
#ENVIRONMENT=local
#FRONTEND_URL=http://localhost:5173

4
.gitignore vendored
View file

@ -2,4 +2,6 @@ node_modules
dist dist
src/logs/ src/logs/
.env.local

View file

@ -1,10 +0,0 @@
<html>
<head>
<title>SkyJo Server list</title>
</head>
<body>
<h1>SkyJo Server list</h1>
<button>Start new Game</button>
</body>
</html>

View file

@ -19,6 +19,9 @@ export const handleNewGame = (
const { sessionId } = gameDetails; const { sessionId } = gameDetails;
const players = io.sockets.adapter.rooms.get(sessionId); const players = io.sockets.adapter.rooms.get(sessionId);
// get players based on socket
const playersInSession = io.sockets.adapter.sids.get(socket.id);
console.log("Players in session:", playersInSession?.size);
if (players && players.size > 1) { if (players && players.size > 1) {
const game = new Game(socket, sessionId, players); const game = new Game(socket, sessionId, players);

View file

@ -13,11 +13,15 @@ import corsOptions from "./config/corsOptions";
import cookieParser from "cookie-parser"; import cookieParser from "cookie-parser";
import rootRouter from "./routes/root"; import rootRouter from "./routes/root";
import { handleJoinSession, handleNewGame } from "./game/events"; import { handleJoinSession, handleNewGame } from "./game/events";
import dotenv from "dotenv";
dotenv.config();
const FRONTEND_URL = process.env.FRONTEND_URL ?? "";
const httpServer = new Server(app); const httpServer = new Server(app);
export const io = new SocketIOServer(httpServer, { export const io = new SocketIOServer(httpServer, {
cors: { cors: {
origin: "https://skyjo.voltvector.org", origin: FRONTEND_URL,
methods: ["GET", "POST"], methods: ["GET", "POST"],
}, },
}); });
@ -36,6 +40,7 @@ io.on("connection", (socket: Socket) => {
socket.on("disconnect", () => { socket.on("disconnect", () => {
console.log("A user disconnected:", socket.id); console.log("A user disconnected:", socket.id);
// TODO: remove players from session and delete game object // TODO: remove players from session and delete game object
io;
}); });
}); });