WebsocketConnection.h
Go to the documentation of this file.
44 using WebsocketBinaryDelegate = Delegate<void(WebsocketConnection&, uint8_t* data, size_t size)>;
112 bool send(IDataSourceStream* source, ws_frame_type_t type = WS_FRAME_TEXT, bool useMask = false, bool isFin = true);
120 static void broadcast(const char* message, size_t length, ws_frame_type_t type = WS_FRAME_TEXT);
Provides http base used for client and server connections.
Definition: HttpConnection.h:28
Represents either an incoming or outgoing response to a HTTP request.
Definition: HttpResponse.h:26
const char * c_str() const
Get a constant (un-modifiable) pointer to String content.
Definition: WString.h:616
size_t length(void) const
Obtain the String length in characters, excluding NUL terminator.
Definition: WString.h:243
Definition: TcpClient.h:46
Definition: WebsocketConnection.h:62
bool onConnected()
Call this method when the websocket connection was (re)activated.
bool send(const char *message, size_t length, ws_frame_type_t type=WS_FRAME_TEXT)
Sends a websocket message from a buffer.
static int staticOnDataBegin(void *userData, ws_frame_type_t type)
bool send(const String &message, ws_frame_type_t type=WS_FRAME_TEXT)
Sends websocket message from a String.
Definition: WebsocketConnection.h:98
void * getUserData()
Retrieves user data attached.
Definition: WebsocketConnection.h:174
WsConnectionState getState()
Gets the state of the websocket connection.
Definition: WebsocketConnection.h:272
void setConnection(HttpConnection *connection, bool isClientConnection=true)
Sets the underlying (transport ) HTTP connection.
void close()
Closes a websocket connection (without closing the underlying http connection)
static const WebsocketList & getActiveWebsockets()
Obtain the list of active websockets.
Definition: WebsocketConnection.h:193
WebsocketMessageDelegate wsMessage
Definition: WebsocketConnection.h:296
void setBinaryHandler(WebsocketBinaryDelegate handler)
Sets the callback handler to be called after a binary websocket message is received.
Definition: WebsocketConnection.h:220
static void broadcast(const String &message, ws_frame_type_t type=WS_FRAME_TEXT)
Broadcasts a message to all active websocket connections.
Definition: WebsocketConnection.h:127
static int staticOnControlBegin(void *userData, ws_frame_type_t type)
bool processFrame(TcpClient &client, char *at, int size)
Callback handler to process a received TCP data frame.
void setPongHandler(WebsocketDelegate handler)
Sets the callback handler to be called when pong reply received.
Definition: WebsocketConnection.h:228
static void broadcast(const char *message, size_t length, ws_frame_type_t type=WS_FRAME_TEXT)
Broadcasts a message to all active websocket connections.
static int staticOnDataEnd(void *userData)
bool send(IDataSourceStream *source, ws_frame_type_t type=WS_FRAME_TEXT, bool useMask=false, bool isFin=true)
Sends websocket message from a stream.
bool sendBinary(const uint8_t *data, size_t length)
Sends a binary websocket message.
Definition: WebsocketConnection.h:146
void setUserData(void *userData)
Attaches a user data to a websocket connection.
Definition: WebsocketConnection.h:165
void setDisconnectionHandler(WebsocketDelegate handler)
Sets the callback handler to be called before closing a websocket connection.
Definition: WebsocketConnection.h:236
static int staticOnControlPayload(void *userData, const char *, size_t length)
void setMessageHandler(WebsocketMessageDelegate handler)
Sets the callback handler to be called after a websocket message is received.
Definition: WebsocketConnection.h:211
virtual ~WebsocketConnection()
Definition: WebsocketConnection.h:71
static int staticOnDataPayload(void *userData, const char *at, size_t length)
void activate()
Should be called after a websocket connection is established to activate the websocket parser and all...
WebsocketDelegate wsDisconnect
Definition: WebsocketConnection.h:299
bool operator==(const WebsocketConnection &rhs) const
Test if another connection refers to the same object.
Definition: WebsocketConnection.h:183
bool bind(HttpRequest &request, HttpResponse &response)
Binds websocket connection to an http server connection.
void setConnectionHandler(WebsocketDelegate handler)
Sets the callback handler to be called after successful websocket connection.
Definition: WebsocketConnection.h:202
bool sendString(const String &message)
Sends a string websocket message.
Definition: WebsocketConnection.h:136
static int staticOnControlEnd(void *userData)
HttpConnection * getConnection()
Gets the underlying HTTP connection.
Definition: WebsocketConnection.h:257
WebsocketConnection(HttpConnection *connection=nullptr, bool isClientConnection=true)
Constructs a websocket connection on top of http client or server connection.
#define DECLARE_FSTR(name)
Declare a global FSTR::String& reference.
Definition: String.hpp:63
WsConnectionState
Current state of Websocket connection.
Definition: WebsocketConnection.h:49
Definition: WebsocketConnection.h:55