NAP
iwebsocketserverendpoint.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 // Local Includes
8 #include "websocketutils.h"
9 #include "websocketticket.h"
10 #include "websocketconnection.h"
11 
12 // External Includes
13 #include <utility/errorstate.h>
14 #include <nap/device.h>
15 #include <nap/resourceptr.h>
16 
17 namespace nap
18 {
19  // Forward declares
20  class IWebSocketServer;
21 
65  class NAPAPI IWebSocketServerEndPoint : public Device
66  {
67  friend class IWebSocketServer;
68  RTTI_ENABLE(Device)
69  public:
70 
74  enum class EAccessMode : int
75  {
76  EveryOne = 0,
77  Ticket = 1,
78  Reserved = 2
79  };
80 
84  virtual bool isOpen() const = 0;
85 
94  virtual bool send(const WebSocketConnection& connection, const std::string& message, EWebSocketOPCode code, nap::utility::ErrorState& error) = 0;
95 
105  virtual bool send(const WebSocketConnection& connection, void const* payload, int length, EWebSocketOPCode code, nap::utility::ErrorState& error) = 0;
106 
114  virtual bool broadcast(const std::string& message, EWebSocketOPCode code, nap::utility::ErrorState& error) = 0;
115 
124  virtual bool broadcast(void const* payload, int length, EWebSocketOPCode code, nap::utility::ErrorState& error) = 0;
125 
129  virtual std::string getHostName(const WebSocketConnection& connection) = 0;
130 
135  virtual void getHostNames(std::vector<std::string>& outHosts) = 0;
136 
140  virtual int getConnectionCount() = 0;
141 
145  virtual bool acceptsNewConnections() = 0;
146 
147  EAccessMode mMode = EAccessMode::EveryOne;
148  int mConnectionLimit = -1;
149  int mPort = 80;
150  bool mLogConnectionUpdates = true;
151  bool mAllowPortReuse = false;
153  std::vector<ResourcePtr<WebSocketTicket>> mClients;
154  std::string mAccessAllowControlOrigin = "*";
155  std::string mIPAddress = "";
156 
157  protected:
162  virtual void registerListener(IWebSocketServer& server) = 0;
163 
168  virtual void unregisterListener(IWebSocketServer& server) = 0;
169  };
170 }
nap::WebSocketConnection
Definition: websocketconnection.h:27
nap::IWebSocketServerEndPoint::EAccessMode
EAccessMode
Definition: iwebsocketserverendpoint.h:74
nap::utility::ErrorState
Definition: errorstate.h:19
nap::IWebSocketServerEndPoint
Definition: iwebsocketserverendpoint.h:65
nap::EWebSocketLogLevel::Warning
@ Warning
Information about important problems not severe enough to close connection.
nap::IWebSocketServerEndPoint::mClients
std::vector< ResourcePtr< WebSocketTicket > > mClients
Property: "Clients" All authorized clients when mode is set to 'Reserved'".
Definition: iwebsocketserverendpoint.h:153
nap
Definition: templateapp.h:17
nap::IWebSocketServer
Definition: websocketserver.h:22
nap::EWebSocketOPCode
EWebSocketOPCode
Definition: websocketutils.h:29
nap::EWebSocketLogLevel
EWebSocketLogLevel
Definition: websocketutils.h:17
nap::Device
Definition: device.h:20