WireStats: bytesIn property

Available since @irtio/client 5.0BrowsersNode

The bytesIn property of the WireStats interface is the total size, in bytes, of the protocol messages the client has received since it was created, across reconnects.

Value

A number of bytes, from 0. Sizes are of protocol messages as encoded, without the transport’s own framing, such as a WebSocket frame header.

Examples

Warning about a heavy room

A client warns in the console once the room has sent it more than 5 MB, a sign that its interest sends too much.

// heavy-room.ts
import type { ReadyRoomClient } from "@irtio/client";

export function warnWhenHeavy(room: ReadyRoomClient) {
  const watching = new AbortController();
  room.addEventListener(
    "update",
    () => {
      if (room.stats.bytesIn <= 5 * 1024 * 1024) return;
      console.warn(`received ${room.stats.bytesIn} bytes so far`);
      watching.abort();
    },
    { signal: watching.signal },
  );
}

See also

Runtime availability

BrowsersNode
bytesIn5.05.0