feat: api for server could be wrong

This commit is contained in:
shahdlala66
2026-06-23 09:37:21 +02:00
parent 8728817231
commit aeca003191
6 changed files with 40 additions and 9 deletions
@@ -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),
@@ -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 {
+13 -4
View File
@@ -4,12 +4,21 @@ import { GameStreamEvent, TournamentStreamEvent } from '../models/tournament.mod
@Injectable({ providedIn: 'root' })
export class TournamentStreamService {
streamTournament(tournamentId: string): Observable<TournamentStreamEvent> {
return this.ndjson<TournamentStreamEvent>(`/api/tournament/${tournamentId}/stream`);
streamTournament(serverUrl: string, tournamentId: string): Observable<TournamentStreamEvent> {
return this.ndjson<TournamentStreamEvent>(
this.url(serverUrl, `/api/tournament/${tournamentId}/stream`)
);
}
streamGame(tournamentId: string, gameId: string): Observable<GameStreamEvent> {
return this.ndjson<GameStreamEvent>(`/api/tournament/${tournamentId}/game/${gameId}/stream`);
streamGame(serverUrl: string, tournamentId: string, gameId: string): Observable<GameStreamEvent> {
return this.ndjson<GameStreamEvent>(
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<T>(url: string): Observable<T> {
+2 -1
View File
@@ -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'
};
+2 -1
View File
@@ -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'
};
+2 -1
View File
@@ -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'
};