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:
@@ -1,5 +1,5 @@
|
||||
import { io, Socket } from 'socket.io-client';
|
||||
import type { ServerEvents, ClientEvents, WorldState, StateUpdate, PlayerJoined, PlayerLeft, PlayerInput } from '@dflike/shared';
|
||||
import type { ServerEvents, ClientEvents, WorldState, StateUpdate, PlayerJoined, PlayerLeft, PlayerInput, NarrationEvent } from '@dflike/shared';
|
||||
|
||||
type TypedSocket = Socket<ServerEvents, ClientEvents>;
|
||||
|
||||
@@ -13,6 +13,9 @@ export class SocketClient {
|
||||
onStateUpdate: ((data: StateUpdate) => void) | null = null;
|
||||
onPlayerJoined: ((data: PlayerJoined) => void) | null = null;
|
||||
onPlayerLeft: ((data: PlayerLeft) => void) | null = null;
|
||||
onNarrationEvent: ((data: NarrationEvent) => void) | null = null;
|
||||
onNarrationUpdate: ((data: { id: number; narration: string }) => void) | null = null;
|
||||
onNarrationHistory: ((data: NarrationEvent[]) => void) | null = null;
|
||||
|
||||
constructor(url: string) {
|
||||
this.socket = io(url);
|
||||
@@ -36,6 +39,10 @@ export class SocketClient {
|
||||
this.socket.on('player-left', (data) => {
|
||||
this.onPlayerLeft?.(data);
|
||||
});
|
||||
|
||||
this.socket.on('narration-event', (data) => this.onNarrationEvent?.(data));
|
||||
this.socket.on('narration-update', (data) => this.onNarrationUpdate?.(data));
|
||||
this.socket.on('narration-history', (data) => this.onNarrationHistory?.(data));
|
||||
}
|
||||
|
||||
get playerId(): string | null { return this._playerId; }
|
||||
|
||||
Reference in New Issue
Block a user