ofxHTTP
A collection of tools for HTTP.
ofx::HTTP::WebSocketRoute Class Reference

A route for handling WebSockets. More...

#include <WebSocketRoute.h>

Inheritance diagram for ofx::HTTP::WebSocketRoute:
ofx::HTTP::BaseRoute_< WebSocketRouteSettings > ofx::HTTP::AbstractRoute ofx::HTTP::AbstractHTTPRequestHandler ofx::HTTP::AbstractHTTPRequestHandlerFactory ofx::HTTP::AbstractServerEventRequestHandler

Public Types

typedef WebSocketRouteSettings Settings
 A typedef for the WebSocketRouteSettings.
 

Public Member Functions

 WebSocketRoute (const Settings &settings)
 Create a WebSocketRoute with the given Settings. More...
 
virtual ~WebSocketRoute ()
 Destroy the WebSocketRoute.
 
virtual bool canHandleRequest (const Poco::Net::HTTPServerRequest &request, bool isSecurePort) const override
 Determine if this route can handle the given request. More...
 
virtual Poco::Net::HTTPRequestHandler * createRequestHandler (const Poco::Net::HTTPServerRequest &request) override
 Creates a new HTTPRequestHandler for the given request. More...
 
virtual void stop () override
 Stop any pending activity and close this route. More...
 
void broadcast (const WebSocketFrame &frame)
 Send a WebSocketFrame to all connected websockets. More...
 
template<class ListenerClass >
void registerWebSocketEvents (ListenerClass *listener, int priority=OF_EVENT_ORDER_AFTER_APP)
 Register event listeners for this route. More...
 
template<class ListenerClass >
void unregisterWebSocketEvents (ListenerClass *listener, int priority=OF_EVENT_ORDER_AFTER_APP)
 Unregister event listeners for this route. More...
 
std::size_t numConnections () const
 
const std::vector< std::unique_ptr< AbstractWebSocketFilterFactory > > & filterFactories () const
 
- Public Member Functions inherited from ofx::HTTP::BaseRoute_< WebSocketRouteSettings >
 BaseRoute_ (const WebSocketRouteSettings &settings=WebSocketRouteSettings())
 Create a BaseRoute. More...
 
virtual ~BaseRoute_ ()
 Destroy a BaseRoute.
 
virtual void setup (const WebSocketRouteSettings &settings)
 Setup the route with settings. More...
 
virtual std::string routePathPattern () const override
 Get the route's regex path pattern. More...
 
void handleRequest (Poco::Net::HTTPServerRequest &request, Poco::Net::HTTPServerResponse &response) override
 
virtual void handleRequest (ServerEventArgs &evt) override
 Handle the ServerEventArgs. More...
 
const WebSocketRouteSettingssettings () const
 
AbstractServergetServer () override
 
void setServer (AbstractServer *server) override
 Set the server that owns this route. More...
 
- Public Member Functions inherited from ofx::HTTP::AbstractRoute
virtual ~AbstractRoute ()
 Destroy the AbstractRoute instance.
 
- Public Member Functions inherited from ofx::HTTP::AbstractHTTPRequestHandler
virtual ~AbstractHTTPRequestHandler ()
 Destroy the AbstractHTTPRequestHandler.
 
- Public Member Functions inherited from ofx::HTTP::AbstractServerEventRequestHandler
virtual ~AbstractServerEventRequestHandler ()
 Destroy the AbstractServerEventRequestHandler.
 
- Public Member Functions inherited from ofx::HTTP::AbstractHTTPRequestHandlerFactory
virtual ~AbstractHTTPRequestHandlerFactory ()
 Destroy the AbstractHTTPRequestHandlerFactory.
 

Public Attributes

WebSocketEvents events
 WebSocketEvents for WebSocket callbacks.
 

Protected Member Functions

void registerConnection (WebSocketConnection *connection)
 
void unregisterConnection (WebSocketConnection *connection)
 

Friends

class WebSocketConnection
 

Additional Inherited Members

- Protected Attributes inherited from ofx::HTTP::BaseRoute_< WebSocketRouteSettings >
WebSocketRouteSettings _settings
 The settings.
 
AbstractServer_server
 A pointer to the server.
 

Detailed Description

A route for handling WebSockets.

Constructor & Destructor Documentation

◆ WebSocketRoute()

ofx::HTTP::WebSocketRoute::WebSocketRoute ( const Settings settings)

Create a WebSocketRoute with the given Settings.

Parameters
settingsThe WebSocketRoute settings.

Member Function Documentation

◆ broadcast()

void ofx::HTTP::WebSocketRoute::broadcast ( const WebSocketFrame frame)

Send a WebSocketFrame to all connected websockets.

Parameters
frameThe frame to send.

◆ canHandleRequest()

bool ofx::HTTP::WebSocketRoute::canHandleRequest ( const Poco::Net::HTTPServerRequest &  request,
bool  isSecurePort 
) const
overridevirtual

Determine if this route can handle the given request.

Parameters
requestThe incoming Poco::Net::HTTPServerRequest to be tested.
isSecurePorttrue iff the connection is SSL encrypted. Some implmenetations of this interface may choose to only handle requests on secure ports.
Returns
true iff the route can handle the given request.

Reimplemented from ofx::HTTP::BaseRoute_< WebSocketRouteSettings >.

◆ createRequestHandler()

Poco::Net::HTTPRequestHandler * ofx::HTTP::WebSocketRoute::createRequestHandler ( const Poco::Net::HTTPServerRequest &  request)
overridevirtual

Creates a new HTTPRequestHandler for the given request.

Before this is called, it is expected that the calling server has confirmed that this route is capable of handling the request by calling canHandleRequest().

Parameters
requestThe HTTPServerRequest to be passed to the handler.
Returns
An HTTPRequestHandler that will handle the request.
Note
Redeclared here for documentation puposes.

Reimplemented from ofx::HTTP::BaseRoute_< WebSocketRouteSettings >.

◆ filterFactories()

const std::vector< std::unique_ptr< AbstractWebSocketFilterFactory > > & ofx::HTTP::WebSocketRoute::filterFactories ( ) const
Returns
a reference to the filter factories.

◆ numConnections()

std::size_t ofx::HTTP::WebSocketRoute::numConnections ( ) const
Returns
The number of active connections.

◆ registerWebSocketEvents()

template<class ListenerClass >
void ofx::HTTP::WebSocketRoute::registerWebSocketEvents ( ListenerClass *  listener,
int  priority = OF_EVENT_ORDER_AFTER_APP 
)

Register event listeners for this route.

The listener class must implement the following callbacks:

onWebSocketOpenEvent(...), onWebSocketCloseEvent(...), onWebSocketFrameReceivedEvent(...), onWebSocketFrameSentEvent(...), onWebSocketErrorEvent(...).

Template Parameters
ListenerClassThe lister class to register.
Parameters
listenerA pointer to the listener class.
priorityThe listener priority.

◆ stop()

void ofx::HTTP::WebSocketRoute::stop ( )
overridevirtual

Stop any pending activity and close this route.

This method may block until the route is fully stopped.

Reimplemented from ofx::HTTP::BaseRoute_< WebSocketRouteSettings >.

◆ unregisterWebSocketEvents()

template<class ListenerClass >
void ofx::HTTP::WebSocketRoute::unregisterWebSocketEvents ( ListenerClass *  listener,
int  priority = OF_EVENT_ORDER_AFTER_APP 
)

Unregister event listeners for this route.

Template Parameters
ListenerClassThe lister class to uregister.
Parameters
listenerA pointer to the listener class.
priorityThe listener priority.

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