|
Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
|
Public Member Functions | |
| WebsocketConnection (HttpConnection *connection, bool isClientConnection=true) | |
| Constructs a websocket connection on top of http client or server connection. More... | |
| bool | bind (HttpRequest &request, HttpResponse &response) |
| Binds websocket connection to an http server connection. More... | |
| virtual void | send (const char *message, size_t length, ws_frame_type_t type=WS_FRAME_TEXT) |
| Sends a websocket message from a buffer. More... | |
| void | send (const String &message, ws_frame_type_t type=WS_FRAME_TEXT) |
| Sends websocket message from a String. More... | |
| void | sendString (const String &message) |
| Sends a string websocket message. More... | |
| void | sendBinary (const uint8_t *data, size_t length) |
| Sends a binary websocket message. More... | |
| void | close () |
| Closes a websocket connection (without closing the underlying http connection. More... | |
| void | reset () |
| Resets a websocket connection. More... | |
| void | setUserData (void *userData) |
| Attaches a user data to a websocket connection. More... | |
| void * | getUserData () |
| Retrieves user data attached. More... | |
| bool | operator== (const WebsocketConnection &rhs) const |
| Test if another connection refers to the same object. More... | |
| void | setConnectionHandler (WebsocketDelegate handler) |
| Sets the callback handler to be called after successful websocket connection. More... | |
| void | setMessageHandler (WebsocketMessageDelegate handler) |
| Sets the callback handler to be called after a websocket message is received. More... | |
| void | setBinaryHandler (WebsocketBinaryDelegate handler) |
| Sets the callback handler to be called after a binary websocket message is received. More... | |
| void | setDisconnectionHandler (WebsocketDelegate handler) |
| Sets the callback handler to be called before closing a websocket connection. More... | |
| void | activate () |
| Should be called after a websocket connection is established to activate the websocket parser and allow sending of websocket data. More... | |
| bool | onConnected () |
| Call this method when the websocket connection was (re)activated. More... | |
| HttpConnection * | getConnection () |
| Gets the underlying HTTP connection. More... | |
| void | setConnection (HttpConnection *connection, bool isClientConnection=true) |
| Sets the underlying (transport ) HTTP connection. More... | |
| WsConnectionState | getState () |
| Gets the state of the websocket connection. More... | |
Static Public Member Functions | |
| 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. More... | |
| static void | broadcast (const String &message, ws_frame_type_t type=WS_FRAME_TEXT) |
| Broadcasts a message to all active websocket connections. More... | |
| static const WebsocketList & | getActiveWebsockets () |
| Obtain the list of active websockets. More... | |
Protected Member Functions | |
| bool | processFrame (TcpClient &client, char *at, int size) |
| Callback handler to process a received TCP data frame. More... | |
| size_t | encodeFrame (ws_frame_type_t type, const char *inData, size_t inLength, char *outData, size_t outLength, bool useMask=true, bool isFin=true) |
| Encode user content into a valid websocket frame. More... | |
Protected Attributes | |
| WebsocketDelegate | wsConnect = nullptr |
| WebsocketMessageDelegate | wsMessage = nullptr |
| WebsocketBinaryDelegate | wsBinary = nullptr |
| WebsocketDelegate | wsDisconnect = nullptr |
| void * | userData = nullptr |
| WsConnectionState | state = eWSCS_Ready |
| WebsocketConnection::WebsocketConnection | ( | HttpConnection * | connection, |
| bool | isClientConnection = true |
||
| ) |
Constructs a websocket connection on top of http client or server connection.
| connection | the transport connection |
| isClientConnection | true when the passed connection is an http client conneciton |
| void WebsocketConnection::activate | ( | ) |
Should be called after a websocket connection is established to activate the websocket parser and allow sending of websocket data.
| bool WebsocketConnection::bind | ( | HttpRequest & | request, |
| HttpResponse & | response | ||
| ) |
Binds websocket connection to an http server connection.
| request | |
| response |
| bool | true on success, false otherwise |
|
static |
Broadcasts a message to all active websocket connections.
| message | |
| length | |
| type |
|
inlinestatic |
Broadcasts a message to all active websocket connections.
| message | |
| type |
| void WebsocketConnection::close | ( | ) |
Closes a websocket connection (without closing the underlying http connection.
|
protected |
Encode user content into a valid websocket frame.
| type | |
| inData | |
| inLength | |
| outData | |
| outLength | |
| useMask | MUST be true for client connections |
| isFin | true if this is the final frame |
| size_t | Size of encoded frame |
|
inlinestatic |
Obtain the list of active websockets.
| const | WebsocketList& |
|
inline |
Gets the underlying HTTP connection.
| HttpConnection* |
|
inline |
Gets the state of the websocket connection.
| WsConnectionState |
|
inline |
Retrieves user data attached.
| void* | The user data previously set by setUserData() |
| bool WebsocketConnection::onConnected | ( | ) |
Call this method when the websocket connection was (re)activated.
| bool | true on success |
|
inline |
Test if another connection refers to the same object.
| rhs | The other WebsocketConnection to compare with |
| bool |
|
protected |
Callback handler to process a received TCP data frame.
| client | |
| at | |
| size |
| bool | true if data parsing successful |
| void WebsocketConnection::reset | ( | ) |
Resets a websocket connection.
|
virtual |
Sends a websocket message from a buffer.
| message | |
| length | Quantity of data in message |
| type |
|
inline |
|
inline |
Sends a binary websocket message.
| data | |
| length |
|
inline |
Sends a string websocket message.
| message |
|
inline |
Sets the callback handler to be called after a binary websocket message is received.
| handler |
|
inline |
Sets the underlying (transport ) HTTP connection.
| connection | the transport connection |
| isClientConnection | true when the passed connection is an http client conneciton |
|
inline |
Sets the callback handler to be called after successful websocket connection.
| handler |
|
inline |
Sets the callback handler to be called before closing a websocket connection.
| handler |
|
inline |
Sets the callback handler to be called after a websocket message is received.
| handler |
|
inline |
Attaches a user data to a websocket connection.
| userData |