Struct WebSocketServerCallbacks

Struct Documentation

struct WebSocketServerCallbacks

The callback interface for a WebSocket server.

These methods are invoked from the client’s main poll loop and must be as low-latency as possible.

Note

These callbacks may be invoked concurrently from multiple threads. You must synchronize access to your mutable internal state or shared resources.

Public Members

std::function<void(uint64_t channel_id)> onSubscribe

Callback invoked when a client subscribes to a channel.

Only invoked if the channel is associated with the server and isn’t already subscribed to by the client.

std::function<void(uint64_t channel_id)> onUnsubscribe

Callback invoked when a client unsubscribes from a channel.

Only invoked for channels that had an active subscription from the client.

std::function<void(uint32_t client_id, const ClientChannel &channel)> onClientAdvertise

Callback invoked when a client advertises a client channel.

Requires the capability WebSocketServerCapabilities::ClientPublish

std::function<void(uint32_t client_id, uint32_t client_channel_id, const std::byte *data, size_t data_len)> onMessageData

Callback invoked when a client message is received.

std::function<void(uint32_t client_id, uint32_t client_channel_id)> onClientUnadvertise

Callback invoked when a client unadvertises a client channel.

Requires the capability WebSocketServerCapabilities::ClientPublish

std::function<std::vector<Parameter>(uint32_t client_id, std::optional<std::string_view> request_id, const std::vector<std::string_view> &param_names)> onGetParameters

Callback invoked when a client requests parameters.

Requires the capability WebSocketServerCapabilities::Parameters.

Param client_id:

The client ID.

Param request_id:

A request ID unique to this client. May be NULL.

Param param_names:

A list of parameter names to fetch. If empty, this method should return all parameters.

std::function<std::vector<Parameter>(uint32_t client_id, std::optional<std::string_view> request_id, const std::vector<ParameterView> &params)> onSetParameters

Callback invoked when a client sets parameters.

Requires the capability WebSocketServerCapabilities::Parameters.

This function should return the updated parameters. All clients subscribed to updates for the returned parameters will be notified.

Param client_id:

The client ID.

Param request_id:

A request ID unique to this client. May be NULL.

Param param_names:

A list of updated parameter values.

std::function<void(const std::vector<std::string_view> &param_names)> onParametersSubscribe

Callback invoked when a client subscribes to the named parameters for the first time.

Requires the capability WebSocketServerCapabilities::Parameters.

Param param_names:

A list of parameter names.

std::function<void(const std::vector<std::string_view> &param_names)> onParametersUnsubscribe

Callback invoked when the last client unsubscribes from the named parameters.

Requires the capability WebSocketServerCapabilities::Parameters.

Param param_names:

A list of parameter names.

std::function<void()> onConnectionGraphSubscribe

Callback invoked when a client requests connection graph updates.

Requires the capability WebSocketServerCapabilities::ConnectionGraph

std::function<void()> onConnectionGraphUnsubscribe

Callback invoked when a client unsubscribes from connection graph updates.

Requires the capability WebSocketServerCapabilities::ConnectionGraph