import { F as FireworkKind, a as FireworkLaunchPayload } from '../../types-DBVDr8Mu.js';

interface FireworksUserIdentity {
    userId: string;
    nickname?: string;
    avatarUrl?: string;
}
interface DanmakuBroadcastEvent {
    id: string;
    roomId: string;
    text: string;
    color?: string;
    kind?: FireworkKind;
    user: FireworksUserIdentity;
    timestamp: number;
}
interface FireworkBroadcastEvent {
    id: string;
    roomId: string;
    payload: FireworkLaunchPayload;
    user: FireworksUserIdentity;
    timestamp: number;
}
type FireworksClientMessage = {
    type: 'join';
    roomId: string;
    user: FireworksUserIdentity;
} | {
    type: 'leave';
} | {
    type: 'danmaku.send';
    payload: {
        text: string;
        color?: string;
        kind?: FireworkKind;
    };
} | {
    type: 'firework.launch';
    payload: FireworkLaunchPayload;
} | {
    type: 'ping';
    ts?: number;
};
type FireworksServerMessage = {
    type: 'joined';
    roomId: string;
    self: FireworksUserIdentity;
    onlineCount: number;
} | {
    type: 'room.snapshot';
    roomId: string;
    users: FireworksUserIdentity[];
    danmakuHistory: DanmakuBroadcastEvent[];
    fireworkHistory: FireworkBroadcastEvent[];
} | {
    type: 'room.user_joined';
    roomId: string;
    user: FireworksUserIdentity;
    onlineCount: number;
} | {
    type: 'room.user_left';
    roomId: string;
    userId: string;
    onlineCount: number;
} | {
    type: 'danmaku.broadcast';
    roomId: string;
    event: DanmakuBroadcastEvent;
} | {
    type: 'firework.broadcast';
    roomId: string;
    event: FireworkBroadcastEvent;
} | {
    type: 'pong';
    ts: number;
} | {
    type: 'error';
    code: string;
    message: string;
};
interface FireworksConnectionTransport {
    send: (encodedMessage: string) => void;
    close?: (code?: number, reason?: string) => void;
}
interface FireworksConnection {
    id: string;
    handleMessage: (raw: unknown) => void;
    disconnect: (reason?: string) => void;
    send: (message: FireworksServerMessage) => void;
}
interface FireworksRoomHubOptions {
    maxUsersPerRoom?: number;
    historyLimit?: number;
    maxDanmakuLength?: number;
    logger?: Pick<Console, 'info' | 'warn' | 'error'>;
}
interface FireworksHubStats {
    rooms: number;
    connections: number;
}
interface WsLikeSocket {
    send: (data: string) => void;
    on: (event: 'message' | 'close' | 'error', listener: (...args: unknown[]) => void) => void;
}

declare class FireworksRoomHub {
    private readonly rooms;
    private readonly sessions;
    private readonly maxUsersPerRoom;
    private readonly historyLimit;
    private readonly maxDanmakuLength;
    private readonly logger?;
    constructor(options?: FireworksRoomHubOptions);
    connect(transport: FireworksConnectionTransport, id?: string): FireworksConnection;
    disconnect(connectionId: string, reason?: string): void;
    getStats(): {
        rooms: number;
        connections: number;
    };
    getRoomOnlineCount(roomId: string): number;
    private handleRawMessage;
    private joinRoom;
    private leaveRoom;
    private handleDanmaku;
    private handleFirework;
    private createRoom;
    private sendToConnection;
    private broadcastToRoom;
    private sendError;
}

interface BindWsSocketOptions {
    connectionId?: string;
    onConnected?: (connection: FireworksConnection) => void;
    onDisconnected?: (connectionId: string) => void;
}
/**
 * Bind a ws-like socket to FireworksRoomHub.
 *
 * Example (ws package):
 * const hub = new FireworksRoomHub();
 * wss.on('connection', (socket) => bindWsSocket(hub, socket));
 */
declare function bindWsSocket(hub: FireworksRoomHub, socket: WsLikeSocket, options?: BindWsSocketOptions): FireworksConnection;

export { type BindWsSocketOptions, type DanmakuBroadcastEvent, type FireworkBroadcastEvent, type FireworksClientMessage, type FireworksConnection, type FireworksConnectionTransport, type FireworksHubStats, FireworksRoomHub, type FireworksRoomHubOptions, type FireworksServerMessage, type FireworksUserIdentity, type WsLikeSocket, bindWsSocket };
