NAP
apiwebsocketserver.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // External Includes
8 #include <apievent.h>
9 #include <websocketserver.h>
10 
11 namespace nap
12 {
13  // Forward Declares
14  class APIWebSocketService;
15  class APIService;
16 
87  class NAPAPI APIWebSocketServer : public IWebSocketServer
88  {
89  RTTI_ENABLE(IWebSocketServer)
90  public:
96 
122  bool send(nap::APIEventPtr apiEvent, const WebSocketConnection& connection, utility::ErrorState& error);
123 
130  bool broadcast(nap::APIEventPtr apiEvent, nap::utility::ErrorState& error);
131 
132  bool mSendWebSocketEvents = true;
133  bool mVerbose = true;
134 
135  private:
136 
144  void sendErrorReply(const WebSocketConnection& connection, nap::utility::ErrorState& error);
145 
146  // Called by web-socket server endpoint when a new message is received
147  virtual void onMessageReceived(const WebSocketConnection& connection, const WebSocketMessage& message) override;
148 
149  // Called by web-socket server endpoint when a client connection opened
150  virtual void onConnectionOpened(const WebSocketConnection& connection) override;
151 
152  // Called by web-socket server endpoint when a client connection closed
153  virtual void onConnectionClosed(const WebSocketConnection& connection, int code, const std::string& reason) override;
154 
155  // Called by web-socket server endpoint when a client connection failed to extablish
156  virtual void onConnectionFailed(const WebSocketConnection& connection, int code, const std::string& reason) override;
157 
158  APIService* mAPIService = nullptr;
159  };
160 
161  // Object creator used for constructing the api web-socket server
163 }
nap::WebSocketConnection
Definition: websocketconnection.h:27
nap::APIWebSocketServer
Definition: apiwebsocketserver.h:87
nap::rtti::ObjectCreator
Definition: factory.h:49
nap::utility::ErrorState
Definition: errorstate.h:19
nap::APIService
Definition: apiservice.h:47
nap::WebSocketMessage
Definition: websocketmessage.h:29
nap::APIEventPtr
std::unique_ptr< nap::APIEvent > APIEventPtr
Definition: apievent.h:179
nap
Definition: templateapp.h:17
nap::IWebSocketServer
Definition: websocketserver.h:22
nap::APIWebSocketService
Definition: apiwebsocketservice.h:18