feat: add socket.io events for narration broadcast

Wire narration events through the socket layer so clients receive
real-time narration updates. Server emits narration-event on creation,
narration-update when LLM text arrives, and narration-history on connect.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-08 18:14:50 +00:00
parent 78c8dbfb7f
commit 57695043f2
3 changed files with 25 additions and 1 deletions
+13
View File
@@ -26,6 +26,16 @@ export class SocketServer {
const update = serializeStateUpdate(this.gameLoop.world, this.gameLoop.getTick(), this.gameLoop.getGameTime());
this.io.emit('state-update', update);
});
const narrationService = this.gameLoop.narrationService;
narrationService.onEventCreated = (event) => {
this.io.emit('narration-event', event);
};
narrationService.onEventUpdated = (event) => {
this.io.emit('narration-update', { id: event.id, narration: event.narration });
};
}
private setupConnections(): void {
@@ -51,6 +61,9 @@ export class SocketServer {
socket.emit('world-state', serializeWorldState(world, map));
socket.emit('player-joined', { playerId, entityId: entity });
// Send narration history
socket.emit('narration-history', this.gameLoop.narrationService.getRecentEvents());
// Notify others
socket.broadcast.emit('player-joined', { playerId, entityId: entity });