UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

73 lines 2.81 kB
/** * Transport adapter over a browser `WebTransport` connection, using the * unreliable/unordered **datagram** channel — the moral equivalent of * UDP, exposed over HTTP/3. * * Properties: * - Authenticated by TLS (https:// origin required by the API). * - No head-of-line blocking, unlike WebSocket-over-TCP. * - Datagrams have a per-implementation MTU (typically 1200 bytes * after framing); larger payloads should go through the engine's * fragment-send machinery as with any UDP-style transport. * * For reliable / ordered traffic (chat, room state, file transfer) * the same `WebTransport` exposes bidirectional streams. This adapter * does not surface them; build a separate stream-mode transport if * needed, or use {@link WebSocketTransport} for that traffic. * * The `WebTransport` global is browser-only and requires a relatively * recent runtime (Chromium 97+, Firefox 114+). Server-side, an HTTP/3 * server is required (e.g. `quiche-py`, `aioquic`, or a dedicated * WebTransport library — out of scope for the engine). * * Either pass a pre-constructed `wt` instance (useful for tests via * a mock) or pass `url` + optional `options` and let the adapter * construct it. * * @author Alex Goldring * @copyright Company Named Limited (c) 2025 */ export class WebTransportTransport extends Transport { /** * @param {{ wt?: object, url?: string, options?: object }} params */ constructor({ wt, url, options }?: { wt?: object; url?: string; options?: object; }); /** * The underlying `WebTransport` instance. Exposed for callers * that need to access stream-mode APIs or attach lifecycle * listeners (`.closed`, `.draining`). * @type {object} */ wt: object; /** * Fires when `writer.write()` rejects but the underlying * connection is still open — typically transient backpressure * (writer queue full / slow consumer). Distinct from * `onDisconnect`, which fires only on the actual `wt.closed` * settlement (clean close or abrupt error). Callers can * subscribe to throttle their send rate, drop optional traffic, * or surface a warning. * * If you don't care, ignore — sends remain fire-and-forget and * a dropped packet is no different from a UDP datagram lost on * the network. * * @type {Signal} */ onSendDropped: Signal; /** * Await `wt.ready`, acquire the datagram writer and reader, and * start the receive loop. Idempotent. * * @returns {Promise<void>} */ connect(): Promise<void>; #private; } import { Transport } from "../Transport.js"; import Signal from "../../../../core/events/signal/Signal.js"; //# sourceMappingURL=WebTransportTransport.d.ts.map