Skip to content

Commit

Permalink
DONE
Browse files Browse the repository at this point in the history
  • Loading branch information
ismail-kharrobi committed Nov 15, 2023
1 parent 77196e3 commit 58831e9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
21 changes: 11 additions & 10 deletions backend/code/src/game/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,19 +356,20 @@ export class Game {
this.emitGameEnd('end');
}
}
private removeLis(socket) {
socket.removeListener('disconnect', () => {});
socket.removeListener('leave', () => {});
socket.removeListener('screen', () => {});
socket.removeListener('mouse', () => {});
socket.removeListener('up', () => {});
socket.removeListener('down', () => {});

private removeListeners(socket: Socket) {
socket.removeAllListeners('disconnect');
socket.removeAllListeners('leave');
socket.removeAllListeners('screen');
socket.removeAllListeners('mouse');
socket.removeAllListeners('up');
socket.removeAllListeners('down');
}
private emitGameEnd(message: string) {
console.log('game end');
console.log`asdaqwe Game end`;
this.closeGame = true;
this.removeLis(this.p1socket);
this.removeLis(this.p2socket);
this.removeListeners(this.p1socket);
this.removeListeners(this.p2socket);

if (message === 'p1Leave') {
this.eventEmitter.emit('game.end', {
Expand Down
10 changes: 1 addition & 9 deletions frontend/code/src/Components/Game/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ import { BsFillArrowRightCircleFill, BsFillArrowLeftCircleFill} from "react-icon
import { useGameState } from "./States/GameState";
import { useSocketStore } from "../Chat/Services/SocketsServices";
import { useNavigate } from "react-router-dom";
import { matchRoutes, useLocation } from "react-router-dom";



const routes = [
{ path: "Game/:id" },
];

const useCurrentPath = () => {
const location = useLocation();
const [{ route }]: any = matchRoutes(routes, location);
return route.path;
};

const DURATION = 20;
type Cords = {
x:number;
Expand Down
1 change: 1 addition & 0 deletions frontend/code/src/Components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const Layout: FC<PropsWithChildren> = (): JSX.Element => {
return () => {
socketStore.socket.off("leave");
}
// eslint-disable-next-line
},[path])
useLayoutEffect(() => {
const log = async () => {
Expand Down

0 comments on commit 58831e9

Please sign in to comment.