diff --git a/containers/api/src/app.controller.ts b/containers/api/src/app.controller.ts index 47c17ed7..24d6d00e 100644 --- a/containers/api/src/app.controller.ts +++ b/containers/api/src/app.controller.ts @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/17 01:00:00 by apommier #+# #+# */ -/* Updated: 2023/06/19 19:48:52 by apommier ### ########.fr */ +/* Updated: 2023/06/21 01:19:01 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -220,7 +220,10 @@ export class AppController { @UseGuards(JwtAuthGuard) @Post('/win') async addWin(@Request() req, @Body() data: any) { + console.log("WIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIN: ", req.user.username) const user = await this.userService.findOne(req.user.username); + console.log("User", user) + // const user2 = await this.userService.findOne(data.opName); user.win++; const Esp = 1 / (1 + Math.pow(10, (data.opRank - user.rank) / this.scaleFactor)) const newRank = user.rank + this.kFactor * (1 - Esp); @@ -234,14 +237,16 @@ export class AppController { newMatch.opScore = data.opScore; newMatch.opponent = data.opName; newMatch.parent = user; - + console.log(`newMatch WIIIN = ${newMatch}`); await this.userService.saveChild(user, newMatch); } @UseGuards(JwtAuthGuard) @Post('/loss') async addLoss(@Request() req, @Body() data: any) { + console.log("LOOOOOOOOOOOOOOOSE: ", req.user.username) const user = await this.userService.findOne(req.user.username); + console.log("User", user) user.loss++; const Esp = 1 / (1 + Math.pow(10, (data.opRank - user.rank) / this.scaleFactor)) @@ -256,7 +261,7 @@ export class AppController { newMatch.opScore = data.opScore; newMatch.opponent = data.opName; newMatch.parent = user; - + console.log(`newMatch Loose= ${newMatch}`); await this.userService.saveChild(user, newMatch); } @@ -292,10 +297,10 @@ export class AppController { @UseGuards(JwtAuthGuard) @Get('/partyInvite') - async getPartyInvite(@Body() data: any) + async getPartyInvite(@Request() req, @Body() data: any) { //find data.username and add invite to list - const user = await this.userService.findOne(data.username); + const user = await this.userService.findOne(req.user.username); user.partyInvite = user.partyInvite || []; // this.userService.save(user); // user.partyInvite.push(data); @@ -308,8 +313,13 @@ export class AppController { async deleteInvite(@Request() req, @Body() data: any) { console.log("delete invite user= ", data.username) - const user = await this.userService.findOne(data.username); - user.partyInvite = user.partyInvite.filter(item => Object.values(item)[1] !== req.user.username); + const user = await this.userService.findOne(req.user.username); + + + // user.partyInvite = user.partyInvite.filter(item => Object.values(item)[1] !== req.user.username); + console.log("user.partyInvite before", user.partyInvite) + user.partyInvite = user.partyInvite.filter((item) => Object.values(item)[1] !== data.username); + console.log("user.partyInvite after", user.partyInvite) this.userService.save(user); } diff --git a/containers/api/src/chat/chat.service.ts b/containers/api/src/chat/chat.service.ts index 25a5a626..b912ff83 100644 --- a/containers/api/src/chat/chat.service.ts +++ b/containers/api/src/chat/chat.service.ts @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/17 01:00:25 by apommier #+# #+# */ -/* Updated: 2023/06/18 13:14:51 by apommier ### ########.fr */ +/* Updated: 2023/06/20 16:47:02 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,6 +85,7 @@ async banUser(convId: number, username: string) { conv.banned = conv.banned || []; if (conv.banned.find(item => item === username)) return (1); + conv.members = conv.members.filter((item) => item !== username); conv.banned.push(username); this.save(conv); } diff --git a/containers/api/src/users/users.service.ts b/containers/api/src/users/users.service.ts index 45a9e1e4..1e078d57 100644 --- a/containers/api/src/users/users.service.ts +++ b/containers/api/src/users/users.service.ts @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/17 01:00:07 by apommier #+# #+# */ -/* Updated: 2023/06/17 01:00:08 by apommier ### ########.fr */ +/* Updated: 2023/06/21 01:31:44 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -47,6 +47,7 @@ export class UsersService { async saveChild(user: User, match: MatchLog): Promise { // user.match = savedChild; + user.children.push(match) await this.matchRepository.save(match); return await this.userRepository.save(user); } diff --git a/containers/chat/src/chat/chat.gateway.ts b/containers/chat/src/chat/chat.gateway.ts index 0f44fe1f..405bd818 100644 --- a/containers/chat/src/chat/chat.gateway.ts +++ b/containers/chat/src/chat/chat.gateway.ts @@ -98,85 +98,80 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa } } - @SubscribeMessage('socket.io') - socketConnect(client: any, payload: any): void { - console.log("/socket.io") +// @SubscribeMessage('socket.io') +// socketConnect(client: any, payload: any): void { +// console.log("/socket.io") +// } + +@SubscribeMessage('ban') +banUser(client: any, payload: any): void { + if (!this.clientsNames.has(payload.username)) + { + console.log("No user found."); + return; + } + const bannedClients = this.clientsNames.get(payload.username); + bannedClients.forEach(client => { + console.log("Banning client:", client); + // Perform ban operation on each client, e.g., emit a 'ban' event + console.log("clietn socket=", this.clients[client]) + this.clients[client].emit('ban', payload); + }); + // console.log("/ban") +// console.log("in ban username=", payload.username) +// if (!this.clientsNames[payload.username]) +// { +// console.log("no user ??") +// return ; +// } +// this.clientsNames[payload.username].forEach() +// console.log("client=", this.clientsNames) +// this.clients[payload.username].emit('ban', payload) +} + +@SubscribeMessage('mute') +muteUser(client: any, payload: any): void { + if (!this.clientsNames.has(payload.username)) + { + console.log("No user found."); + return; + } + const mutedClients = this.clientsNames.get(payload.username); + mutedClients.forEach(client => { + console.log("Banning client:", client); + // Perform ban operation on each client, e.g., emit a 'ban' event + console.log("clietn socket=", this.clients[client]) + this.clients[client].emit('mute', payload); + }); + console.log("/mute") } - // @SubscribeMessage('sendMessage') - // handleMessage(user: any, payload: any): void { - // console.log(`message recceveid: ${payload}`) - // console.log(`message recceveid: ${payload.sender}`) - // console.log(`message recceveid: ${payload.convId}`) - // console.log(`message recceveid: ${payload.members}`) - - // console.log(`client id: ${user.id}`) - - // this.clientsNames.forEach((clientArray, clientName) => { - // console.log(`Clients with name ${clientName}:`); - - // // clientArray.forEach((client) => { - // this.clientsNames[clientName] - // // .forEach(client => { - // // // if(client.id != user.id) - // // // { - // // console.log("send to someone") - // // console.log(client); // Perform actions on each client - // // // clients.emit('message', payload) - // // client.emit('message') - // // // } - // // }); - - // // .forEach((client) => { - // // if(client.id != user.id) - // // { - // // console.log("send to someone") - // // console.log(client); // Perform actions on each client - // // // clients.emit('message', payload) - // // client.emit('message') - // // } - // }); - // }; - @SubscribeMessage('sendMessage') handleMessage(client: Socket, payload: any): void { // console.log(`message received: ${payload}`); - console.log(`message sender: ${payload.sender}`); - console.log(`client id: ${client.id}`); - console.log(`conversation ID: ${payload.convId}`); - console.log(`members: ${payload.members}`); + // console.log(`message sender: ${payload.sender}`); + // console.log(`client id: ${client.id}`); + // console.log(`conversation ID: ${payload.convId}`); + // console.log(`members: ${payload.members}`); this.clientsNames.forEach((clientArray, clientName) => { - console.log(` 5Clients with name ${clientName}:`); + // console.log(` 5Clients with name ${clientName}:`); if (payload.members.includes(clientName)) { clientArray.forEach((targetClient, index) => { - console.log(`client id: ${client.id}`); - console.log(`target: ${targetClient}`); - console.log(`target id: ${targetClient}`); + // console.log(`client id: ${client.id}`); + // console.log(`target: ${targetClient}`); + // console.log(`target id: ${targetClient}`); if (targetClient && targetClient !== client.id) { - console.log("Sending to someone"); - console.log(`index= ${index}`); - console.log(`target: ${targetClient}`); // Perform actions on each target client - // targetClient.emit('message') - // this.clientsNames[clientName].emit('message') - // this.clientsNames["apommier"].emit('message') + // console.log("Sending to someone"); + // console.log(`index= ${index}`); + // console.log(`target: ${targetClient}`); // Perform actions on each target client this.clients[targetClient].emit('message', payload) - // console.log(test) - // console.log(test) - // this.clientsNames[clientName][index].emit('message'); - // const socket = this.server.sockets.sockets.get(targetClient.id); - // if (socket) { - // socket.emit('message', payload); - // } else { - // console.log(`Socket with ID ${client.id} not found.`); - // } - // targetClient.emit('message', payload); - // targetClient.emit('message', payload); + } else { console.log("not sending"); @@ -191,41 +186,3 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa - - // for (let key in this.clientsNames) { - // if (payload.members.includes(key)) { - // console.log("Key exists in the array"); - // // if (key !== payload.sender) - // // { - // for (let key2 in this.clientsNames[key]) - // { - // if (client.id !== this.clientsNames[key][key2]) - // { - // console.log("send to someone") - // this.clientsNames[key][key2].emit('message', payload) - // } - // } - // // } - // //if member socket different from mine - // //send - // } else { - // console.log("Key does not exist in the array"); - // } - //if key is in member - - // let socket = this.clients[key]; - // console.log("Clé:", key); - // console.log("Socket:", socket); - // } - // payload.convId // conv user instead ? - //find user to send message to - //const res = { - //convId: payload.convId - //sender: payload.sender - - // } - //while (user of conv)//how to get conv user - // if (user connected) - //send res to user -// } - diff --git a/containers/pong/src/pong/pong.gateway.ts b/containers/pong/src/pong/pong.gateway.ts index a136302d..42e1b648 100644 --- a/containers/pong/src/pong/pong.gateway.ts +++ b/containers/pong/src/pong/pong.gateway.ts @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/19 15:18:38 by apommier #+# #+# */ -/* Updated: 2023/06/19 21:38:55 by apommier ### ########.fr */ +/* Updated: 2023/06/21 00:59:39 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,26 +53,53 @@ export class PongGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa // console.log(`Client disconnected: ${client.id}`); console.log(`Normal disconnected: ${client.id}`); // this.waitingClients.delete(client); - this.waitingClients.forEach((waitingClient) => { - if (waitingClient.client === client) { - this.waitingClients.delete(waitingClient); - }}) - delete this.clients[client.id]; - console.log(`Total connected clients: ${Object.keys(this.clients).length}`); - } + // this.waitingClients.forEach((waitingClient) => { + // if (waitingClient.client === client) { + // this.waitingClients.delete(waitingClient); + // }}) + // delete this.clients[client.id]; - - @SubscribeMessage('pong:disconnect') - disconnectClient(client: Socket, payload: any): void { - console.log("disconnect forced client= ", client.id) - - for (const key in this.clients) { - if (this.clients.hasOwnProperty(key) && this.clients[key] === client) - delete this.clients[key]; - } - - // Delete the socket from the 'waitingClients' set - this.waitingClients.forEach((item) => { + this.waitingClients.forEach((item) => { + if (item.client === client) + this.waitingClients.delete(item); + }); + + // Delete the socket from the 'games' map + this.games.forEach((sockets, gameId) => { + const index = sockets.indexOf(client); + if (index !== -1) + { + if (index === 0) + { + console.log("emit boy1") + sockets[1].emit("pong:win") + // sockets[0].emit("/win") + } + else + { + console.log("emit boy2") + sockets[0].emit("pong:win") + // sockets[1].emit("/win") + } + this.games.delete(gameId); + delete this.clients[client.id]; + } + }) + + console.log(`Total connected clients: ${Object.keys(this.clients).length}`); + } + + + @SubscribeMessage('pong:disconnect') + disconnectClient(client: Socket, payload: any): void { + console.log("disconnect forced client= ", client.id) + + for (const key in this.clients) { + if (this.clients.hasOwnProperty(key) && this.clients[key] === client) + delete this.clients[key]; + } + // Delete the socket from the 'waitingClients' set + this.waitingClients.forEach((item) => { if (item.client === client) this.waitingClients.delete(item); }); @@ -82,7 +109,6 @@ export class PongGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa const index = sockets.indexOf(client); if (index !== -1) { - if (index === 0) { console.log("emit boy1") @@ -95,19 +121,6 @@ export class PongGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa sockets[0].emit("pong:win") // sockets[1].emit("/win") } - // let playersIds = - // const playersIds = this.games.get(gameId).map(socket => socket.id); - // // if (playersIds[0] === payload.id) - // // { - // if (this.clients[playersIds[1]]) - // this.clients[playersIds[1]].emit('pong:win'); - // if (this.clients[playersIds[0]]) - // this.clients[playersIds[0]].emit('pong:win'); - // } - // if (playersIds[1] === payload.id) - // { - // } - //send victory to the other one this.games.delete(gameId); delete this.clients[client.id]; } diff --git a/containers/react/src/components/Messages/Chats.tsx b/containers/react/src/components/Messages/Chats.tsx index 9805e584..44328f1e 100644 --- a/containers/react/src/components/Messages/Chats.tsx +++ b/containers/react/src/components/Messages/Chats.tsx @@ -97,6 +97,7 @@ function Chats(){ // let socket: Socket; const socket = useRef(null); + // const socket = Socket | null // socket = useRef( useRef(null)); @@ -119,15 +120,22 @@ function Chats(){ // console.log(`connection....`); socket.current = io('http://' + process.env.REACT_APP_BASE_URL + ':4001', { transports: ['polling'] }); - // console.log(`connection done`); socket.current.emit('connection', {username: tmpUser.data.username}) - socket.current.on('message', (data) => { //data should be a message ? - // console.log(`message received data= ${data.sender}`) - // console.log(`message received data= ${data.convId}`) - // console.log(`message received data= ${data.sender}`) - // console.log(`current chat = ${currentChat}`) + socket.current.on('message', (data) => { //data should be a message ?) setIncomingMessage(data); }); + + socket.current.on('ban', (data) => { + // setIncomingMessage(data); + console.log("banned hehe"); + window.location.reload() + }); + + socket.current.on('mute', (data) => { + console.log("muted hehe"); + //set mute var to true and do nothing + }); + setIsLoading(false) } @@ -138,6 +146,14 @@ function Chats(){ }; getConv(); + return () => { + console.log("Cleanup"); + if (socket.current) + socket.current.disconnect(); + // cleanup(); // Call the cleanup function to stop the ongoing process or perform necessary cleanup tasks + // cleanup(); + }; + }, []) useEffect(()=> { @@ -179,6 +195,7 @@ function Chats(){ try { const res = await api.post('/getMessage', data); + console.log("message of conv=", res.data) setMessage(res.data); } catch(err) { @@ -202,6 +219,14 @@ function Chats(){ id: null, }; try{ + const allowed = await api.post('/allowed', {convId: currentChat.id}); + console.log("convid:", currentChat.id); + if (!allowed.data) + { + console.log("muted or banned"); + return ; + } + console.log("not muted or banned"); const res = await api.post('/message', message); const convMember = await api.post('/member', message); message.members = convMember.data.members; @@ -471,7 +496,7 @@ function Chats(){ initial={false} onExitComplete={() => null} > - {setting && } + {setting && } diff --git a/containers/react/src/components/Messages/GameModal.tsx b/containers/react/src/components/Messages/GameModal.tsx index f1004eb3..00a4a542 100644 --- a/containers/react/src/components/Messages/GameModal.tsx +++ b/containers/react/src/components/Messages/GameModal.tsx @@ -29,6 +29,7 @@ interface ModalGame { const GameModal = ({ handleClose }: ModalGame) => { const [users, setUsers] = useState([]); +// const [user, setUser] = useState(); const [selectedUser, setSelectedUser] = useState(''); // const [convs, setConvs] = useState([]); const [channel, setChannel] = useState(''); @@ -39,8 +40,10 @@ const GameModal = ({ handleClose }: ModalGame) => { const fetchData = async () => { try { const tmpUsers = await api.get("/users"); + // const tmpUser = await api.get("/profile"); // const tmpConvs = await api.get("/convs"); setUsers(tmpUsers.data); + // setUser(tmpUser.data); // setConvs(tmpConvs.data); } catch (err) { console.log(err); @@ -53,20 +56,20 @@ const GameModal = ({ handleClose }: ModalGame) => { setSelectedUser(event.target.value); }; - const joinChannel = async () => { - try { - await api.post("/join", { convId: channel }); - } catch (err) { - console.log(err); - } - }; +// const joinChannel = async () => { +// try { +// await api.post("/join", { convId: channel }); +// } catch (err) { +// console.log(err); +// } +// }; - const handleCheckButtonClick = () => { - // Perform your check action here - console.log("Checking user:", selectedUser); - }; +// const handleCheckButtonClick = () => { +// // Perform your check action here +// console.log("Checking user:", selectedUser); +// }; - const handleButtonClick = () => { + const handleButtonClick = async () => { // let path = `play?`; let path = `http://` + process.env.REACT_APP_BASE_URL + `/pong/play?`; @@ -93,6 +96,8 @@ const GameModal = ({ handleClose }: ModalGame) => { // path = path.slice(0, -1); // console.log(path) + // await api.post("/partyInvite", {username: selectedUser, gameId}) + // console.log("path= ", path) // history(path, { replace: true }); // window.location.replace(path); diff --git a/containers/react/src/components/Messages/Message.tsx b/containers/react/src/components/Messages/Message.tsx index e1c368e7..da8479ad 100644 --- a/containers/react/src/components/Messages/Message.tsx +++ b/containers/react/src/components/Messages/Message.tsx @@ -6,7 +6,11 @@ /* By: sadjigui +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/01 18:24:46 by apommier #+# #+# */ +<<<<<<< HEAD /* Updated: 2023/06/23 19:33:40 by sadjigui ### ########.fr */ +======= +/* Updated: 2023/06/20 19:05:10 by apommier ### ########.fr */ +>>>>>>> apommier /* */ /* ************************************************************************** */ @@ -42,6 +46,7 @@ function MessageMe({message, own}: MessageMeProps){ const [user, setUser] = useState(); const scrollRef = useRef(null); + // console.log("Message eher") useEffect(() => { if (scrollRef.current) @@ -82,13 +87,20 @@ function MessageMe({message, own}: MessageMeProps){ }; if (!user || !sender || !conv) + { + // console.log("return") return (<>); + } // console.log("result includes=", conv.banned.includes(user.username)) // console.log("result includes=", conv.blocked.includes(user.username)) if (user.blocked && user.blocked.includes(message.sender)) return (<>); - else if (conv.banned && conv.banned.includes(user.username)) - return (<>); + // else if (conv.banned && conv.banned.includes(user.username)) + // { + // console.log("return2") + // return (<>); + // } + // console.log("noy return") // if (user.blocked.includes(message.sender))/ return ( diff --git a/containers/react/src/components/Messages/Modal.tsx b/containers/react/src/components/Messages/Modal.tsx index 8bb6fc01..50b040fc 100644 --- a/containers/react/src/components/Messages/Modal.tsx +++ b/containers/react/src/components/Messages/Modal.tsx @@ -100,11 +100,11 @@ const Modal = ({handleClose}) => { // let new_name; return ( - + e.stopPropagation()} - className="modalSetting" - variant={dropIn} + className="modal" + // variant={dropIn} initial="hidden" animate="visible" exit="exit" diff --git a/containers/react/src/components/Messages/ModalSetting.tsx b/containers/react/src/components/Messages/ModalSetting.tsx index 3b73b59b..8226ed32 100644 --- a/containers/react/src/components/Messages/ModalSetting.tsx +++ b/containers/react/src/components/Messages/ModalSetting.tsx @@ -8,6 +8,7 @@ import { Link } from "react-router-dom"; import api from "../../script/axiosApi.tsx"; import React from "react"; import {User} from "../../../interfaces.tsx" +import { Socket } from "socket.io-client"; const dropIn = { @@ -28,10 +29,11 @@ const dropIn = { interface ModalSettingProps { handleClose: Function, - convId: string + convId: string, + socket: Socket | null, } -const ModalSetting = ({handleClose, convId}: ModalSettingProps) => { +const ModalSetting = ({handleClose, convId, socket }: ModalSettingProps) => { const [password, setPassword] = useState(false); const [users, setUsers] = useState([]); const [selectTags, setSelectTag] = useState([{ id: 1, selectedOption: ''}]); @@ -108,6 +110,7 @@ const ModalSetting = ({handleClose, convId}: ModalSettingProps) => { return ; try{ api.post("/name", {convId: convId, name: newName}) + window.location.reload() } catch(err) { console.log(err); } @@ -118,51 +121,56 @@ const ModalSetting = ({handleClose, convId}: ModalSettingProps) => { if (e.key !== "Enter") return ; try{ - api.post("/password", {convId: convId, password: newPassword}) + await api.post("/password", {convId: convId, password: newPassword}) } catch(err) { console.log(err); } handleClose(); } - const handleBan = () => { + const handleBan = async () => { // console.log("ban option= ", selectedUser) try{ // console.log("user select=", selectedUser.length) if (!selectedUser.length) return ; - api.post("/ban", {convId: convId, username: selectedUser}) + await api.post("/ban", {convId: convId, username: selectedUser}) + if (socket) + { + console.log("emit to ban server") + socket.emit("ban", {username: selectedUser}) + } } catch(err) { console.log(err); } handleClose(); }; - const handleAdmin = () => { + const handleAdmin = async () => { if (!selectedUser.length) return ; try{ - api.post("/admin", {convId: convId, username: selectedUser}) + await api.post("/admin", {convId: convId, username: selectedUser}) } catch(err) { console.log(err); } handleClose(); }; - const handleMute = () => { + const handleMute = async () => { if (!selectedUser.length) return ; try{ - api.post("/mute", {convId: convId, username: selectedUser}) + await api.post("/mute", {convId: convId, username: selectedUser}) } catch(err) { console.log(err); } handleClose(); }; - const handleInvite = () => { + const handleInvite = async () => { try{ - api.post("/invite", {convId: convId, username: selectedUser}) + await api.post("/invite", {convId: convId, username: selectedUser}) } catch(err) { console.log(err); } diff --git a/containers/react/src/components/Messages/PartyInvite.tsx b/containers/react/src/components/Messages/PartyInvite.tsx index 6bb8509d..791d632b 100644 --- a/containers/react/src/components/Messages/PartyInvite.tsx +++ b/containers/react/src/components/Messages/PartyInvite.tsx @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/19 16:44:29 by apommier #+# #+# */ -/* Updated: 2023/06/20 03:47:52 by apommier ### ########.fr */ +/* Updated: 2023/06/20 23:53:01 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -82,9 +82,6 @@ export default function PartyInvite({currentInvite}: UserProps) window.history.pushState({}, '', path); window.location.reload(); }; - - - const Accept = async (request: User) => { try{ @@ -118,6 +115,7 @@ export default function PartyInvite({currentInvite}: UserProps) // Vérifier si le contenu doit être caché if (clickEvent) { + console.log("retrun true") return null; // Rendre null pour ne pas afficher le contenu } diff --git a/containers/react/src/pages/canvas.tsx b/containers/react/src/pages/canvas.tsx index 7cef82fe..46dd1a58 100644 --- a/containers/react/src/pages/canvas.tsx +++ b/containers/react/src/pages/canvas.tsx @@ -61,7 +61,7 @@ function DrawCanvas(option: number, gameParam: GameProps) { if(!ctx) return ; - const socket = io('http://' + process.env.REACT_APP_BASE_URL + ':4000'); + const socket = io('http://' + process.env.REACT_APP_BASE_URL + ':4000', { transports: ['polling'] }); // useEffect(() => { // console.log("useeffect?????????????????") // return () => { @@ -137,14 +137,14 @@ function DrawCanvas(option: number, gameParam: GameProps) { socket.on('pong:win', async () => { myScore = maxScore; console.log("instant win opponent disconnect") - const data = { - myScore: myScore, - opScore: hisScore, - opName: opName, - opRank: opRank, - }; + // const data = { + // myScore: myScore, + // opScore: hisScore, + // opName: opName, + // opRank: opRank, + // }; - await api.post('/win', data); + // await api.post('/win', data); console.log("after request1") await api.post('/status', {status: 1}); console.log("after request2") @@ -152,7 +152,7 @@ socket.on('pong:win', async () => { running = false; socket.emit('pong:disconnect', {id: myId}); console.log("before reload") - window.location.replace("http://" + process.env.REACT_APP_BASE_URL + "/pong"); + // window.location.replace("http://" + process.env.REACT_APP_BASE_URL + "/pong"); // window.location.reload(); return ; // console.log("send all ?? win"); @@ -468,6 +468,7 @@ async function draw(timestamp: number) } if (myScore === maxScore || hisScore === maxScore) { + console.log("maxScore!!!!") const data = { myScore: myScore, opScore: hisScore, @@ -485,8 +486,9 @@ async function draw(timestamp: number) } else { - // await api.post('/loss', data); - // await api.post('/status', {status: 1}); + await api.post('/loss', data); + await api.post('/status', {status: 1}); + socket.emit('pong:disconnect', {id: myId}); //disconnect ? console.log("send loose"); } @@ -604,7 +606,9 @@ async function draw(timestamp: number) } if (ballX > canvas.width) { - console.log("win point") + // if (ballX > canvas.width * 2) + // socket.emit + // console.log("win point") // if (ballY <= paddleY + paddleHeight + ballRadius && ballY >= paddleY - ballRadius) // { // console.log('true hehe');