stub socket connection to game id namespace
This commit is contained in:
parent
c033e3558a
commit
7f1386f7a7
2 changed files with 18 additions and 6 deletions
|
@ -9,7 +9,7 @@ const show = async (req, res, next) => {
|
||||||
const gameId = req.params.id;
|
const gameId = req.params.id;
|
||||||
if (!gameId) throw('missing game parameter')
|
if (!gameId) throw('missing game parameter')
|
||||||
const game = await gameQueries.findGameById(gameId);
|
const game = await gameQueries.findGameById(gameId);
|
||||||
enableGameSocket(game.room, game.id);
|
enableGameSocket(game.room);
|
||||||
|
|
||||||
const record = await moveQueries.findGameRecord(gameId);
|
const record = await moveQueries.findGameRecord(gameId);
|
||||||
res.status(200).json({game, record})
|
res.status(200).json({game, record})
|
||||||
|
|
|
@ -8,7 +8,7 @@ io.on('connection', ()=> {
|
||||||
io.emit('connected', {message: 'socket connected'});
|
io.emit('connected', {message: 'socket connected'});
|
||||||
})
|
})
|
||||||
|
|
||||||
const enableRoomSocket = (roomId) => {
|
const enableRoomSocket = () => {
|
||||||
const roomSocket = io.of(roomId);
|
const roomSocket = io.of(roomId);
|
||||||
roomSocket.on('connection', (socket) => {
|
roomSocket.on('connection', (socket) => {
|
||||||
|
|
||||||
|
@ -27,13 +27,25 @@ const enableRoomSocket = (roomId) => {
|
||||||
return roomSocket;
|
return roomSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
const enableGameSocket = (roomId, gameId) => {
|
const enableGameSocket = (roomId) => {
|
||||||
const gameSocket = io.of(roomId);
|
const gameSocket = io.of(roomId);
|
||||||
|
let game;
|
||||||
gameSocket.on('connection', (socket) => {
|
gameSocket.on('connection', (socket) => {
|
||||||
socket.join(gameId);
|
socket.on('joined game', (gameId) => {
|
||||||
socket.to(gameId).emit(`joined room ${gameId}`)
|
game = `game-${gameId}`;
|
||||||
console.log(socket)
|
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;
|
return gameSocket;
|
||||||
|
|
Loading…
Reference in a new issue