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:
@@ -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 });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user