-
An application wishing to provide data for streamed consumption by Foxglove hosts a WebSocket server.
-
The client (Foxglove) will specify supported subprotocols (a standard part of the WebSocket handshake) when establishing the connection. The current version of this document corresponds to subprotocol
foxglove.websocket.v1
. The server must select a subprotocol with which it is compatible for the connection to continue.- Example client code in JavaScript:
new WebSocket("ws://...", ["foxglove.websocket.v1"]);
- Example client code in JavaScript:
-
Both text and binary messages are used on the WebSocket connection.
-
Each text message must be a JSON object having a field called
op
which identifies the type of message. The interpretation of the other fields depends on the opcode. -
Similarly, each binary message starts with a 1-byte opcode identifying the type of message. The interpretation of the remaining bytes depends on the opcode.
-
-
Upon establishing a connection, the server must send clients a Server Info message with a list of supported capabilities.
- Server Info (json)
- Status (json)
- Remove Status (json)
- Advertise (json)
- Unadvertise (json)
- Message Data (binary)
- Time (binary)
- Parameter Values (json)
- Advertise Services (json)
- Unadvertise Services (json)
- Service Call Response (binary)
- Connection Graph Update (json)
- Fetch Asset Response (binary)
- Service Call Failure (json)
- Subscribe (json)
- Unsubscribe (json)
- Client Advertise (json)
- Client Unadvertise (json)
- Client Message Data (binary)
- Get Parameters (json)
- Set Parameters (json)
- Subscribe Parameter Update (json)
- Unsubscribe Parameter Update (json)
- Service Call Request (binary)
- Subscribe connection graph updates (json)
- Unubscribe connection graph updates (json)
- Fetch asset (json)
Each JSON message must be an object containing a field called op
which identifies the type of message.
- This message is always sent to new clients upon connection.
op
: string"serverInfo"
name
: free-form information about the server which the client may optionally display or use for debugging purposescapabilities
: array of strings, informing the client about which optional features are supportedclientPublish
: Allow clients to advertise channels to send data messages to the serverparameters
: Allow clients to get & set parametersparametersSubscribe
: Allow clients to subscribe to parameter changestime
: The server may publish binary time messagesservices
: Allow clients to call servicesconnectionGraph
: Allow clients to subscribe to updates to the connection graphassets
: Allow clients to fetch assets
supportedEncodings
: array of strings | informing the client about which encodings may be used for client-side publishing or service call requests/responses. Only set if client publishing or services are supported.metadata
: optional map of key-value pairssessionId
: optional string. Allows the client to understand if the connection is a re-connection or if it is connecting to a new server instance. This can for example be a timestamp or a UUID.
{
"op": "serverInfo",
"name": "example server",
"capabilities": ["clientPublish", "time"],
"supportedEncodings": ["json"],
"metadata": {
"key": "value"
},
"sessionId": "1675789422160"
}
- The server may send this message at any time. Client developers may use it for debugging purposes, display it to the end user, or ignore it.
op
: string"status"
level
: 0 (info), 1 (warning), 2 (error)message
: stringid
: string | undefined. Optional identifier for the status message. Newer status messages with the same identifier should replace previous messages. removeStatus can reference the identifier to indicate a status message is no longer valid.
{
"op": "status",
"level": 0,
"message": "Some info",
"id": "status-123"
}
- Informs the client that previously sent status message(s) are no longer valid.
op
: string"removeStatus"
statusIds
: array of string, ids of the status messages to be removed. The array must not be empty.
{
"op": "removeStatus",
"statusIds": ["status-123"]
}
- Informs the client about newly available channels.
- At least one Advertise message is always sent to new clients upon connection.
op
: string"advertise"
channels
: array of:id
: number. The server may reuse ids when channels disappear and reappear, but only if the channel keeps the exact same topic, encoding, schemaName, and schema. Clients will use this unique id to cache schema info and deserialization routines.topic
: stringencoding
: string, type of encoding used for message encodingNote: Encodings currently supported by Foxglove are
json
,protobuf
,ros1
, andcdr
(ROS 2). For more information, see the Foxglove documentation.schemaName
: stringschema
: stringNote: Foxglove expects the schema to be in a format matching the
schemaEncoding
or alternatively theencoding
ifschemaEncoding
is not specified. For more information, see the Foxglove documentation.schemaEncoding
: string | undefined, type of encoding used for schema encoding. May be used if the schema encoding can't be uniquely deduced from the message encoding.
{
"op": "advertise",
"channels": [
{
"id": 1,
"topic": "foo",
"encoding": "protobuf",
"schemaName": "ExampleMsg",
"schema": "ZXhhbXBsZSBkYXRh"
}
]
}
Informs the client that channels are no longer available.
op
: string"unadvertise"
channelIds
: array of number, corresponding to previous Advertise
{
"op": "unadvertise",
"channelIds": [1, 2]
}
Informs the client about parameters. Only supported if the server declares the parameters
capability.
op
: string"parameterValues"
parameters
: array of:name
: string, name of the parametervalue
: ParameterValue, where ParameterValue is of type number | boolean | string | ParameterValue[] | { [key: string]: ParameterValue } | undefined.type
: "byte_array" | "float64" | "float64_array" | undefined. If the type isbyte_array
,value
shall be interpreted as base64 encoded string. If the type isfloat64
, value must be a valid decimal or integer value that can be represented by a float64. If the type isfloat64_array
, value must be an array of valid decimal or integer values.
id
: string | undefined. Only set when the getParameters or setParameters request'sid
field was set
{
"op": "parameterValues",
"parameters": [
{ "name": "/int_param", "value": 2 },
{ "name": "/float_param", "value": 1.2 },
{ "name": "/string_param", "value": "foo" },
{ "name": "/node/nested_ints_param", "value": [1, 2, 3] }
{ "name": "/byte_array_param", "value": "QUJDRA==", "type": "byte_array" },
{ "name": "/float_param_int", "value": 3, "type": "float64" },
{ "name": "/float_array_param", "value": [1.1, 2, 3.3], "type": "float64_array" },
],
"id": "request-123"
}
Informs the client about available services. Only supported if the server declares the services
capability.
op
: string"advertiseServices"
services
: array of:id
: number. The server may reuse ids when services disappear and reappear, but only if the services keeps the exact same name, type, and schema. Clients will use this unique id to cache schema info and deserialization routines.name
: string, name used to identify the service.type
: string, type of the service. May be used to derive request & response schema names ifrequest
orresponse
are not given.request
: object describing the request. Required ifrequestSchema
is not given.encoding
: string, type of encoding used for request message encoding.schemaName
: string, name of the request schema.schemaEncoding
: string, type of encoding used for schema encoding.schema
: string, schema definition in a format matching theschemaEncoding
.
response
: object describing the response. Required ifresponseSchema
is not given.encoding
: string, type of encoding used for response message encoding.schemaName
: string, name of the response schema.schemaEncoding
: string, type of encoding used for schema encoding.schema
: string, schema definition in a format matching theschemaEncoding
.
requestSchema
: string | undefined, request schema definition. The schema encoding will be derived from thesupportedEncodings
sent by the server. Required ifrequest
is not given. Field is present for backwards compatibilty, prefer usingrequest
instead.responseSchema
: string | undefined, response schema definition. The schema encoding will be derived from thesupportedEncodings
sent by the server. Required ifresponse
is not given. Field is present for backwards compatibilty, prefer usingresponse
instead.
{
"op": "advertiseServices",
"services": [
{
"id": 1,
"name": "foo",
"type": "std_srvs/Empty",
"requestSchema": "",
"responseSchema": ""
},
{
"id": 2,
"name": "set_bool",
"type": "std_srvs/SetBool",
"request": { "encoding": "ros1", "schemaName": "std_srvs/SetBool_Request", "schemaEncoding": "ros1msg", "schema": "bool data" },
"response": { "encoding": "ros1", "schemaName": "std_srvs/SetBool_Response", "schemaEncoding": "ros1msg", "schema": "bool success\nstring message" }
}
]
}
Informs the client about services that are no longer available. Only supported if the server declares the services
capability.
op
: string"unadvertiseServices"
serviceIds
: array of number, corresponding to previous advertisement
{
"op": "unadvertiseServices",
"serviceIds": [1, 2]
}
Informs the client about updates to the connection graph. This is only sent to clients which have previously subscribed to connection graph updates. Only supported if the server previously declared that it has the connectionGraph
capability.
op
: string"connectionGraphUpdate"
publishedTopics
: array ofname
: topic namepublisherIds
: array of string, list of publisher IDs. Replaces any previous publisher information about this topic.
subscribedTopics
: array ofname
: topic namesubscriberIds
: array of string, list of subscriber IDs. Replaces any previous subscriber information about this topic.
advertisedServices
: array ofname
: service nameproviderIds
: array of string, list of provider IDs. Replaces any previous provider information about this service.
removedTopics
: array of string, names of topics that have been removedremovedServices
: array of string, names of services that have been removed
{
"op": "connectionGraphUpdate",
"publishedTopics": [
{ "name": "/foo", "publisherIds": ["/node_1"] },
{ "name": "/bar", "publisherIds": ["/node_1"] }
],
"subscribedTopics": [{ "name": "/foo", "subscriberIds": ["/node_2"] }],
"advertisedServices": [{ "name": "/set_bool", "providerIds": ["/node_2"] }],
"removedTopics": ["/baz"],
"removedServices": []
}
Informs the client about failure to call a service.
Only supported if the server previously declared that it has the services
capability.
op
: string"serviceCallFailure"
serviceId
: numbercallId
: numbermessage
: string
{
"op": "serviceCallFailure",
"serviceId": 1,
"callId": 1,
"message": "Service does not exist",
}
- Requests that the server start streaming messages on a given topic (or topics) to the client.
- A client may only have one subscription for each channel at a time.
op
: string"subscribe"
subscriptions
: array of:id
: number chosen by the client. The client may not reuse ids across multiple active subscriptions. The server may ignore subscriptions that attempt to reuse an id (and send an error status message). After unsubscribing, the client may reuse the id.channelId
: number, corresponding to previous Advertise message(s)
{
"op": "subscribe",
"subscriptions": [
{ "id": 0, "channelId": 3 },
{ "id": 1, "channelId": 5 }
]
}
- Requests that the server stop streaming messages to which the client previously subscribed.
op
: string"unsubscribe"
subscriptionIds
: array of number, corresponding to previous Subscribe message(s)
{
"op": "unsubscribe",
"subscriptionIds": [0, 1]
}
- Informs the server about available client channels. Note that the client is only allowed to advertise channels if the server previously declared that it has the
clientPublish
capability.
op
: string"advertise"
channels
: array of:id
: number chosen by the client. The client may reuse ids that have previously been unadvertised.topic
: stringencoding
: string, one of the message encodings supported by the serverschemaName
: stringschema
: string | undefined, optional schema definition.schemaEncoding
: string | undefined, optional schema encoding.
{
"op": "advertise",
"channels": [
{
"id": 1,
"topic": "foo",
"encoding": "protobuf",
"schemaName": "ExampleMsg"
}
]
}
- Informs the server that client channels are no longer available. Note that the client is only allowed to unadvertise channels if the server previously declared that it has the
clientPublish
capability.
op
: string"unadvertise"
channelIds
: array of number, corresponding to previous Client Advertise
{
"op": "unadvertise",
"channelIds": [1, 2]
}
Request one or more parameters. Only supported if the server previously declared that it has the parameters
capability.
op
: string"getParameters"
parameterNames
: string[], leave empty to retrieve all currently set parametersid
: string | undefined, arbitrary string used for identifying the corresponding server response
{
"op": "getParameters",
"parameterNames": [
"/int_param",
"/float_param",
"/string_param",
"/node/nested_ints_param"
],
"id": "request-123"
}
Set one or more parameters. Only supported if the server previously declared that it has the parameters
capability.
op
: string"setParameters"
parameters
: array of:name
: stringvalue
: number | boolean | string | number[] | boolean[] | string[] | undefined. If the value is not set (undefined
), the parameter shall be unset (removed).type
: "byte_array" | "float64" | "float64_array" | undefined. If the type isbyte_array
,value
shall be a base64 encoded string. If the type isfloat64
, value must be a valid decimal or integer value that can be represented by a float64. If the type isfloat64_array
, value must be an array of valid decimal or integer values.
id
: string | undefined, arbitrary string used for identifying the corresponding server response. If this field is not set, the server may not send a response to the client.
{
"op": "setParameters",
"parameters": [
{ "name": "/int_param", "value": 3 },
{ "name": "/float_param", "value": 4.1 },
{ "name": "/byte_array_param", "value": "QUJDRA==", "type": "byte_array" },
{ "name": "/float_param_int", "value": 3, "type": "float64" },
{ "name": "/float_array_param", "value": [1.1, 2, 3.3], "type": "float64_array" },
],
"id": "request-456"
}
Subscribe to parameter updates. Only supported if the server previously declared that it has the parametersSubscribe
capability.
Sending subscribeParameterUpdates
multiple times will append the list of parameter subscriptions, not replace them. Note that parameters can be subscribed at most once. Hence, this operation will ignore parameters that are already subscribed. Use unsubscribeParameterUpdates to unsubscribe from existing parameter subscriptions.
op
: string"subscribeParameterUpdates"
parameterNames
: string[], leave empty to subscribe to all currently known parameters
{
"op": "subscribeParameterUpdates",
"parameterNames": [
"/int_param",
"/float_param",
"/string_param",
"/node/nested_ints_param"
]
}
Unsubscribe from parameter updates. Only supported if the server previously declared that it has the parametersSubscribe
capability.
op
: string"unsubscribeParameterUpdates"
parameterNames
: string[], leave empty to unsubscribe from all parameter updates
{
"op": "unsubscribeParameterUpdates",
"parameterNames": [
"/int_param",
"/float_param",
"/string_param",
"/node/nested_ints_param"
]
}
Subscribe to connection graph updates. Only supported if the server previously declared that it has the connectionGraph
capability.
op
: string"subscribeConnectionGraph"
{
"op": "subscribeConnectionGraph"
}
Unsubscribe from connection graph updates. Only supported if the server previously declared that it has the connectionGraph
capability.
op
: string"unsubscribeConnectionGraph"
{
"op": "unsubscribeConnectionGraph"
}
Fetch an asset from the server. Only supported if the server previously declared that it has the assets
capability.
op
: string"fetchAsset"
uri
: string, uniform resource identifier to locate a single assetrequestId
: number, unique 32-bit unsigned integer which is to be included in the response
{
"op": "fetchAsset",
"uri": "package://foo/robot.urdf",
"requestId": 123
}
All binary messages must start with a 1-byte opcode identifying the type of message. The interpretation of the remaining bytes depends on the opcode.
All integer types explicitly specified (uint32, uint64, etc.) in this section are encoded with little-endian byte order.
- Provides a raw message payload, encoded as specified in the Advertise corresponding to the channel.
- Subscription id must correspond to a Subscribe that was previously sent.
Bytes | Type | Description |
---|---|---|
1 | opcode | 0x01 |
4 | uint32 | subscription id |
8 | uint64 | receive timestamp (nanoseconds) |
remaining bytes | uint8[] | message payload |
- Inform clients about the latest server time. This allows accelerated, slowed, or stepped control over the progress of time.
- If the server publishes time data, then timestamps of published messages must originate from the same time source
- The server may only publish time data if it previously declared support for it via the
time
capability
Bytes | Type | Description |
---|---|---|
1 | opcode | 0x02 |
8 | uint64 | timestamp (nanoseconds) |
- Provides the response to a previous service call.
- If the service call failed, a service call failure response will be sent instead.
- Only supported if the server previously declared the
services
capability.
Bytes | Type | Description |
---|---|---|
1 | opcode | 0x03 |
4 | uint32 | service id |
4 | uint32 | call id |
4 | uint32 | encoding length |
encoding length | char[] | encoding, same encoding that was used for the request |
remaining bytes | uint8[] | response payload |
- Response to a fetch asset request
- Only supported if the server previously declared the
assets
capability.
Bytes | Type | Description |
---|---|---|
1 | opcode | 0x04 |
4 | uint32 | request id, as given in the corresponding request |
1 | uint8 | status enum, 0 for success and 1 for error. Values >1 are reserved for future use |
4 | uint32 | error message length |
error message length | char[] | error message, empty if status == 0 |
remaining bytes | uint8[] | asset data (file contents), empty if status != 0 |
- Sends a binary websocket message containing the raw messsage payload to the server. Note that the client is only allowed to publish messages if the server previously declared that it has the
clientPublish
capability. - The message payload is encoded as advertised in the Client Advertise operation.
Bytes | Type | Description |
---|---|---|
1 | opcode | 0x01 |
4 | uint32 | channel id |
remaining bytes | uint8[] | message payload |
- Request to call a service that has been advertised by the server.
- Only supported if the server previously declared the
services
capability.
Bytes | Type | Description |
---|---|---|
1 | opcode | 0x02 |
4 | uint32 | service id |
4 | uint32 | call id, a unique number to identify the corresponding service response |
4 | uint32 | encoding length |
encoding length | char[] | encoding, one of the encodings supported by the server |
remaining bytes | uint8[] | request payload |