NAP
apiwebsocketevent.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 <websocketconnection.h>
10 #include <websocketinterface.h>
11 
12 namespace nap
13 {
14  /*
15  * Adds web-socket functionality to a default nap::APIEvent. Use getConnection()
16  * to access the webs-socket connection handle to the client or server. Note
17  * that the handle could be invalid when a client or server disconnected or the connection
18  * failed to establish. Use getInterface() to access the client or server associated with event. Most
19  * likely the interface is a nap::APIWebSocketClient or nap::APIWebSocketServer.
20  */
21  class NAPAPI APIWebSocketEvent : public APIEvent
22  {
23  RTTI_ENABLE(APIEvent)
24  public:
32  APIWebSocketEvent(const std::string& name, const WebSocketConnection& connection,
33  WebSocketInterface& wsInterface);
34 
42  APIWebSocketEvent(std::string&& name, const WebSocketConnection& connection,
43  WebSocketInterface& wsInterface);
44 
54  APIWebSocketEvent(const std::string& name, const std::string& id, const WebSocketConnection& connection,
55  WebSocketInterface& wsInterface);
56 
66  APIWebSocketEvent(std::string&& name, std::string&& id, const WebSocketConnection& connection,
67  WebSocketInterface& wsInterface);
68 
72  const WebSocketConnection& getConnection() const { return mConnection; }
73 
79  WebSocketInterface& getInterface();
80 
86  const WebSocketInterface& getInterface() const;
87 
88  private:
89  WebSocketConnection mConnection;
90  WebSocketInterface* mInterface = nullptr;
91  };
92 
93  using APIWebSocketEventPtr = std::unique_ptr<APIWebSocketEvent>;
94 }
nap::WebSocketConnection
Definition: websocketconnection.h:27
nap::APIWebSocketEventPtr
std::unique_ptr< APIWebSocketEvent > APIWebSocketEventPtr
Definition: apiwebsocketevent.h:93
nap::APIWebSocketEvent
Definition: apiwebsocketevent.h:21
nap
Definition: templateapp.h:17
nap::WebSocketInterface
Definition: websocketinterface.h:28
nap::APIWebSocketEvent::getConnection
const WebSocketConnection & getConnection() const
Definition: apiwebsocketevent.h:72
nap::APIEvent
Definition: apievent.h:37