2020-01-08 19:24:24 +00:00
|
|
|
// TODO const someSocketLogic = require('./middleware/socketssockets/...');
|
2020-01-21 22:33:40 +00:00
|
|
|
const socketIO = require('socket.io');
|
|
|
|
const io = socketIO({ cookie: false });
|
2020-01-08 19:24:24 +00:00
|
|
|
|
2020-01-24 05:25:08 +00:00
|
|
|
const gameQueries = require('./data/queries/game');
|
2020-01-31 05:03:27 +00:00
|
|
|
const gameServices = require('./services/gameServices');
|
2020-01-24 05:25:08 +00:00
|
|
|
|
2020-01-26 00:50:18 +00:00
|
|
|
io.on('connection', socket=> {
|
|
|
|
socket.emit('connected', {message: 'socket connected'});
|
|
|
|
socket.on('connect_room', data => {
|
2020-01-28 06:40:03 +00:00
|
|
|
if (data.user && data.user.email) {
|
|
|
|
delete data.user.email;
|
|
|
|
}
|
2020-01-30 01:01:46 +00:00
|
|
|
const room= data.room;
|
|
|
|
const roomIo = io.of(room);
|
2020-01-28 06:40:03 +00:00
|
|
|
roomIo.on('connection', socket => {
|
|
|
|
socket.emit('connected')
|
|
|
|
socket.emit('new_user', data);
|
2020-01-30 01:01:46 +00:00
|
|
|
socket.on('connect_game', data => {
|
|
|
|
const game = `game-${data.game.id}`;
|
2020-02-01 04:28:39 +00:00
|
|
|
socket.join(game, async () => {
|
|
|
|
// ! temp
|
|
|
|
gameServices.initGame({id: data.game.id})
|
|
|
|
// ! end-temp
|
|
|
|
const gameData = await gameServices.getBoard(data.game.id);
|
|
|
|
io.of(room).to(game).emit('game_connected', gameData)
|
2020-01-30 01:01:46 +00:00
|
|
|
});
|
|
|
|
});
|
2020-01-31 05:03:27 +00:00
|
|
|
socket.on('make_move', data => {
|
|
|
|
const { user, move, board, game, room } = data;
|
2020-02-01 04:28:39 +00:00
|
|
|
console.log(move)
|
2020-01-31 05:03:27 +00:00
|
|
|
console.log(data)
|
2020-02-01 04:28:39 +00:00
|
|
|
gameServices.makeMove(1, move)
|
2020-01-31 05:03:27 +00:00
|
|
|
})
|
2020-01-30 01:01:46 +00:00
|
|
|
});
|
2020-01-28 06:40:03 +00:00
|
|
|
})
|
2020-01-26 00:50:18 +00:00
|
|
|
})
|
2020-01-08 19:24:24 +00:00
|
|
|
|
2020-01-21 22:33:40 +00:00
|
|
|
module.exports = {
|
2020-02-01 04:28:39 +00:00
|
|
|
io
|
2020-01-24 05:25:08 +00:00
|
|
|
}
|