Class Channel#

Class Documentation#

class Channel#

A multiplexed line of communication on a websocket.

See WebUI for more discussion on WebUI.

Public Functions

Channel(const Channel&) = delete#
Channel &operator=(const Channel&) = delete#
virtual ~Channel()#

Router destructor.

std::string_view uuid() const#

A universally unique identifier for the channel.

Returns:

The uuid

void broadcastMessage(std::string_view msg)#

Send a message on this channel to all clients.

Parameters:

msg – - The message to send

void sendMessage(std::string_view msg, int client_id)#

Send a message on this channel to a specific client.

Parameters:
  • msg – - The message to send

  • client_id – - The id for the client to send to

void setOnConnect(std::function<void(int)> callback)#

Set a function called on websocket client connection.

Parameters:

callback – - The callback function

void setOnMessage(std::function<void(std::string_view, int)> callback)#

Set a function called on receiving a websocket message.

Parameters:

callback – - The callback function

void setOnDisconnect(std::function<void(int)> callback)#

Set a function called on websocket client disconnect.

Parameters:

callback – - The callback function

void defer(std::function<void()> callback)#

Submit a function to be called in the event loop.

Parameters:

callback – - The callback function

void sync()#

Block for deferred calls.

This places a deferred callback on the event loop and waits for the callback to be called, ensuring any prior callbacks have also been called. This does not wait for the event loop to reach quiescence.