UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

58 lines 1.97 kB
/** * Holds inbound payloads keyed by frame number, releasing them only after they * have aged enough that the consumer has high confidence ordering is settled. * * The delay (`delay_frames`) is the cost we pay to absorb arrival jitter. A * larger delay smooths over more jitter but adds visible latency; the canonical * choice is `~3 * snapshot_interval + small slack` (Glenn Fiedler). * * Generic over payload type — the buffer treats payloads as opaque blobs to * pass through. Common payload types: `Uint8Array` (raw packet), `BinaryBuffer`, * deserialized action records. * * @author Alex Goldring * @copyright Company Named Limited (c) 2025 */ export class JitterBuffer { /** * @param {{ delay_frames?: number }} [options] */ constructor({ delay_frames }?: { delay_frames?: number; }); /** @readonly @type {number} */ readonly delay_frames: number; /** * Insert a payload tagged with its source frame number. Inserts in * frame-sorted order so {@link drain_until} can scan from the front. * * @param {number} frame * @param {*} payload */ push(frame: number, payload: any): void; /** * Release every payload whose frame is `<= current_frame - delay_frames`. * Callback receives `(frame, payload)` in frame-ascending order. * * @param {number} current_frame * @param {function(number, *): void} callback * @returns {number} number of payloads released */ drain_until(current_frame: number, callback: (arg0: number, arg1: any) => void): number; /** * Discard everything in the buffer (e.g. on disconnect). */ clear(): void; /** * Number of payloads currently held. * @returns {number} */ size(): number; /** * Frame of the oldest payload, or `-1` if empty. * @returns {number} */ earliest_frame(): number; #private; } //# sourceMappingURL=JitterBuffer.d.ts.map