UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

74 lines 2.64 kB
export class Channel { /** * @param {{ * transport: { send(bytes: Uint8Array, length: number): void, onReceive: Signal }, * }} options */ constructor({ transport }: { transport: { send(bytes: Uint8Array, length: number): void; onReceive: Signal; }; }); /** * @type {{ send(bytes: Uint8Array, length: number): void, onReceive: Signal }} */ transport: { send(bytes: Uint8Array, length: number): void; onReceive: Signal; }; /** * Fired when an outgoing seq has been positively acknowledged by the peer. * @type {Signal} */ onPacketAcked: Signal; /** * Fired when an outgoing seq has aged out of the ack window without being acked. * @type {Signal} */ onPacketLost: Signal; /** * Fired when an inbound packet's payload is ready (header already stripped). * Handler args: (payload: Uint8Array starting at offset 0, length: number). * The Uint8Array is owned by the Channel and may be reused after the handler returns. * @type {Signal} */ onPayload: Signal; /** * Wrap and send a payload. Returns the seq number assigned to it. * * @param {Uint8Array} payload * @param {number} length payload length in bytes * @returns {number} seq */ send(payload: Uint8Array, length: number): number; /** * Number of outgoing packets sent but not yet acked or marked lost. * @returns {number} */ unacked_count(): number; /** * Most recent seq received from the peer, or -1 if none yet. * @returns {number} */ latest_received_seq(): number; /** * Test-only: seed the next outgoing seq number. Used to fast-forward * the seq counter so the seq16 wraparound can be exercised in * unit tests without sending 65k packets. Do not call from production. * @param {number} seq */ seed_outgoing_seq_for_testing(seq: number): void; /** * Detach this Channel from its transport. The transport.onReceive subscription * is removed so the Channel stops processing inbound bytes; the Channel's own * Signals are left in place (callers usually hold no references to them after * dispose, so they GC with the Channel). Required before discarding a Channel * whose transport will be reused — otherwise the old Channel keeps consuming * inbound packets in parallel with whatever replaces it. */ dispose(): void; #private; } import Signal from "../../../core/events/signal/Signal.js"; //# sourceMappingURL=Channel.d.ts.map