ClockSyncStats: {
    bestRtt: number;
    frozen: boolean;
    offset: number;
    rtt: number;
    samples: number;
}

Clock synchronization between clients and the authoritative server.

Every client periodically sends a ping stamped with its own clock; the server answers with a pong that echoes that stamp and adds its own clock; the client acknowledges with the server stamp so the server can measure the round trip too. From each pong the client derives the round-trip time and a clock offset (server minus local at the midpoint of the trip). The offset with the lowest round trip in a rolling window wins, because a fast trip is the least distorted by queueing.

Scenes read getServerTime() for a clock every participant agrees on, and the server reads getPlayerLatency() to bound how early a client can claim an input happened.

Type declaration

  • bestRtt: number

    Lowest round trip among the samples the offset was picked from.

  • frozen: boolean

    True while the offset is held fixed (see freeze).

  • offset: number

    Estimated server clock minus local clock, in milliseconds.

  • rtt: number

    Latest measured round trip, in milliseconds.

  • samples: number

    Number of samples in the window.