@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
59 lines • 2.14 kB
TypeScript
/**
* In-process Transport pair for tests and tooling.
*
* Two `LoopbackTransport` instances are paired via {@link bind_pair}. Calls to
* `send` on one place a copy of the bytes into the peer's inbound queue, where
* they sit until {@link deliver_all} is called. This gives tests precise control
* over packet timing — no hidden setTimeout, no real network.
*
* Wire-condition simulation is offered as deterministic helpers
* ({@link drop_next}, {@link reorder}) rather than randomized parameters; tests
* are easier to write and reproduce when they pick which packet to drop, not
* "5% of packets". Random conditions can be layered on top by the test if needed.
*
* Each `send` copies the bytes (because the caller may reuse the source buffer
* immediately). Pool-based optimization is reasonable later but not necessary
* for correctness.
*
* @author Alex Goldring
* @copyright Company Named Limited (c) 2025
*/
export class LoopbackTransport extends Transport {
/**
* Bind two LoopbackTransports together so they deliver to each other.
*
* @param {LoopbackTransport} a
* @param {LoopbackTransport} b
*/
static bind_pair(a: LoopbackTransport, b: LoopbackTransport): void;
/**
* Deliver every packet in the inbound queue to {@link onReceive}, in order.
* Updates inbound stats. Returns the number of packets delivered.
*
* @returns {number}
*/
deliver_all(): number;
/**
* Drop the next `n` queued inbound packets (simulates packet loss).
* If fewer than `n` are queued, drops what's available.
*
* @param {number} n
* @returns {number} actual number dropped
*/
drop_next(n: number): number;
/**
* Swap two queued inbound packets by index (simulates reorder).
*
* @param {number} i
* @param {number} j
*/
reorder(i: number, j: number): void;
/**
* Number of packets currently waiting to be delivered.
* @returns {number}
*/
queued_count(): number;
#private;
}
import { Transport } from "./Transport.js";
//# sourceMappingURL=LoopbackTransport.d.ts.map