RoomClient: rtt property

Available since @irtio/client 5.0BrowsersNode

The rtt read-only property of the RoomClient interface is the round-trip time to the room, in milliseconds, the smallest of the client’s recent pings.

Value

A number of milliseconds. It’s 0 until the room first answers a ping.

Description

The client pings the room three times 100 ms apart after each connection is accepted, then every 2 seconds, or every 15 seconds while the room sleeps. rtt is the smallest round trip of the last 8 pings, so a single slow ping doesn’t move it; jitter says how much they vary. serverTick() and serverTime() are estimated from the same ping.

The client reports its rtt in each ping, and the room reads it as connection.rtt.

Examples

Showing the ping

The game shows the round trip in the corner of the screen, refreshed once a second, in green, yellow or red.

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

export function showPing(room: RoomClient, label: HTMLElement): void {
  setInterval(() => {
    const ms = Math.round(room.rtt);
    label.textContent = `${ms} ms`;
    label.className = ms < 80 ? "good" : ms < 160 ? "fair" : "poor";
  }, 1000);
}

See also

Runtime availability

BrowsersNode
rtt5.05.0