mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
webrtc: Show provide status about the RTCPeerConnection via the REST API
Signed-off-by: Steffen Vogel <steffen.vogel@opal-rt.com>
This commit is contained in:
parent
7ad3dff578
commit
82ea02884d
5 changed files with 43 additions and 0 deletions
|
@ -106,6 +106,12 @@ protected:
|
|||
return -1;
|
||||
}
|
||||
|
||||
virtual
|
||||
json_t * _readStatus() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
/** Initialize node with default values */
|
||||
Node(const uuid_t &id = {}, const std::string &name = "");
|
||||
|
|
|
@ -47,6 +47,9 @@ protected:
|
|||
virtual
|
||||
int _write(struct Sample *smps[], unsigned cnt);
|
||||
|
||||
virtual
|
||||
json_t * _readStatus() const;
|
||||
|
||||
public:
|
||||
WebRTCNode(const uuid_t &id = {}, const std::string &name = "");
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <jansson.h>
|
||||
#include <rtc/rtc.hpp>
|
||||
|
||||
#include <villas/log.hpp>
|
||||
|
@ -31,6 +32,8 @@ public:
|
|||
void onMessage(std::function<void(rtc::binary)> callback);
|
||||
void sendMessage(rtc::binary msg);
|
||||
|
||||
json_t * readStatus() const;
|
||||
|
||||
void connect();
|
||||
void disconnect();
|
||||
|
||||
|
|
|
@ -463,6 +463,10 @@ json_t * Node::toJson() const
|
|||
if (stats)
|
||||
json_object_set_new(json_node, "stats", stats->toJson());
|
||||
|
||||
auto *status = _readStatus();
|
||||
if (status)
|
||||
json_object_set_new(json_node, "status", status);
|
||||
|
||||
/* Add all additional fields of node here.
|
||||
* This can be used for metadata */
|
||||
json_object_update(json_node, config);
|
||||
|
|
|
@ -10,9 +10,11 @@
|
|||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/ostream.h>
|
||||
#include <fmt/chrono.h>
|
||||
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/exceptions.hpp>
|
||||
#include <villas/nodes/webrtc/peer_connection.hpp>
|
||||
|
@ -79,6 +81,31 @@ bool PeerConnection::waitForDataChannel(std::chrono::seconds timeout)
|
|||
return startupCondition.wait_until(lock, deadline, [this](){ return this->stopStartup; });
|
||||
}
|
||||
|
||||
json_t * PeerConnection::readStatus()
|
||||
{
|
||||
auto *json = json_pack("{ s: I, s: I }",
|
||||
"bytes_received", conn->bytesReceived(),
|
||||
"bytes_sent", conn->bytesSent()
|
||||
);
|
||||
|
||||
auto rtt = conn->rtt();
|
||||
if (rtt.has_value()) {
|
||||
auto *json_rtt = json_real(rtt.value().count() / 1e3);
|
||||
json_object_set_new(json, "rtt", json_rtt);
|
||||
}
|
||||
|
||||
rtc::Candidate local, remote;
|
||||
if (conn->getSelectedCandidatePair(&local, &remote)) {
|
||||
auto *json_cp = json_pack("{ s: s, s: s }",
|
||||
"local", std::string(local).c_str(),
|
||||
"remote", std::string(remote).c_str()
|
||||
);
|
||||
json_object_set_new(json, "candidate_pair", json_cp);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
void PeerConnection::notifyStartup()
|
||||
{
|
||||
stopStartup = true;
|
||||
|
|
Loading…
Add table
Reference in a new issue