/** * Realtime traffic metrics — SDK-owned counters for every spatial message the * client sends (the `client.udp.send*` mutations, including the ones issued * internally by the World Stores layers) and every notification delivered on * the shared `udpNotifications` subscription. * * Exposed as `client.metrics`; call {@link RealtimeMetrics.snapshot} from a * HUD/diagnostics loop. Byte counts measure the app-defined **payload** field * of each message (`state` / `audioData` / `text` / `payload` / `voxelState`), * not wire framing or GraphQL envelope overhead. */ /** Counter pair tracked per direction and per message kind. */ export interface RealtimeMetricsCounters { /** Number of messages. */ messages: number; /** Total payload bytes (see module docs for what "payload" means). */ bytes: number; } /** Per-kind counters for one message kind (e.g. `actorUpdate`, `audio`). */ export interface RealtimeMetricsKind { sent: RealtimeMetricsCounters; received: RealtimeMetricsCounters; } /** The result of {@link RealtimeMetrics.snapshot}. */ export interface RealtimeMetricsSnapshot { /** Cumulative counters since construction or the last {@link RealtimeMetrics.reset}. */ totals: { sent: number; received: number; bytesSent: number; bytesReceived: number; }; /** * Cumulative counters broken down by message kind. Sent kinds use the send * method's message name (`actorUpdate`, `voxelUpdate`, `audio`, `text`, * `clientEvent`, `singleActorMessage`, `channelMessage`); received kinds use * the notification handler names (`actorUpdate`, `voxelUpdate`, `audio`, * `text`, `clientEvent`, `serverEvent`, `singleActorMessage`, * `channelMessage`, `genericError`, `connectionEvent`, ...). */ perKind: Record; /** Rates averaged over the sliding window (~10 s). */ rates: { sentPerSecond: number; receivedPerSecond: number; bytesSentPerSecond: number; bytesReceivedPerSecond: number; }; /** Epoch milliseconds when tracking began (construction or last reset). */ startedAt: number; } /** * Counter store behind `client.metrics`. All methods are cheap (plain counter * increments and a fixed ring of per-second rate buckets), so recording on * every message adds no meaningful overhead to the send/receive hot paths. */ export declare class RealtimeMetrics { private readonly now; private readonly buckets; private readonly perKind; private totalSent; private totalReceived; private totalBytesSent; private totalBytesReceived; private startedAtMs; /** @param now - Clock override for tests. Defaults to `Date.now`. */ constructor(now?: () => number); /** Record one outbound message. Called by the SDK's `udp.send*` methods. */ recordSent(kind: string, payloadBytes: number): void; /** Record one delivered notification. Called by the realtime dispatch. */ recordReceived(kind: string, payloadBytes: number): void; /** * A point-in-time copy of all counters plus rates averaged over the sliding * window. Safe to call every frame; allocation is proportional to the number * of distinct message kinds. */ snapshot(): RealtimeMetricsSnapshot; /** Zero every counter and restart the rate window. */ reset(): void; private kindEntry; private bucket; } /** * The size of a message's app-defined payload field: the first of `state`, * `audioData`, `text`, `payload`, or `voxelState` present as a string. Base64 * and ASCII payloads measure 1 byte per character; multi-byte UTF-8 text is * approximated by its UTF-16 length. */ export declare function payloadBytesOf(record: Record): number; //# sourceMappingURL=metrics.d.ts.map