20 lines
616 B
JavaScript
20 lines
616 B
JavaScript
import axios from "axios";
|
|
import { getUser } from "../state/connection.js";
|
|
import { createGame, joinGame, playCard, getGame } from "../state/game.js";
|
|
|
|
const API_URL = process.env.API_URL || "http://localhost:8000/api";
|
|
|
|
export const handleGameEvents = (io, socket) => {
|
|
socket.on("create-game", async (data) => {
|
|
try {
|
|
const user = getUser(socket.id);
|
|
const game = createGame(data.type, user);
|
|
socket.join(`game_${game.match_id}`);
|
|
|
|
} catch (error) {
|
|
console.error("Error creating game:", error);
|
|
socket.emit("error", { message: "Failed to create game." });
|
|
}
|
|
});
|
|
};
|