[]previous and next page

FrameReader

Reads the frames a peer sends.

Reads the frames a peer sends. Feed it the bytes as they arrive; it returns the events they complete and keeps the rest. A violation throws a WebSocketProtocolError; the reader must not be used after that.

Import#

ts
import { FrameReader } from "@shadow-js/dusk/server";

Signature#

ts
class FrameReader

Members#

Name Type Description
bufferedBytes get bufferedBytes(): number Bytes received that no event has used yet.
push push(chunk: Uint8Array): WsEvent[] Adds bytes and returns the events they complete, in order.

Examples#

ts
const reader = new FrameReader({ maxMessageBytes: 1 << 20, requireMask: true });
for (const event of reader.push(chunk)) if (event.kind === "text") handle(event.data);