RoomClient: tickRate property
@irtio/client 5.0BrowsersNodeThe tickRate read-only property of the RoomClient interface is how many ticks the room runs per second.
Value
A number: the room’s tick rate, or 0 in a room without ticks. It’s also 0 until the router accepts the first connection.
Description
The client counts time in the room’s ticks: serverTick(), predict() and interpolate() all do. In a room without ticks they throw an IrtError named InvalidStateError, and serverTime() is the room’s clock instead. Before the first connection is accepted, the client can’t tell, so they don’t throw.
Owner writes go to the room at most once per tick in a room with ticks. In a room without ticks they go at the end of the task that made them, and a burst of them at most once every 16 ms.
Examples
Converting ticks to seconds
The room keeps the tick its round ends at, and the client shows the seconds left from the room’s estimated tick.
// time-left.ts
import { connect, defineSchema, entity } from "@irtio/client";
const Round = entity("round", { endsAt: "u32" });
const room = await connect("main", { schema: defineSchema({ state: Round }) });
export function secondsLeft(): number {
if (room.tickRate === 0) return 0;
return Math.max(0, (room.state.endsAt - room.serverTick()) / room.tickRate);
}
See also
Runtime availability
| Browsers | Node | |
|---|---|---|
tickRate | 5.0 | 5.0 |