stub game connection via socket room

This commit is contained in:
Sorrel Bri 2020-01-29 17:01:46 -08:00 committed by sorrelbri
parent d6ec6c3163
commit fd72f135dd
4 changed files with 14 additions and 7 deletions

View file

@ -36,8 +36,8 @@ exports.up = function(knex) {
table.enu('win_type', winType); table.enu('win_type', winType);
table.float('score'); table.float('score');
table.integer('black_captures'); table.integer('captures_black');
table.integer('white_captures'); table.integer('captures_white');
table.integer('user_black').references('id').inTable('user'); table.integer('user_black').references('id').inTable('user');
table.integer('user_white').references('id').inTable('user'); table.integer('user_white').references('id').inTable('user');

View file

@ -4,7 +4,7 @@ const gameDetailSelect = [
'game.id', 'application', 'application_version', 'game.id', 'application', 'application_version',
'board_size', 'komi', 'handicap', 'open', 'win_type', 'board_size', 'komi', 'handicap', 'open', 'win_type',
'player_black', 'player_black_rank', 'player_white', 'player_white_rank', 'player_black', 'player_black_rank', 'player_white', 'player_white_rank',
'black_captures', 'white_captures', 'score', 'win_type', 'captures_black', 'captures_white', 'score', 'win_type',
'description', 'event', 'round', 'name', 'room' 'description', 'event', 'round', 'name', 'room'
] ]

View file

@ -11,11 +11,18 @@ io.on('connection', socket=> {
if (data.user && data.user.email) { if (data.user && data.user.email) {
delete data.user.email; delete data.user.email;
} }
const roomIo = io.of(data.room); const room= data.room;
const roomIo = io.of(room);
roomIo.on('connection', socket => { roomIo.on('connection', socket => {
socket.emit('connected') socket.emit('connected')
socket.emit('new_user', data); socket.emit('new_user', data);
}) socket.on('connect_game', data => {
const game = `game-${data.game.id}`;
socket.join(game, () => {
io.of(room).to(game).emit('game_connected', {})
});
});
});
}) })
}) })

View file

@ -15,8 +15,8 @@ const apiRoomSpec = (chai, knex, server) => {
player_black_rank: 'UR', player_black_rank: 'UR',
player_white: 'user-two', player_white: 'user-two',
player_white_rank: 'UR', player_white_rank: 'UR',
black_captures: null, captures_black: null,
white_captures: null, captures_white: null,
score: null, score: null,
description: null, description: null,
event: null, event: null,