API Documentation
Loading...
Searching...
No Matches
SocketIO.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Hardware
28File: SocketIO
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <QListWidget>
34#include <QTimer>
35#include <string>
36#undef emit
37#include <sio_client.h>
38#include "DLLInfo.h"
39#include "Base/Headers/String.h"
42#include "Base/Headers/UUID.h"
43namespace NDEVR
44{
45 class SocketIOChannel;
46 using namespace sio;
47 /**--------------------------------------------------------------------------------------------------
48 \brief Provides the ability to communicate over a network using SocketIO (https://socket.io/docs/v4/)
49 **/
50 class SOCKET_IO_API SocketIO : public QObject
51 {
52 protected:
53 explicit SocketIO(QObject *parent = 0);
54 public:
56 static DynamicPointer<SocketIO> GetSocketIO(const String& url = "http://ndevr.org:3000");
57 void setName(const String& name);
58 void setRunID(const UUID& run_id);
59 bool connect(const String& url = "http://ndevr.org:3000");
60 void close();
62 DynamicPointer<SocketIOChannel> createChannel(const String& name, std::function<void(const char* data, uint04 size)> data_callback, UUID target = Constant<UUID>::Invalid);
66 bool isConnected() const { return m_is_connected; }
67 const String& url() const { return m_url; }
68 private:
69 void OnNewMessage(std::string const& name, message::ptr const& data, bool hasAck, message::list &ack_resp);
70 void OnUserJoined(std::string const& name, message::ptr const& data, bool hasAck, message::list &ack_resp);
71 void OnUserLeft(std::string const& name, message::ptr const& data, bool hasAck, message::list &ack_resp);
72 void OnLogin(std::string const& name, message::ptr const& data, bool hasAck, message::list &ack_resp);
73 void OnConnected(std::string const& nsp);
74 void OnClosed(client::close_reason const& reason);
75 void OnFailed();
76 bool m_is_connected;
77 std::unique_ptr<client> _io;
78 Dictionary<UUID, String> m_online_users;
79 String m_name;
80 UUID m_run_id;
81 String m_url = "ws://localhost:3000";
83 static Dictionary<String, DynamicPointer<SocketIO>> s_server_channels;
84
85 };
86}
#define SOCKET_IO_API
Definition DLLInfo.h:55
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:320
Provides the ability to communicate over a network using SocketIO (https://socket....
Definition SocketIO.h:51
DynamicPointer< SocketIOChannel > createChannel(const String &name, UUID target=Constant< UUID >::Invalid)
static DynamicPointer< SocketIO > GetSocketIO(const String &url="http://ndevr.org:3000")
bool connect(const String &url="http://ndevr.org:3000")
SocketIO(QObject *parent=0)
DynamicPointer< SocketIOChannel > createChannel(const String &name, std::function< void(const char *data, uint04 size)> data_callback, UUID target=Constant< UUID >::Invalid)
void addChannel(DynamicPointer< SocketIOChannel > &channel)
void setName(const String &name)
bool isConnected() const
Definition SocketIO.h:66
const Dictionary< UUID, String > & onlineClients() const
void removeChannel(DynamicPointer< SocketIOChannel > &channel)
void setRunID(const UUID &run_id)
const String & url() const
Definition SocketIO.h:67
The core String class for the NDEVR API.
Definition String.h:69
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:60
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233