diff --git a/packages/server/server/controllers/api/apiGame.js b/packages/server/server/controllers/api/apiGame.js index d828830..48b8b16 100644 --- a/packages/server/server/controllers/api/apiGame.js +++ b/packages/server/server/controllers/api/apiGame.js @@ -9,7 +9,7 @@ const show = async (req, res, next) => { const gameId = req.params.id; if (!gameId) throw('missing game parameter') const game = await gameQueries.findGameById(gameId); - enableGameSocket(game.room, game.id); + enableGameSocket(game.room); const record = await moveQueries.findGameRecord(gameId); res.status(200).json({game, record}) diff --git a/packages/server/server/socket.js b/packages/server/server/socket.js index be916f0..e932e52 100644 --- a/packages/server/server/socket.js +++ b/packages/server/server/socket.js @@ -8,7 +8,7 @@ io.on('connection', ()=> { io.emit('connected', {message: 'socket connected'}); }) -const enableRoomSocket = (roomId) => { +const enableRoomSocket = () => { const roomSocket = io.of(roomId); roomSocket.on('connection', (socket) => { @@ -27,13 +27,25 @@ const enableRoomSocket = (roomId) => { return roomSocket; } -const enableGameSocket = (roomId, gameId) => { +const enableGameSocket = (roomId) => { const gameSocket = io.of(roomId); + let game; gameSocket.on('connection', (socket) => { - socket.join(gameId); - socket.to(gameId).emit(`joined room ${gameId}`) - console.log(socket) + socket.on('joined game', (gameId) => { + game = `game-${gameId}`; + console.log(gameId) + socket.join(game); + // socket + // .to(game) + io.sockets.in(game).emit('success', game) + }) + }); + // console.log(game) + // gameSocket + // .to(game) + // .emit(`success`, game) + // socket.on('hey', () => console.log('hey')) return gameSocket;