couch-kit
    Preparing search index...

    Function useServerTime

    • React hook that synchronizes the client clock with the host server.

      Periodically sends PING messages over the WebSocket and processes PONG responses to estimate the clock offset and round-trip time.

      This hook is used internally by useGameClient and does not need to be called directly. Access getServerTime() and rtt from the useGameClient return value instead.

      Parameters

      • socket: WebSocket | null

        The active WebSocket connection (or null if not yet connected).

      Returns {
          getServerTime: () => number;
          handlePong: (
              payload: { id: string; origTimestamp: number; serverTime: number },
          ) => void;
          rtt: number;
      }

      An object with getServerTime (returns estimated server time), rtt, and handlePong (callback for PONG messages).