stub socket connection to game id namespace

This commit is contained in:
Sorrel Bri 2020-01-24 15:51:15 -08:00
parent 34a5fa8d6f
commit dbd4575128
2 changed files with 18 additions and 6 deletions

View file

@ -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})

View file

@ -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;