Skip to content

Commit

Permalink
modifications to push
Browse files Browse the repository at this point in the history
  • Loading branch information
ellenyuX committed Sep 18, 2024
1 parent d33caac commit 3e4ab2e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/app/game/game-multiplayer/lobby/lobby.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ export class LobbyComponent implements OnInit, OnDestroy {
) {}

ngOnInit(): void {
/* if (this.initializeComponent) {
//this.initializeComponent();
} */
const difficulty = 2; // Difficulty set to medium (1 for easy, 3 for hard)
this.subscriptions.add(this.multiPlayerService.joinGame(difficulty).subscribe());
this.subscriptions.add(
Expand Down
1 change: 0 additions & 1 deletion src/app/game/services/multiplayer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ export class MultiplayerService {

clearState() {
this.stateInfo = this.initialState;
//this.webSocketService.disconnect();
}

changestate(gameState: GAMESTATE) {
Expand Down
16 changes: 8 additions & 8 deletions src/app/game/services/web-socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { GameStateService } from '../services/game-state-service';
export class WebSocketService {
socket: Socket | undefined;
private retryAttempts = 0;
private maxRetries = 5; // Maximum number of retry attempts
private retryDelay = 3000; // Delay between retries in milliseconds
private maxRetries = 5;
private retryDelay = 3000;

playerDisconnectedData: PlayerDisconnectedData | undefined;

Expand Down Expand Up @@ -83,12 +83,12 @@ export class WebSocketService {
this.socket = undefined;
this.isConnected = false;
this.isRetrying = false;
console.log("Websocket closed properly maybe")
console.log("Websocket closed properly")
this.retryAttempts = 0;
} else if (this.socket) {
this.socket.removeAllListeners();
this.socket.disconnect();
console.log("THis did not work as wished")
console.log("Websocket closed properly without ever being connected")
}
}

Expand Down Expand Up @@ -120,15 +120,15 @@ export class WebSocketService {
if (this.retryAttempts <= this.maxRetries) {
console.warn(`Retrying connection... Attempt ${this.retryAttempts}/${this.maxRetries}`);
setTimeout(() => {
this.startSockets(); // Retry connection after delay
this.startSockets();
}, this.retryDelay);
} else {
console.error('Max retry attempts reached. Redirecting to error page.');
this.redirectToErrorPage();
console.error('Max retry attempts reached. Redirecting to welcome page.');
this.redirectToWelcomePage();
}
}

redirectToErrorPage() {
redirectToWelcomePage() {
this.disconnect();
this.router.navigate(['/welcome'])
}
Expand Down

0 comments on commit 3e4ab2e

Please sign in to comment.