stub socket connection to game id namespace
This commit is contained in:
parent
67f0449963
commit
f6b6134d5b
2 changed files with 18 additions and 6 deletions
|
@ -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})
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue