fix: NCWF-1 401 (#6)

Co-authored-by: shahdlala66 <shahd.lala66@gmail.com>
Co-authored-by: Lala, Shahd <Shahd.Lala@sybit.de>
Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
2026-05-13 00:01:26 +02:00
parent ac4fe8b005
commit 6d1e06dfd6
4 changed files with 58 additions and 36 deletions
+17 -7
View File
@@ -10,6 +10,7 @@ export class GameStreamService {
private readonly destroyRef = inject(DestroyRef);
private streamSubscription: Subscription | null = null;
private pollSubscription: Subscription | null = null;
private lastGameStateHash: string | null = null;
startStreaming(
gameId: string,
@@ -20,7 +21,10 @@ export class GameStreamService {
.streamGame(gameId)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe({
next: (event) => onEvent(event),
next: (event) => {
this.lastGameStateHash = JSON.stringify(event);
onEvent(event);
},
error: () => {
onStreamError();
this.startPolling(gameId, onEvent);
@@ -37,7 +41,7 @@ export class GameStreamService {
return;
}
this.pollSubscription = interval(1500)
this.pollSubscription = interval(5000)
.pipe(
startWith(0),
switchMap(() => this.gameApi.getGame(gameId)),
@@ -45,11 +49,16 @@ export class GameStreamService {
)
.subscribe({
next: (game) => {
const event: GameStreamEvent = {
type: 'gameFull',
game
};
onEvent(event);
// Only emit if game state changed to avoid unnecessary updates
const stateHash = JSON.stringify(game.state);
if (this.lastGameStateHash !== stateHash) {
this.lastGameStateHash = stateHash;
const event: GameStreamEvent = {
type: 'gameFull',
game
};
onEvent(event);
}
}
});
}
@@ -59,5 +68,6 @@ export class GameStreamService {
this.pollSubscription?.unsubscribe();
this.streamSubscription = null;
this.pollSubscription = null;
this.lastGameStateHash = null;
}
}