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#ifdef NDEVR_SUPPORTS_SOCKET_IO
40#include "Base/Headers/String.h"
43#include "Base/Headers/UUID.h"
44namespace NDEVR
45{
46 class SocketIOChannel;
47 using namespace sio;
48
49 class SOCKET_IO_API SocketIO : public QObject
50 {
51 protected:
52 explicit SocketIO(QObject *parent = 0);
53 public:
54 ~SocketIO();
55 static DynamicPointer<SocketIO> GetSocketIO(const String& url = "http://ndevr.org:3000");
56 void setName(const String& name);
57 void setRunID(const UUID& run_id);
58 bool connect(const String& url = "http://ndevr.org:3000");
59 void close();
60 DynamicPointer<SocketIOChannel> createChannel(const String& name, UUID target = Constant<UUID>::NaN);
61 DynamicPointer<SocketIOChannel> createChannel(const String& name, std::function<void(const char* data, uint04 size)> data_callback, UUID target = Constant<UUID>::NaN);
62 void addChannel(DynamicPointer<SocketIOChannel>& channel);
63 void removeChannel(DynamicPointer<SocketIOChannel>& channel);
64 const Dictionary<UUID, String>& onlineClients() const;
65 bool isConnected() const { return m_is_connected; }
66 const String& url() const { return m_url; }
67 private:
68 void OnNewMessage(std::string const& name, message::ptr const& data, bool hasAck, message::list &ack_resp);
69 void OnUserJoined(std::string const& name, message::ptr const& data, bool hasAck, message::list &ack_resp);
70 void OnUserLeft(std::string const& name, message::ptr const& data, bool hasAck, message::list &ack_resp);
71 void OnLogin(std::string const& name, message::ptr const& data, bool hasAck, message::list &ack_resp);
72 void OnConnected(std::string const& nsp);
73 void OnClosed(client::close_reason const& reason);
74 void OnFailed();
75 bool m_is_connected;
76 std::unique_ptr<client> _io;
77 Dictionary<UUID, String> m_online_users;
78 String m_name;
79 UUID m_run_id;
80 String m_url = "ws://localhost:3000";
81 Dictionary<String, DynamicPointer<SocketIOChannel>> m_socket_channels;
82 static Dictionary<String, DynamicPointer<SocketIO>> s_server_channels;
83
84 };
85}
86#endif
#define SOCKET_IO_API
Definition DLLInfo.h:73
Definition ACIColor.h:37