mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
webrtc: Add peer option
Signed-off-by: Steffen Vogel <steffen.vogel@opal-rt.com>
This commit is contained in:
parent
94636e8b09
commit
20dc83bee4
6 changed files with 21 additions and 8 deletions
|
@ -30,6 +30,7 @@ class WebRTCNode : public Node {
|
|||
protected:
|
||||
std::string server;
|
||||
std::string session;
|
||||
std::string peer;
|
||||
|
||||
int wait_seconds;
|
||||
Format *format;
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace webrtc {
|
|||
class PeerConnection {
|
||||
|
||||
public:
|
||||
PeerConnection(const std::string &server, const std::string &session, rtc::Configuration config, Web *w, rtc::DataChannelInit d);
|
||||
PeerConnection(const std::string &server, const std::string &session, const std::string &peer, rtc::Configuration config, Web *w, rtc::DataChannelInit d);
|
||||
~PeerConnection();
|
||||
|
||||
bool waitForDataChannel(std::chrono::seconds timeout);
|
||||
|
|
|
@ -81,7 +81,7 @@ protected:
|
|||
int writable();
|
||||
|
||||
public:
|
||||
SignalingClient(const std::string &server, const std::string &session, Web *w);
|
||||
SignalingClient(const std::string &server, const std::string &session, const std::string &peer, Web *w);
|
||||
~SignalingClient();
|
||||
|
||||
static
|
||||
|
|
|
@ -50,14 +50,16 @@ int WebRTCNode::parse(json_t *json, const uuid_t sn_uuid)
|
|||
|
||||
const char *sess;
|
||||
const char *svr = nullptr;
|
||||
const char *pr = nullptr;
|
||||
int ord = -1;
|
||||
int &rexmit = dci.reliability.rexmit.emplace<int>(0);
|
||||
json_t *ice_json = nullptr;
|
||||
json_t *fmt_json = nullptr;
|
||||
|
||||
json_error_t err;
|
||||
ret = json_unpack_ex(json, &err, 0, "{ s:s, s?s, s?i, s?i, s?b, s?o }",
|
||||
ret = json_unpack_ex(json, &err, 0, "{ s:s, s?:s, s?s, s?i, s?i, s?b, s?o }",
|
||||
"session", &sess,
|
||||
"peer", &pr,
|
||||
"server", &svr,
|
||||
"wait_seconds", &wait_seconds,
|
||||
"max_retransmits", &rexmit,
|
||||
|
@ -73,6 +75,9 @@ int WebRTCNode::parse(json_t *json, const uuid_t sn_uuid)
|
|||
if (svr)
|
||||
server = svr;
|
||||
|
||||
if (pr)
|
||||
peer = pr;
|
||||
|
||||
if (ord)
|
||||
dci.reliability.unordered = !ord;
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ PeerConnection::PeerConnection(const std::string &server, const std::string &ses
|
|||
secondID(INT_MAX),
|
||||
onMessageCallback(nullptr)
|
||||
{
|
||||
client = std::make_shared<SignalingClient>(server, session, web);
|
||||
client = std::make_shared<SignalingClient>(server, session, peer, web);
|
||||
client->onConnected([this](){ this->onSignalingConnected(); });
|
||||
client->onDisconnected([this](){ this->onSignalingDisconnected(); });
|
||||
client->onError([this](auto err){ this->onSignalingError(std::move(err)); });
|
||||
|
|
|
@ -7,16 +7,20 @@
|
|||
* @license Apache 2.0
|
||||
*********************************************************************************/
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/web.hpp>
|
||||
#include <villas/exceptions.hpp>
|
||||
#include <villas/nodes/webrtc/signaling_client.hpp>
|
||||
#include <villas/nodes/webrtc/signaling_message.hpp>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
using namespace villas::node;
|
||||
using namespace villas::node::webrtc;
|
||||
|
||||
SignalingClient::SignalingClient(const std::string &srv, const std::string &sess, Web *w) :
|
||||
SignalingClient::SignalingClient(const std::string &server, const std::string &session, const std::string &peer, Web *w) :
|
||||
retry_count(0),
|
||||
web(w),
|
||||
running(false),
|
||||
|
@ -27,10 +31,13 @@ SignalingClient::SignalingClient(const std::string &srv, const std::string &sess
|
|||
|
||||
memset(&info, 0, sizeof(info));
|
||||
|
||||
ret = asprintf(&uri, "%s/%s", srv.c_str(), sess.c_str());
|
||||
ret = asprintf(&uri, "%s/%s", server.c_str(), session.c_str());
|
||||
if (ret < 0)
|
||||
throw RuntimeError { "Could not format signaling server uri" };
|
||||
|
||||
if (!peer.empty())
|
||||
strcatf(&uri, "/%s", peer.c_str());
|
||||
|
||||
ret = lws_parse_uri(uri, &prot, &a, &info.port, &p);
|
||||
if (ret)
|
||||
throw RuntimeError("Failed to parse WebSocket URI: '{}'", uri);
|
||||
|
@ -120,7 +127,7 @@ int SignalingClient::protocolCallback(struct lws *wsi, enum lws_callback_reasons
|
|||
buffer.append((char *) in, len);
|
||||
|
||||
if (lws_is_final_fragment(wsi)) {
|
||||
logger->trace("Received signaling message: {:.{}}", buffer.data(), buffer.size());
|
||||
logger->trace("Signaling message received: {:.{}}", buffer.data(), buffer.size());
|
||||
|
||||
auto *json = buffer.decode();
|
||||
if (json == nullptr) {
|
||||
|
@ -201,7 +208,7 @@ int SignalingClient::writable()
|
|||
if (len > sizeof(buf) - LWS_PRE)
|
||||
return -1;
|
||||
|
||||
logger->trace("Sending signaling message: {:.{}}", buf + LWS_PRE, len);
|
||||
logger->trace("Signaling message send: {:.{}}", buf + LWS_PRE, len);
|
||||
|
||||
auto ret = lws_write(wsi, (unsigned char *) buf + LWS_PRE, len, LWS_WRITE_TEXT);
|
||||
if (ret < 0)
|
||||
|
|
Loading…
Add table
Reference in a new issue