reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
KurentoConnection.hxx
Go to the documentation of this file.
1#if !defined(KurentoConnection_hxx)
2#define KurentoConnection_hxx
3
4#include <chrono>
5#include <deque>
6#include <string>
7#include <memory>
8
9#include <websocketpp/config/asio_no_tls_client.hpp>
10#include <websocketpp/client.hpp>
11
12#include "cajun/json/elements.h"
13
15
16// from kms-jsonrpc JsonRpcConstants.hpp
17#define JSON_RPC_PROTO "jsonrpc"
18#define JSON_RPC_PROTO_VERSION "2.0"
19#define JSON_RPC_ID "id"
20#define JSON_RPC_METHOD "method"
21#define JSON_RPC_PARAMS "params"
22#define JSON_RPC_RESULT "result"
23#define JSON_RPC_ERROR "error"
24#define JSON_RPC_ERROR_CODE "code"
25#define JSON_RPC_ERROR_MESSAGE "message"
26#define JSON_RPC_ERROR_DATA "data"
27
28#define JSON_RPC_OBJECT "object"
29#define JSON_RPC_VALUE "value"
30#define JSON_RPC_TYPE "type"
31#define JSON_RPC_SESSION_ID "sessionId"
32#define JSON_RPC_MEDIAPIPELINE "mediaPipeline"
33#define JSON_RPC_SINK "sink"
34
35namespace kurento
36{
37
38typedef websocketpp::client<websocketpp::config::asio_client> client;
39
40class Object;
41
43{
44 public:
46 virtual void onConnected() = 0;
47};
48
50{
51 public:
52 typedef std::shared_ptr<KurentoConnection> ptr;
53
54 KurentoConnection(KurentoConnectionObserver& observer, std::string uri, client& wSClient, std::chrono::milliseconds timeout, std::chrono::milliseconds retryInterval, bool waitForResponse = true);
55 virtual ~KurentoConnection();
56
57 void onRetryRequired();
58
59 void onOpen(client* wSClient, websocketpp::connection_hdl h);
60 void onFail(client* wSClient, websocketpp::connection_hdl h);
61 void onClose(client* wSClient, websocketpp::connection_hdl h);
62 void onMessage(client* wSClient, websocketpp::connection_hdl, client::message_ptr msg);
63
64 std::string sendRequest(std::shared_ptr<KurentoResponseHandler> krh, const std::string& method, const json::Object& params);
65
66 void registerObject(std::shared_ptr<KurentoResponseHandler> object);
67 void unregisterObject(const std::string& objectId);
68
69 private:
70
71 void processSendQueue();
72 void sendMessage(const std::string& msg);
73
74 void onResponse(const std::string& id, std::shared_ptr<KurentoResponseHandler> krh, const json::Object& message);
75 void onEvent(const std::string& eventName, const json::Object& message);
76
78 std::string mUri;
79 client& mWSClient;
80 websocketpp::connection_hdl mHandle;
81 std::chrono::milliseconds mTimeout;
82 std::chrono::milliseconds mRetryInterval;
83 bool mWaitForResponse;
84 bool mRunning = true;
85 unsigned long mNextId = 1;
86 unsigned long mLastResponse = 0;
87 unsigned long mRequestSentCount = 0;
88 unsigned long mResponseReceivedCount = 0;
89 std::string mSessionId;
90 std::deque<std::string> mSendQueue; // FIXME: post events to queue from other threads?
91 typedef std::map<std::string, std::shared_ptr<KurentoResponseHandler> > KurentoResponseHandlerMap;
92 KurentoResponseHandlerMap mResponseHandlers;
93
94 typedef std::map<std::string, std::shared_ptr<Object> > KurentoObjectMap;
95 KurentoObjectMap mObjects;
96
97};
98
99}
100
101#endif
102
103/* ====================================================================
104
105 Copyright (c) 2021, Software Freedom Institute https://softwarefreedom.institute
106 Copyright (c) 2021, Daniel Pocock https://danielpocock.com
107 All rights reserved.
108
109 Redistribution and use in source and binary forms, with or without
110 modification, are permitted provided that the following conditions are
111 met:
112
113 1. Redistributions of source code must retain the above copyright
114 notice, this list of conditions and the following disclaimer.
115
116 2. Redistributions in binary form must reproduce the above copyright
117 notice, this list of conditions and the following disclaimer in the
118 documentation and/or other materials provided with the distribution.
119
120 3. Neither the name of Plantronics nor the names of its contributors
121 may be used to endorse or promote products derived from this
122 software without specific prior written permission.
123
124 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
125 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
126 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
127 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
128 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
129 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
130 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
131 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
132 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
133 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
134 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
135
136 ==================================================================== */
void registerObject(std::shared_ptr< KurentoResponseHandler > object)
void onMessage(client *wSClient, websocketpp::connection_hdl, client::message_ptr msg)
void unregisterObject(const std::string &objectId)
std::shared_ptr< KurentoConnection > ptr
void onOpen(client *wSClient, websocketpp::connection_hdl h)
void onFail(client *wSClient, websocketpp::connection_hdl h)
std::string sendRequest(std::shared_ptr< KurentoResponseHandler > krh, const std::string &method, const json::Object &params)
void onClose(client *wSClient, websocketpp::connection_hdl h)
This class is used in the logging subsystem to identify logging messages generated from the Kurento c...
websocketpp::client< websocketpp::config::asio_client > client
void list()
Definition userAdmin.cxx:66