{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Ably Connections Client Event",
  "type": "object",
  "description": "A message sent on the clientEvents:connections metachannel describing a sampled client connection.",
  "properties": {
    "host": {
      "type": "string",
      "description": "The HTTP Host header of the connection request."
    },
    "requestId": {
      "type": "string",
      "description": "The unique ID of the connection request that Ably can use to correlate a connection event with internal logs, if necessary."
    },
    "site": {
      "type": "string",
      "description": "The site the connection was established to."
    },
    "headers": {
      "type": "object",
      "description": "The HTTP headers of the connection request. Header names are lower case (e.g. 'accept', 'content-type', 'user-agent', etc.).",
      "properties": {
        "ably-agent": {
          "type": "string",
          "description": "The Ably-Agent header describing the SDK and runtime environment of the client."
        },
        "x-ably-version": {
          "type": "string",
          "description": "The Ably API protocol version expected by the client."
        },
        "x-geoip": {
          "type": "string",
          "description": "Geographic information related to the detected IP address of the client formatted as '<country-code>,<region>,<latitude>,<longitude>'"
        },
        "x-request-start": {
          "type": "string",
          "description": "The time the request was received by Ably's routing layer, represented as the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC"
        }
      }
    },
    "query": {
      "type": "object",
      "description": "The parsed query component of the connection request, excluding authentication parameters. The query contains connection information such as the client library version and any custom transport parameters.",
      "properties": {
        "agent": {
          "type": "string",
          "description": "The Ably-Agent header describing the SDK and runtime environment of the client."
        },
        "format": {
          "type": "string",
          "description": "The format used to encode protocol messages. Either 'json' or 'msgpack'."
        },
        "heartbeats": {
          "type": "string",
          "description": "The type of heartbeats to send on the connection. True for Ably protocol heartbeats, false for transport specific heartbeats.",
          "enum": ["true", "false"]
        },
        "v": {
          "type": "string",
          "description": "The Ably API protocol version expected by the client."
        }
      }
    },
    "connectionId": {
      "type": "string",
      "description": "The unique ID of the connection."
    },
    "clientId": {
      "type": "string",
      "description": "The ID of the client that attempted the connection."
    },
    "channels": {
      "type": "array",
      "description": "The list of channels referenced in the connection request. This is only relevant where channels are supported as part of the connection request, such as with SSE."
    },
    "duration": {
      "type": "integer",
      "description": "The duration the connection was open for in milliseconds."
    },
    "messages": {
      "type": "object",
      "description": "Message statistics",
      "properties": {
        "inbound": {
          "type": "object",
          "description": "Number of inbound messages",
          "properties": {
            "messages": {
              "type": "object",
              "description": "Message statistics",
              "properties": {
                "count": {
                  "type": "integer",
                  "description": "Message count"
                },
                "data": {
                  "type": "integer",
                  "description": "Message data in bytes"
                }
              }
            },
            "presence": {
              "type": "object",
              "description": "Presence statistics",
              "properties": {
                "count": {
                  "type": "integer",
                  "description": "Message count"
                },
                "data": {
                  "type": "integer",
                  "description": "Message data in bytes"
                }
              }
            },
            "maxRate": {
              "type": "integer",
              "description": "Maximum message rate over a 6 second interval"
            }
          }
        },
        "outbound": {
          "type": "object",
          "description": "Number of outbound messages",
          "properties": {
            "messages": {
              "type": "object",
              "description": "Message statistics",
              "properties": {
                "count": {
                  "type": "integer",
                  "description": "Message count"
                },
                "data": {
                  "type": "integer",
                  "description": "Message data in bytes"
                }
              }
            },
            "presence": {
              "type": "object",
              "description": "Presence statistics",
              "properties": {
                "count": {
                  "type": "integer",
                  "description": "Message count"
                },
                "data": {
                  "type": "integer",
                  "description": "Message data in bytes"
                }
              }
            },
            "maxRate": {
              "type": "integer",
              "description": "Maximum message rate over a 6 second interval"
            }
          }
        }
      }
    },
    "credential": {
      "type": "object",
      "description": "Details of the credential used to authenticate the client.",
      "properties": {
        "hasUserClaims": {
          "type": "boolean",
          "description": "Does this token contain user claims."
        },
        "hasLimitsClaims": {
          "type": "boolean",
          "description": "Does this token contain limits claims."
        },
        "keyName": {
          "type": "string",
          "description": "The credential's key name."
        },
        "type": {
          "type": "string",
          "description": "The credential type: either 'key', 'ablyToken', 'ablyJWT', or 'ablyJWE'."
        }
      },
      "required": ["hasUserClaims", "hasLimitsClaims", "keyName", "type"]
    },
    "error": {
      "type": "object",
      "description": "The details of any error encountered whilst processing the connection.",
      "properties": {
        "message": {
          "type": "string",
          "description": "The error message."
        },
        "code": {
          "type": "integer",
          "description": "The error code. See https://faqs.ably.com/ably-error-codes."
        },
        "statusCode": {
          "type": "integer",
          "description": "The HTTP status code. See https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html."
        }
      },
      "required": ["message", "code", "statusCode"]
    }
  },
  "additionalProperties": false,
  "required": ["host", "site", "headers", "query"]
}
