NDEVR
API Documentation
SocketIO.h
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"
40#include "Base/Headers/Dictionary.h"
41#include "Base/Headers/Pointer.hpp"
42#include "Base/Headers/UUID.h"
43namespace NDEVR
44{
45 class SocketIOChannel;
46 using namespace sio;
50 class SOCKET_IO_API SocketIO : public QObject
51 {
52 protected:
56 explicit SocketIO(QObject *parent = 0);
57 public:
64 static DynamicPointer<SocketIO> GetSocketIO(const StringView& url = "http://ndevr.org:3000");
68 void setName(const StringView& name);
72 void setRunID(const UUID& run_id);
77 bool connect(const StringView& url = "http://ndevr.org:3000");
79 void close();
85 DynamicPointer<SocketIOChannel> createChannel(const StringView& name, UUID target = Constant<UUID>::Invalid);
92 DynamicPointer<SocketIOChannel> createChannel(const StringView& name, std::function<void(const char* data, uint04 size)> data_callback, UUID target = Constant<UUID>::Invalid);
108 bool isConnected() const { return m_is_connected; }
112 const String& url() const { return m_url; }
113 private:
115 void OnNewMessage(std::string const& name, message::ptr const& data, bool hasAck, message::list &ack_resp);
117 void OnUserJoined(std::string const& name, message::ptr const& data, bool hasAck, message::list &ack_resp);
119 void OnUserLeft(std::string const& name, message::ptr const& data, bool hasAck, message::list &ack_resp);
121 void OnLogin(std::string const& name, message::ptr const& data, bool hasAck, message::list &ack_resp);
123 void OnConnected(std::string const& nsp);
125 void OnClosed(client::close_reason const& reason);
127 void OnFailed();
128 bool m_is_connected;
129 std::unique_ptr<client> _io;
130 Dictionary<UUID, String> m_online_users;
131 String m_name;
132 UUID m_run_id;
133 String m_url = String("ws://localhost:3000");
135 static Dictionary<String, DynamicPointer<SocketIO>> s_server_channels;
136
137 };
138}
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
A specific channel of communication within the SocketIO framework.
DynamicPointer< SocketIOChannel > createChannel(const StringView &name, UUID target=Constant< UUID >::Invalid)
Creates a new communication channel with the given name.
void removeChannel(DynamicPointer< SocketIOChannel > &channel)
Removes a channel from this connection.
DynamicPointer< SocketIOChannel > createChannel(const StringView &name, std::function< void(const char *data, uint04 size)> data_callback, UUID target=Constant< UUID >::Invalid)
Creates a new communication channel with a data receive callback.
void setName(const StringView &name)
Sets the display name for this client.
const String & url() const
Gets the current server URL.
Definition SocketIO.h:112
SocketIO(QObject *parent=0)
Constructs a SocketIO instance.
~SocketIO()
Destructor.
void close()
Closes the current connection.
bool isConnected() const
Checks whether the client is currently connected.
Definition SocketIO.h:108
const Dictionary< UUID, String > & onlineClients() const
Gets the dictionary of currently online clients.
void addChannel(DynamicPointer< SocketIOChannel > &channel)
Adds an existing channel to this connection.
bool connect(const StringView &url="http://ndevr.org:3000")
Connects to a SocketIO server at the given URL.
void setRunID(const UUID &run_id)
Sets the run ID for this session.
static DynamicPointer< SocketIO > GetSocketIO(const StringView &url="http://ndevr.org:3000")
Gets or creates a shared SocketIO instance for the given URL.
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...