#include <websocketclient.h>
Public Member Functions | |
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 |
Public Attributes | |
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... | |
Protected Member Functions | |
virtual void | onConnectionOpened ()=0 |
virtual void | onConnectionClosed (int code, const std::string &reason)=0 |
virtual void | onConnectionFailed (int code, const std::string &reason)=0 |
virtual void | onMessageReceived (const WebSocketMessage &msg)=0 |
![]() | |
void | addEvent (WebSocketEventPtr newEvent) |
Protected Attributes | |
WebSocketConnection | mConnection |
Web-socket connection. More... | |
![]() | |
std::queue< WebSocketEventPtr > | mEvents |
std::mutex | mEventMutex |
WebSocketService * | mService = nullptr |
Additional Inherited Members | |
![]() | |
static bool | isIDProperty (rtti::Instance &object, const rtti::Property &property) |
Interface for all web-socket clients. Derive from this class to implement your own web-socket client. Override the various virtual functions to receive web-socket client updates. The virtual functions are called from a different thread than the main thread. It is your responsibility to ensure thread-safety. On initialization the client registers itself with a nap::WebSocketClientEndPointBase and tries to connect to the server. When a connection is established the onConnectionOpened function is called. If the connection failed to establish the onConnectionFailed function is called. Call reconnect() to establish a new connection at run-time.
A 'ticket' can be added to every client to specify additional authorization information. 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.
IWebSocketClient | ( | WebSocketService & | service | ) |
Constructor
service | the web-socket service that forwards events to the application. |
const WebSocketConnection& getConnection | ( | ) | const |
|
overridevirtual |
Registers the web-socket client interface with the endpoint. The client 'tries' to establish a connection with the server. The success of the initialization step does not depend on whether or not the client manages to connect to the service.
errorState | contains the error message when initialization fails |
Reimplemented from WebSocketInterface.
bool isConnected | ( | ) | const |
|
protectedpure virtual |
Occurs when the connection to the server is closed.
code | the closing code |
reason | the reason for closing the connection. |
Implemented in APIWebSocketClient.
|
protectedpure virtual |
Occurs when connecting to the server fails.
code | the closing code |
reason | the reason why the connection failed. |
Implemented in APIWebSocketClient.
|
protectedpure virtual |
Occurs when a new connection to the server is opened.
Implemented in APIWebSocketClient.
|
overridevirtual |
Unregisters the web-socket client interface with the endpoint.
Reimplemented from Object.
|
protectedpure virtual |
Occurs when a new message from the server to this client is received.
msg | the received message |
Implemented in APIWebSocketClient.
bool reconnect | ( | utility::ErrorState & | error | ) |
Tries to reconnect this client to the server. The return value does not mean the connection is established! It only tells you that the reconnect operation succeeded. When the connection is established the onConnectionOpened function is called. Failure to establish the connection results in the onConnectionFailed function to be called.
error | contains the error if the reconnect operation failed. |
|
protected |
Web-socket connection.
ResourcePtr<IWebSocketClientEndPoint> mEndPoint |
Property: 'EndPoint' the client endpoint that manages all connections.
ResourcePtr<WebSocketTicket> mTicket = nullptr |
Property: 'Ticket' optional identification token.
std::string mURI |
Property: "URI" Server URI to open connection to.