Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::runtime::WebSocketChannel Class Reference

#include <websocket_channel.hpp>

Public Member Functions

 ~WebSocketChannel () override
bool send (const std::uint8_t *data, std::size_t size) override
 Send a message.
bool send_text (std::string_view text) override
void on_message (MessageCallback callback) override
 Install / replace callbacks.
void on_closed (ChannelClosedCallback callback) override
void on_error (ChannelErrorCallback callback) override
void close () override
 Close the channel. Idempotent. Fires the closed callback.
bool is_open () const override
 Whether the channel is currently usable.
bool send (std::string_view text)

Static Public Member Functions

static std::unique_ptr< WebSocketChannel > connect (std::unique_ptr< TcpStream > tcp, std::string_view host, std::string_view path="/", WebSocketOptions options={})
 Perform a client handshake over tcp, then start the reader.
static std::unique_ptr< WebSocketChannel > accept (std::unique_ptr< TcpStream > tcp, WebSocketOptions options={})
 Perform a server-side handshake over an already-accepted tcp connection.
static std::string compute_accept_key (std::string_view client_key)
 Expose the handshake Sec-WebSocket-Accept for debugging and for tests that want to verify RFC 6455 compliance.

Constructor & Destructor Documentation

◆ ~WebSocketChannel()

pulp::runtime::WebSocketChannel::~WebSocketChannel ( )
override

Member Function Documentation

◆ accept()

std::unique_ptr< WebSocketChannel > pulp::runtime::WebSocketChannel::accept ( std::unique_ptr< TcpStream > tcp,
WebSocketOptions options = {} )
static

Perform a server-side handshake over an already-accepted tcp connection.

Reads the HTTP upgrade request, validates the key, writes a 101 Switching Protocols response, and starts the reader. Returns nullptr on failure.

◆ close()

void pulp::runtime::WebSocketChannel::close ( )
overridevirtual

Close the channel. Idempotent. Fires the closed callback.

Implements pulp::runtime::MessageChannel.

◆ compute_accept_key()

std::string pulp::runtime::WebSocketChannel::compute_accept_key ( std::string_view client_key)
static

Expose the handshake Sec-WebSocket-Accept for debugging and for tests that want to verify RFC 6455 compliance.

◆ connect()

std::unique_ptr< WebSocketChannel > pulp::runtime::WebSocketChannel::connect ( std::unique_ptr< TcpStream > tcp,
std::string_view host,
std::string_view path = "/",
WebSocketOptions options = {} )
static

Perform a client handshake over tcp, then start the reader.

host and path populate the HTTP/1.1 upgrade request (Host: header + request-URI). Returns nullptr on failure.

◆ is_open()

bool pulp::runtime::WebSocketChannel::is_open ( ) const
overridevirtual

Whether the channel is currently usable.

Implements pulp::runtime::MessageChannel.

◆ on_closed()

void pulp::runtime::WebSocketChannel::on_closed ( ChannelClosedCallback callback)
overridevirtual

◆ on_error()

void pulp::runtime::WebSocketChannel::on_error ( ChannelErrorCallback callback)
overridevirtual

◆ on_message()

void pulp::runtime::WebSocketChannel::on_message ( MessageCallback callback)
overridevirtual

Install / replace callbacks.

Safe to call at any time; callbacks installed during send-processing apply to subsequent messages.

Implements pulp::runtime::MessageChannel.

◆ send() [1/2]

bool pulp::runtime::MessageChannel::send ( std::string_view text)
inlineinherited

◆ send() [2/2]

bool pulp::runtime::WebSocketChannel::send ( const std::uint8_t * data,
std::size_t size )
overridevirtual

Send a message.

Returns true if the payload was accepted for transmission (queued or written); false if the channel is closed, errored, or the payload was rejected (e.g., frame too large).

The default overload sends binary; override send_text if the transport distinguishes text from binary.

Implements pulp::runtime::MessageChannel.

◆ send_text()

bool pulp::runtime::WebSocketChannel::send_text ( std::string_view text)
overridevirtual

Reimplemented from pulp::runtime::MessageChannel.


The documentation for this class was generated from the following file: