mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
webrtc: Renamed signaling connection to peer
Signed-off-by: Steffen Vogel <steffen.vogel@opal-rt.com>
This commit is contained in:
parent
0445d671dc
commit
94636e8b09
3 changed files with 42 additions and 32 deletions
|
@ -22,13 +22,14 @@ namespace villas {
|
|||
namespace node {
|
||||
namespace webrtc {
|
||||
|
||||
struct Connection {
|
||||
struct Peer {
|
||||
int id;
|
||||
std::string name;
|
||||
std::string remote;
|
||||
std::string userAgent;
|
||||
std::chrono::time_point<std::chrono::system_clock> created;
|
||||
|
||||
Connection(json_t *j);
|
||||
Peer(json_t *j);
|
||||
json_t * toJSON() const;
|
||||
};
|
||||
|
||||
|
@ -39,8 +40,8 @@ struct RelayMessage {
|
|||
};
|
||||
|
||||
struct ControlMessage {
|
||||
int connectionID;
|
||||
std::vector<Connection> connections;
|
||||
int peerID;
|
||||
std::vector<Peer> peers;
|
||||
|
||||
ControlMessage(json_t *j);
|
||||
json_t * toJSON() const;
|
||||
|
|
|
@ -294,15 +294,15 @@ void PeerConnection::onSignalingMessage(SignalingMessage msg)
|
|||
},
|
||||
|
||||
[&](ControlMessage &c){
|
||||
auto const &id = c.connectionID;
|
||||
auto const &id = c.peerID;
|
||||
|
||||
if (c.connections.size() < 2) {
|
||||
if (c.peers.size() < 2) {
|
||||
resetConnectionAndStandby(lock);
|
||||
return;
|
||||
}
|
||||
|
||||
auto fst = INT_MAX, snd = INT_MAX;
|
||||
for (auto &c : c.connections) {
|
||||
for (auto &c : c.peers) {
|
||||
if (c.id < fst) {
|
||||
snd = fst;
|
||||
fst = c.id;
|
||||
|
|
|
@ -17,33 +17,42 @@ using namespace villas;
|
|||
using namespace villas::node;
|
||||
using namespace villas::node::webrtc;
|
||||
|
||||
json_t * Connection::toJSON() const
|
||||
json_t * Peer::toJSON() const
|
||||
{
|
||||
return json_pack("{ s:i, s:s, s:s, s:s }",
|
||||
return json_pack("{ s:i, s:s*, s:s*, s:s* }",
|
||||
"id", id,
|
||||
"remote", remote.c_str(),
|
||||
"user_agent", userAgent.c_str(),
|
||||
"created", "" // TODO: create json timestamp
|
||||
"name", name.empty() ? nullptr : name.c_str(),
|
||||
"remote", remote.empty() ? nullptr : remote.c_str(),
|
||||
"user_agent", userAgent.empty() ? nullptr : userAgent.c_str()
|
||||
// TODO: created, connected
|
||||
);
|
||||
}
|
||||
|
||||
Connection::Connection(json_t *json)
|
||||
Peer::Peer(json_t *json)
|
||||
{
|
||||
const char *rem, *ua, *ts;
|
||||
const char *nme = nullptr, *rem = nullptr, *ua = nullptr, *tscreat, *tsconn;
|
||||
|
||||
int ret = json_unpack(json, "{ s:i, s:s, s:s, s:s }",
|
||||
int ret = json_unpack(json, "{ s:i, s?:s, s?:s, s?:s, s?:s, s?: s }",
|
||||
"id", &id,
|
||||
"name", &nme,
|
||||
"remote", &rem,
|
||||
"user_agent", &ua,
|
||||
"created", &ts
|
||||
"created", &tscreat,
|
||||
"connected", &tsconn
|
||||
);
|
||||
if (ret)
|
||||
throw RuntimeError("Failed to decode signaling message");
|
||||
|
||||
remote = rem;
|
||||
userAgent = ua;
|
||||
if (nme)
|
||||
name = nme;
|
||||
|
||||
// TODO: created
|
||||
if (rem)
|
||||
remote = rem;
|
||||
|
||||
if (ua)
|
||||
userAgent = ua;
|
||||
|
||||
// TODO: created, connected
|
||||
}
|
||||
|
||||
RelayMessage::RelayMessage(json_t *json)
|
||||
|
@ -82,17 +91,17 @@ RelayMessage::RelayMessage(json_t *json)
|
|||
|
||||
json_t * ControlMessage::toJSON() const
|
||||
{
|
||||
json_t *json_connections = json_array();
|
||||
json_t *json_peers = json_array();
|
||||
|
||||
for (auto &c : connections) {
|
||||
json_t *json_connection = c.toJSON();
|
||||
for (auto &p : peers) {
|
||||
json_t *json_peer = p.toJSON();
|
||||
|
||||
json_array_append_new(json_connections, json_connection);
|
||||
json_array_append_new(json_peers, json_peer);
|
||||
}
|
||||
|
||||
return json_pack("{ s:i, s:o }",
|
||||
"connection_id", connectionID,
|
||||
"connections", json_connections
|
||||
"peer_id", peerID,
|
||||
"peers", json_peers
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -100,23 +109,23 @@ ControlMessage::ControlMessage(json_t *j)
|
|||
{
|
||||
int ret;
|
||||
|
||||
json_t *json_connections;
|
||||
json_t *json_peers;
|
||||
|
||||
ret = json_unpack(j, "{ s:i, s:o }",
|
||||
"connection_id", &connectionID,
|
||||
"connections", &json_connections
|
||||
"peer_id", &peerID,
|
||||
"peers", &json_peers
|
||||
);
|
||||
if (ret)
|
||||
throw RuntimeError("Failed to decode signaling message");
|
||||
|
||||
if (!json_is_array(json_connections))
|
||||
if (!json_is_array(json_peers))
|
||||
throw RuntimeError("Failed to decode signaling message");
|
||||
|
||||
json_t *json_connection;
|
||||
json_t *json_peer;
|
||||
size_t i;
|
||||
// cppcheck-suppress unknownMacro
|
||||
json_array_foreach(json_connections, i, json_connection)
|
||||
connections.emplace_back(json_connection);
|
||||
json_array_foreach(json_peers, i, json_peer)
|
||||
peers.emplace_back(json_peer);
|
||||
}
|
||||
|
||||
json_t * SignalingMessage::toJSON() const
|
||||
|
|
Loading…
Add table
Reference in a new issue