#include <websocketclient.h>
Public Member Functions | |
WebSocketClient (WebSocketService &service) | |
bool | send (const std::string &message, EWebSocketOPCode code, nap::utility::ErrorState &error) |
bool | send (void const *payload, int length, EWebSocketOPCode code, nap::utility::ErrorState &error) |
bool | send (const WebSocketMessage &message, nap::utility::ErrorState &error) |
![]() | |
IWebSocketClient (WebSocketService &service) | |
virtual bool | init (utility::ErrorState &errorState) override |
virtual void | onDestroy () override |
bool | isConnected () const |
bool | reconnect (utility::ErrorState &error) |
const WebSocketConnection & | getConnection () const |
![]() | |
WebSocketInterface (WebSocketService &service) | |
virtual | ~WebSocketInterface () |
template<typename T > | |
T & | as () |
template<typename T > | |
const T & | as () const |
![]() | |
Resource () | |
![]() | |
Object () | |
virtual | ~Object () |
Object (Object &)=delete | |
Object & | operator= (const Object &)=delete |
Object (Object &&)=delete | |
Object & | operator= (Object &&)=delete |
Additional Inherited Members | |
![]() | |
static bool | isIDProperty (rtti::Instance &object, const rtti::Property &property) |
![]() | |
ResourcePtr< IWebSocketClientEndPoint > | mEndPoint |
Property: 'EndPoint' the client endpoint that manages all connections. More... | |
ResourcePtr< WebSocketTicket > | mTicket = nullptr |
Property: 'Ticket' optional identification token. More... | |
std::string | mURI |
Property: "URI" Server URI to open connection to. More... | |
![]() | |
std::string | mID |
Property: 'mID' unique name of the object. Used as an identifier by the system. More... | |
![]() | |
void | addEvent (WebSocketEventPtr newEvent) |
![]() | |
WebSocketConnection | mConnection |
Web-socket connection. More... | |
![]() | |
std::queue< WebSocketEventPtr > | mEvents |
std::mutex | mEventMutex |
WebSocketService * | mService = nullptr |
Default implementation of a web-socket client. Converts connection updates and messages into web-socket events. These events are consumed by the nap::WebSocketService on the main application thread. On update all events in the queue are forwarded to a nap::WebSocketComponent. Use a nap::WebSocketComponent to receive and react to web-socket events in your application. On initialization the client registers itself with a nap::WebSocketClientEndPointBase and tries to connect to the server. Call reconnect() to establish a new connection at run-time.
A 'ticket' can be added to specify additional authorization information (username / password). This information is automatically given to the server when the client tries to establish a connection. The server can accept or reject the connection based on that information. When no ticket is provided the client will try to connect without any authorization.
WebSocketClient | ( | WebSocketService & | service | ) |
Constructor
service | the web-socket service that forwards events to the application. |
bool send | ( | const std::string & | message, |
EWebSocketOPCode | code, | ||
nap::utility::ErrorState & | error | ||
) |
Sends a message with the given opcode to the server. The message is send immediately.
message | the message to send |
code | message type |
error | contains the error if sending fails |
bool send | ( | const WebSocketMessage & | message, |
nap::utility::ErrorState & | error | ||
) |
Sends a message to the server. The message is send immediately.
message | the message to send |
error | contains the error if sending fails |
bool send | ( | void const * | payload, |
int | length, | ||
EWebSocketOPCode | code, | ||
nap::utility::ErrorState & | error | ||
) |
Sends a message using the given payload and opcode to the server. The message is send immediately.
payload | the message buffer |
length | total number of bytes |
code | message type |
error | contains the error if sending fails |