Add ServerState support in ChatService with SSE listener and associated data model

This commit is contained in:
akastijn 2026-08-09 00:48:17 +02:00
parent 65d0118e3d
commit 2705cf14ab
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,14 @@
export interface User {
uuid: string;
name: string;
styledName: string;
}
export interface Server {
name: string;
players: User[];
}
export interface ServerState {
servers: Server[];
}

View File

@ -8,6 +8,7 @@ import {precomputeNode} from '@pages/altitude/chat/mini-message/mini-message.uti
import {ChatChannel} from '@pages/altitude/chat/objects/chat-channel.object';
import {NotificationService} from '@pages/altitude/chat/service/chat-notification.service';
import {ChatInfoService} from '@api';
import {ServerState} from '@pages/altitude/chat/objects/server-state.object';
interface SsePayloadEvent {
data: string;
@ -24,6 +25,8 @@ export class ChatService implements OnDestroy {
public readonly channels = computed(() => this._channels().sort((a, b) => a.name.localeCompare(b.name)));
private readonly _selectedChannel = signal<ChatChannel | null>(null);
public readonly selectedChannel = this._selectedChannel.asReadonly()
private readonly _serverState = signal<ServerState | null>(null);
public readonly serverState = this._serverState.asReadonly();
public readonly partieMap = signal<Map<string, string>>(new Map());
public readonly userNameMap = signal<Map<string, string>>(new Map());
private readonly pendingPartyNameRequests = new Set<string>();
@ -78,6 +81,11 @@ export class ChatService implements OnDestroy {
});
});
this.on(source, 'server-state', (event) => {
const state = JSON.parse(event.data) as ServerState;
this._serverState.set(state);
});
source.onerror = (err) => {
console.error('SSE error, polyfill will auto-reconnect:', err);
};