WireStats: lastUpdate property

Available since @irtio/client 5.0BrowsersNode

The lastUpdate property of the WireStats interface describes the last whole state update the client applied: its number and tick, the messages it was split into, their size and whether it was full.

Value

An object with these properties, or undefined until the client applies its first state update:

update
The update number.
tick
The update’s tick, or 0 in a room without ticks.
parts
The number of messages the update was split into, each holding at most about 60 KB.
bytes
The size of those messages together, as sent, compressed or not.
full
A boolean: true for a full update, as on joining or on a reconnect that couldn’t resume, and false for a delta.

Description

The room sends a client a state update only when something it sees changed, so a flush that sent the client nothing leaves lastUpdate as it was. Read it in an update event listener to see each update’s size.

Examples

Logging large deltas

The client logs any delta over 4 KB, the updates that most often show an interest that sends too much.

// big-deltas.ts
import type { ReadyRoomClient } from "@irtio/client";

export function logBigDeltas(room: ReadyRoomClient) {
  room.addEventListener("update", () => {
    const last = room.stats.lastUpdate;
    if (last && !last.full && last.bytes > 4096) console.warn(`tick ${last.tick}: ${last.bytes} bytes in ${last.parts} parts`);
  });
}

See also

Runtime availability

BrowsersNode
lastUpdate5.05.0