WireStats: sent property

Available since @irtio/client 5.0BrowsersNode

The sent read-only property of the WireStats interface counts the messages and bytes the client has sent since it was created, by client message type.

Value

An object whose keys are client message types and whose values are objects with these properties:

messages
The number of messages of the type sent.
bytes
Their total size in bytes.

A type is a key once the client has sent a message of it. The types include input, or typedInput with a schema’s input kind, ping, write (owner writes), message, unreliable, call and hello.

Description

sent.input.bytes is what prediction inputs have cost, and the sum over every type is bytesOut.

Examples

Comparing input encodings

The client logs the average size of an input message, to compare JSON inputs with a schema’s input kind.

// input-size.ts
import type { ReadyRoomClient } from "@irtio/client";

export function inputSize(room: ReadyRoomClient) {
  const inputs = room.stats.sent.typedInput ?? room.stats.sent.input;
  if (!inputs) console.log("no inputs sent");
  else console.log(`${(inputs.bytes / inputs.messages).toFixed(1)} bytes an input message`);
}

Each input message repeats the last 4 inputs, so a single lost message loses no input, and its size is that of up to 4 inputs.

See also

Runtime availability

BrowsersNode
sent5.05.0