From aeca003191bf77f2d22067a1989f3955c11333d6 Mon Sep 17 00:00:00 2001 From: shahdlala66 Date: Tue, 23 Jun 2026 09:37:21 +0200 Subject: [PATCH] feat: api for server could be wrong --- .../tournament-watch.component.ts | 10 +++++++++- .../pages/tournaments/tournaments.component.ts | 13 ++++++++++++- src/app/services/tournament-stream.service.ts | 17 +++++++++++++---- src/environments/environment.development.ts | 3 ++- src/environments/environment.staging.ts | 3 ++- src/environments/environment.ts | 3 ++- 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/app/pages/tournament-watch/tournament-watch.component.ts b/src/app/pages/tournament-watch/tournament-watch.component.ts index 2f3ffd3..502cf50 100644 --- a/src/app/pages/tournament-watch/tournament-watch.component.ts +++ b/src/app/pages/tournament-watch/tournament-watch.component.ts @@ -5,6 +5,7 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { ChessBoardComponent } from '../../components/chess-board/chess-board.component'; import { TournamentStreamService } from '../../services/tournament-stream.service'; import { GameClock, GameStateSnapshot, GameStreamEvent, GameStatus } from '../../models/tournament.models'; +import { environment } from '../../../environments/environment'; const INITIAL_FEN = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'; @@ -22,6 +23,7 @@ export class TournamentWatchComponent implements OnInit { tournamentId = ''; gameId = ''; + serverUrl = ''; fen = INITIAL_FEN; turn: 'white' | 'black' = 'white'; @@ -37,13 +39,19 @@ export class TournamentWatchComponent implements OnInit { ngOnInit(): void { this.tournamentId = this.route.snapshot.paramMap.get('id') ?? ''; this.gameId = this.route.snapshot.paramMap.get('gameId') ?? ''; + this.serverUrl = this.route.snapshot.queryParamMap.get('server') ?? environment.tournamentServerUrl ?? ''; if (!this.tournamentId || !this.gameId) { this.error = 'Missing tournament or game id.'; this.connecting = false; return; } + if (!this.serverUrl) { + this.error = 'Missing tournament server URL.'; + this.connecting = false; + return; + } - this.stream.streamGame(this.tournamentId, this.gameId) + this.stream.streamGame(this.serverUrl, this.tournamentId, this.gameId) .pipe(takeUntilDestroyed(this.destroyRef)) .subscribe({ next: ev => this.apply(ev), diff --git a/src/app/pages/tournaments/tournaments.component.ts b/src/app/pages/tournaments/tournaments.component.ts index 9c69cee..bd62f99 100644 --- a/src/app/pages/tournaments/tournaments.component.ts +++ b/src/app/pages/tournaments/tournaments.component.ts @@ -12,6 +12,7 @@ import { TournamentServerService, ExternalTournamentServer } from '../../service import { Bot } from '../../models/bot.models'; import { Tournament, TournamentResult, RoundPairings } from '../../models/tournament.models'; import { CurrentUser } from '../../models/auth.models'; +import { environment } from '../../../environments/environment'; type StatusTab = 'started' | 'created' | 'finished'; @@ -77,6 +78,9 @@ export class TournamentsComponent implements OnInit { .pipe(takeUntilDestroyed(this.destroyRef)) .subscribe(u => { this.currentUser = u; }); this.loadTournaments(); + this.tournamentServerService.list() + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe({ next: res => { this.servers = res.servers; }, error: () => {} }); } openCreateDialog(): void { @@ -166,7 +170,14 @@ export class TournamentsComponent implements OnInit { watchGame(gameId: string): void { const tid = this.selectedTournament?.id; if (!tid) return; - void this.router.navigate(['/tournament', tid, 'game', gameId]); + const server = this.servers[0]?.url || environment.tournamentServerUrl; + if (!server) { + this.joinError = 'No tournament server configured. Cannot open stream.'; + return; + } + void this.router.navigate(['/tournament', tid, 'game', gameId], { + queryParams: { server } + }); } openJoinDialog(event: MouseEvent, tournamentId: string): void { diff --git a/src/app/services/tournament-stream.service.ts b/src/app/services/tournament-stream.service.ts index 7983b57..d6458bd 100644 --- a/src/app/services/tournament-stream.service.ts +++ b/src/app/services/tournament-stream.service.ts @@ -4,12 +4,21 @@ import { GameStreamEvent, TournamentStreamEvent } from '../models/tournament.mod @Injectable({ providedIn: 'root' }) export class TournamentStreamService { - streamTournament(tournamentId: string): Observable { - return this.ndjson(`/api/tournament/${tournamentId}/stream`); + streamTournament(serverUrl: string, tournamentId: string): Observable { + return this.ndjson( + this.url(serverUrl, `/api/tournament/${tournamentId}/stream`) + ); } - streamGame(tournamentId: string, gameId: string): Observable { - return this.ndjson(`/api/tournament/${tournamentId}/game/${gameId}/stream`); + streamGame(serverUrl: string, tournamentId: string, gameId: string): Observable { + return this.ndjson( + this.url(serverUrl, `/api/tournament/${tournamentId}/game/${gameId}/stream`) + ); + } + + private url(base: string, path: string): string { + if (!base) return path; + return `${base.replace(/\/+$/, '')}${path}`; } private ndjson(url: string): Observable { diff --git a/src/environments/environment.development.ts b/src/environments/environment.development.ts index 0bb31eb..f80e457 100644 --- a/src/environments/environment.development.ts +++ b/src/environments/environment.development.ts @@ -4,5 +4,6 @@ export const environment = { accountServiceUrl: '', wsBaseUrl: 'ws://localhost:8084', userWsBaseUrl: 'ws://localhost:8084', - apiPath: '/api/board/game' + apiPath: '/api/board/game', + tournamentServerUrl: 'http://141.37.123.132:8086' }; diff --git a/src/environments/environment.staging.ts b/src/environments/environment.staging.ts index 208ecbe..b6eb936 100644 --- a/src/environments/environment.staging.ts +++ b/src/environments/environment.staging.ts @@ -8,5 +8,6 @@ export const environment = { accountServiceUrl: runtimeConfig.apiUrl || 'https://st.nowchess.janis-eccarius.de', wsBaseUrl: runtimeConfig.wsUrl || 'wss://st.nowchess.janis-eccarius.de', userWsBaseUrl: runtimeConfig.wsUrl || 'wss://st.nowchess.janis-eccarius.de', - apiPath: '/api/board/game' + apiPath: '/api/board/game', + tournamentServerUrl: 'http://141.37.123.132:8086' }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 58d8445..f31511f 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -8,5 +8,6 @@ export const environment = { accountServiceUrl: runtimeConfig.apiUrl || '', wsBaseUrl: runtimeConfig.wsUrl, userWsBaseUrl: runtimeConfig.wsUrl, - apiPath: '/api/board/game' + apiPath: '/api/board/game', + tournamentServerUrl: 'http://141.37.123.132:8086' };