Connection: rtt property

Available since @irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room host

The rtt read-only property of the Connection interface is the client’s lowest recent round trip to the room, in milliseconds, as the client reports it in its pings.

Value

A number of milliseconds, or undefined until the client’s first ping, and always for a client older than protocol 3.

Description

The client measures rtt and reports it, so a client can lie about it, as about its view tick. Cap whatever a game gives for it, such as the extra time a rhythm hit is judged with.

Examples

Widening a rhythm game’s hit window, up to a cap

// rhythm.ts
import { defineRoom } from "@irtio/room";

const WINDOW_MS = 60;
const MAX_ALLOWANCE_MS = 80;

export default defineRoom({
  data: () => ({ beatAt: 0 }),
  onMessage(room, connection, message) {
    if (message !== "hit") return;
    const allowance = Math.min((connection.rtt ?? 0) / 2, MAX_ALLOWANCE_MS);
    const off = Math.abs(room.now() - allowance - room.data.beatAt);
    room.send(connection, { type: "judged", good: off <= WINDOW_MS });
  },
});

See also

Runtime availability

Hosted roomsirt dev@irtio/testingSelf-hosted room host
rtt0.10.10.10.1