From 63abebc72240de13aa015739e2a9952ae588e4ca Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Fri, 23 Jul 2021 13:23:26 +0530 Subject: somehow made it work on multiple devices --- src/server/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/server/index.js') diff --git a/src/server/index.js b/src/server/index.js index 9013ac6..2799805 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -2,7 +2,15 @@ const express = require('express'); const app = express(); const http = require('http').Server(app); const path = require('path'); -const io = require('socket.io')(http); + +// const io = require('socket.io')(http); +const io = require("socket.io")(http, { + cors: { + origin: ["http://localhost:5000", "http://localhost:3000"], + "Access-Control-Allow-Origin": "*", + methods: ["GET", "POST"] + } +}); const allEqual = (arr) => arr.includes(2) ? false : arr.every(i => i === arr[0]) @@ -31,7 +39,6 @@ const getScore = (winner, scoreX, scoreO, board) => ({ io.on('connection', (socket) => { socket.on('update-remote-data', (data) => { - console.log(data) if (data.board.includes(0) || data.board.includes(1)) { const rows = getRows(data.board); const winner = (rows.some((i) => allEqual(i)) @@ -42,11 +49,10 @@ io.on('connection', (socket) => { const score = getScore(winner, data.scoreX, data.scoreO, data.board) io.emit('update-client-data', { board: data.board, - turn: data.turn === 0 ? 1 : 0, + turn: score.winner ? data.turn : (data.turn === 0 ? 1 : 0), score: score }); - score.winner && console.log("sending winner") score.winner && io.emit('update-winner', score) }; }); -- cgit v1.2.3