RoomClient: tick property

Available since @irtio/client 5.0BrowsersNode

The tick read-only property of the RoomClient interface is the room tick of the last state update the client applied.

Value

A number. It’s 0 in a room without ticks, and before the first state update.

Description

The room sends a state update only when something this client sees changed, so tick stays put while nothing changes, and it’s always behind the room’s own room.tick. For the room’s current tick, use serverTick().

The fields of state and every other entity are as the room had them at tick.

Examples

Showing how old the view is

The difference between the room’s estimated tick and the last update’s tick is how far behind the room the client’s entities are.

// staleness.ts
import type { RoomClient } from "@irtio/client";

export function viewAge(room: RoomClient): string {
  if (room.tickRate === 0) return "no ticks";
  const ticks = room.serverTick() - room.tick;
  return `${Math.round((ticks * 1000) / room.tickRate)} ms behind`;
}

See also

Runtime availability

BrowsersNode
tick5.05.0