NAP
websocketevent.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 "websocketmessage.h"
9 #include "websocketconnection.h"
10 
11 // External Includes
12 #include <nap/event.h>
13 
14 namespace nap
15 {
19  class NAPAPI WebSocketEvent : public Event
20  {
21  RTTI_ENABLE(Event)
22  };
23 
24 
29  {
30  RTTI_ENABLE(WebSocketEvent)
31  public:
33  mConnection(connection) { }
34 
36  };
37 
38 
44  {
45  RTTI_ENABLE(WebSocketConnectionEvent)
46  public:
47  WebSocketConnectionClosedEvent(const WebSocketConnection& connection, int errorCode, const std::string& reason) :
48  WebSocketConnectionEvent(connection), mErrorCode(errorCode), mReason(reason) { }
49 
50  WebSocketConnectionClosedEvent(const WebSocketConnection& connection, int errorCode, std::string&& reason) :
51  WebSocketConnectionEvent(connection), mErrorCode(errorCode), mReason(std::move(reason)) { }
52 
53  int mErrorCode = -1;
54  std::string mReason;
55  };
56 
57 
63  {
64  RTTI_ENABLE(WebSocketConnectionEvent)
65  public:
67  WebSocketConnectionEvent(connection) { }
68  };
69 
70 
76  {
77  RTTI_ENABLE(WebSocketConnectionEvent)
78  public:
79  WebSocketConnectionFailedEvent(const WebSocketConnection& connection, int errorCode, const std::string& reason) :
80  WebSocketConnectionEvent(connection), mErrorCode(errorCode), mReason(reason) { }
81 
82  WebSocketConnectionFailedEvent(const WebSocketConnection& connection, int errorCode, std::string&& reason) :
83  WebSocketConnectionEvent(connection), mErrorCode(errorCode), mReason(reason) { }
84 
85  int mErrorCode = -1;
86  std::string mReason;
87  };
88 
89 
96  {
97  RTTI_ENABLE(WebSocketEvent)
98  public:
100  mConnection(connection), mMessage(message) { }
101 
103  mConnection(connection),
104  mMessage(std::move(message)) { }
105 
108  };
109 
110  using WebSocketEventPtr = std::unique_ptr<nap::WebSocketEvent>;
111 }
nap::WebSocketConnection
Definition: websocketconnection.h:27
nap::WebSocketConnectionFailedEvent::WebSocketConnectionFailedEvent
WebSocketConnectionFailedEvent(const WebSocketConnection &connection, int errorCode, std::string &&reason)
Definition: websocketevent.h:82
nap::WebSocketConnectionClosedEvent::mReason
std::string mReason
Reason for closing connection.
Definition: websocketevent.h:54
nap::WebSocketMessageReceivedEvent::mMessage
WebSocketMessage mMessage
Message received from a client or server.
Definition: websocketevent.h:107
nap::WebSocketConnectionOpenedEvent::WebSocketConnectionOpenedEvent
WebSocketConnectionOpenedEvent(const WebSocketConnection &connection)
Definition: websocketevent.h:66
nap::Event
Definition: event.h:17
nap::WebSocketConnectionClosedEvent::WebSocketConnectionClosedEvent
WebSocketConnectionClosedEvent(const WebSocketConnection &connection, int errorCode, const std::string &reason)
Definition: websocketevent.h:47
nap::WebSocketConnectionEvent::mConnection
WebSocketConnection mConnection
Definition: websocketevent.h:35
nap::WebSocketConnectionClosedEvent
Definition: websocketevent.h:43
nap::WebSocketMessageReceivedEvent::WebSocketMessageReceivedEvent
WebSocketMessageReceivedEvent(const WebSocketConnection &connection, WebSocketMessage &&message)
Definition: websocketevent.h:102
nap::WebSocketMessage
Definition: websocketmessage.h:29
nap::WebSocketMessageReceivedEvent::mConnection
WebSocketConnection mConnection
Handle to the client or server connection.
Definition: websocketevent.h:106
nap::WebSocketConnectionOpenedEvent
Definition: websocketevent.h:62
nap::WebSocketConnectionFailedEvent::WebSocketConnectionFailedEvent
WebSocketConnectionFailedEvent(const WebSocketConnection &connection, int errorCode, const std::string &reason)
Definition: websocketevent.h:79
nap::WebSocketConnectionFailedEvent::mReason
std::string mReason
Reason for failing to establish connection.
Definition: websocketevent.h:86
nap::WebSocketConnectionEvent::WebSocketConnectionEvent
WebSocketConnectionEvent(const WebSocketConnection &connection)
Definition: websocketevent.h:32
nap::WebSocketEvent
Definition: websocketevent.h:19
nap::WebSocketMessageReceivedEvent
Definition: websocketevent.h:95
nap::WebSocketEventPtr
std::unique_ptr< nap::WebSocketEvent > WebSocketEventPtr
Definition: websocketevent.h:110
nap
Definition: templateapp.h:17
nap::WebSocketMessageReceivedEvent::WebSocketMessageReceivedEvent
WebSocketMessageReceivedEvent(const WebSocketConnection &connection, const WebSocketMessage &message)
Definition: websocketevent.h:99
nap::WebSocketConnectionClosedEvent::WebSocketConnectionClosedEvent
WebSocketConnectionClosedEvent(const WebSocketConnection &connection, int errorCode, std::string &&reason)
Definition: websocketevent.h:50
nap::WebSocketConnectionFailedEvent
Definition: websocketevent.h:75
nap::WebSocketConnectionEvent
Definition: websocketevent.h:28