Interface ClientToServerBase

Messages that clients send, regardless of target server

interface ClientToServerBase {
    authenticate: ((data) => undefined | {
        id: number;
        username: string;
    });
    net/connects: ((data) => void);
    net/ping: ((data) => void);
    net/route_latency: ((data) => void);
    net/timeout: ((data) => void);
    net/unrecoverable_error: ((data) => void);
}

Hierarchy (view full)

Properties

authenticate: ((data) => undefined | {
    id: number;
    username: string;
})

Authenticate with the server.

Prior to authentication, you should perform a GET request to /api/v1/ui/config to get the current configuration. Within the returned JSON you will find all of the necessary fields to authenticate.

Type declaration

    • (data): undefined | {
          id: number;
          username: string;
      }
    • Parameters

      • data: {
            bot_apikey?: string;
            bot_username?: string;
            client?: string;
            client_version?: string;
            device_id?: string;
            jwt: string;
            language?: string;
            language_version?: string;
            user_agent?: string;
        }
        • Optional bot_apikey?: string

          Bot API key, if applicable

        • Optional bot_username?: string

          Bot username connecting, if applicable

        • Optional client?: string

          Client name (your application name)

        • Optional client_version?: string

          Client version string.

        • Optional device_id?: string

          Client generated unique id for the device.

        • jwt: string

          The JSON Web Token (user_jwt field) from /api/v1/ui/config. If connecting as a guest, send ""

        • Optional language?: string

          ISO 639-1 language code used on this device.

        • Optional language_version?: string

          The version of the translation dictionary.

        • Optional user_agent?: string

          Browser user agent (or websocket library)

      Returns undefined | {
          id: number;
          username: string;
      }

net/connects: ((data) => void)

Report connection count and device info for analytics. Sent on each (re)connect to track route reliability.

Type declaration

    • (data): void
    • Parameters

      • data: {
            device_info: DeviceInfo;
            previous_connection_duration_ms: number;
            route: string;
            times_connected: number;
        }
        • device_info: DeviceInfo

          Device information for analytics segmentation

        • previous_connection_duration_ms: number

          Duration in ms of the previous connection, or 0 if first connect

        • route: string

          Network route name (e.g. "cloudflare", "google", "public")

        • times_connected: number

          How many times the client has connected this session

      Returns void

net/ping: ((data) => void)

Sends a ping to the server. This message should be sent regularly. The default interval is 10 seconds. This keeps the connection alive and allows a client to measure clock drift and latency, both of which are vital to adjusting the client's game clock displays.

Type declaration

    • (data): void
    • Parameters

      • data: {
            client: number;
            drift: number;
            latency: number;
        }
        • client: number

          Client timestamp - milliseconds since epoch

        • drift: number

          Last clock drift measurement, or 0

        • latency: number

          Last latency measurement, or 0

      Returns void

net/route_latency: ((data) => void)

Report measured latency for a specific network route

Type declaration

    • (data): void
    • Parameters

      • data: {
            latency: number;
            mobile: boolean;
            route: string;
        }
        • latency: number

          Measured latency in milliseconds

        • mobile: boolean

          Whether the client is on a mobile device

        • route: string

          Network route name

      Returns void

net/timeout: ((data) => void)

Report a ping timeout event for diagnostics. Sent when the client detects that a ping response (pong) was not received within the expected timeout window.

Type declaration

    • (data): void
    • Parameters

      • data: {
            device_info: DeviceInfo;
            in_live_game: boolean;
            latency: number;
            ping_interval: number;
            route: string;
            timeout_delay: number;
            times_connected: number;
        }
        • device_info: DeviceInfo

          Device information

        • in_live_game: boolean

          Whether the client is currently viewing their own live game

        • latency: number

          Last measured latency before timeout (ms)

        • ping_interval: number

          Ping interval at time of timeout (ms)

        • route: string

          Network route name (e.g. "cloudflare", "google", "public")

        • timeout_delay: number

          Timeout delay threshold that was exceeded (ms)

        • times_connected: number

          How many times the client has connected this session

      Returns void

net/unrecoverable_error: ((data) => void)

Report an unrecoverable WebSocket error (e.g. close code 1014/1015)

Type declaration

    • (data): void
    • Parameters

      • data: {
            code: number;
            device_info: DeviceInfo;
            route: string;
            tag: string;
            times_connected: number;
        }
        • code: number

          WebSocket close code

        • device_info: DeviceInfo

          Device information

        • route: string

          Network route name

        • tag: string

          Error tag for categorization

        • times_connected: number

          Connection count at time of error

      Returns void