aboutsummaryrefslogtreecommitdiff
path: root/src/server/index.js
diff options
context:
space:
mode:
authorMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-07-23 13:23:26 +0530
committerMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-07-23 13:23:26 +0530
commit63abebc72240de13aa015739e2a9952ae588e4ca (patch)
tree4f260ff7cf094eb926b13bfbc964ab7340a40daa /src/server/index.js
parent55c5f64755e5d964603f4cc60bdf1ceeccf7df21 (diff)
somehow made it work on multiple devices
Diffstat (limited to 'src/server/index.js')
-rw-r--r--src/server/index.js14
1 files changed, 10 insertions, 4 deletions
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)
};
});