mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
Merge pull request #670 from VILLASframework/webrtc-signaling-fixes
Webrtc signaling fixes
This commit is contained in:
commit
a688afe379
2 changed files with 21 additions and 24 deletions
|
@ -16,6 +16,7 @@
|
|||
#include <libwebsockets.h>
|
||||
|
||||
#include <villas/queue.hpp>
|
||||
#include <villas/buffer.hpp>
|
||||
#include <villas/web.hpp>
|
||||
#include <villas/log.hpp>
|
||||
#include <villas/nodes/webrtc/signaling_message.hpp>
|
||||
|
@ -68,6 +69,8 @@ protected:
|
|||
|
||||
std::atomic<bool> running;
|
||||
|
||||
Buffer buffer; // A buffer for received fragments before JSON decoding.
|
||||
|
||||
Logger logger;
|
||||
|
||||
int protocolCallback(struct lws *wsi, enum lws_callback_reasons reason, void *in, size_t len);
|
||||
|
@ -75,7 +78,6 @@ protected:
|
|||
static
|
||||
void connectStatic(struct lws_sorted_usec_list *sul);
|
||||
|
||||
int receive(void *in, size_t len);
|
||||
int writable();
|
||||
|
||||
public:
|
||||
|
|
|
@ -114,9 +114,22 @@ int SignalingClient::protocolCallback(struct lws *wsi, enum lws_callback_reasons
|
|||
goto do_retry;
|
||||
|
||||
case LWS_CALLBACK_CLIENT_RECEIVE:
|
||||
ret = receive(in, len);
|
||||
if (ret)
|
||||
goto do_retry;
|
||||
if (lws_is_first_fragment(wsi))
|
||||
buffer.clear();
|
||||
|
||||
buffer.append((char *) in, len);
|
||||
|
||||
if (lws_is_final_fragment(wsi)) {
|
||||
auto *json = buffer.decode();
|
||||
if (json == nullptr) {
|
||||
logger->error("Failed to decode JSON");
|
||||
goto do_retry;
|
||||
}
|
||||
|
||||
cbMessage(SignalingMessage::fromJSON(json));
|
||||
|
||||
json_decref(json);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
@ -156,9 +169,9 @@ do_retry:
|
|||
* retrying at the last backoff delay plus the random jitter amount.
|
||||
*/
|
||||
if (lws_retry_sul_schedule_retry_wsi(wsi, &sul_helper.sul, connectStatic, &retry_count))
|
||||
logger->error("Signaling connection attempts exhaused");
|
||||
logger->error("Signaling connection attempts exhausted");
|
||||
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int SignalingClient::writable()
|
||||
|
@ -197,24 +210,6 @@ int SignalingClient::writable()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int SignalingClient::receive(void *in, size_t len)
|
||||
{
|
||||
json_error_t err;
|
||||
json_t *json = json_loadb((char *) in, len, 0, &err);
|
||||
if (!json) {
|
||||
logger->error("Failed to decode json: {} at ({}:{})", err.text, err.line, err.column);
|
||||
return -1;
|
||||
}
|
||||
|
||||
logger->debug("Signaling message received: {:.{}}", (char *)in, len);
|
||||
|
||||
cbMessage(SignalingMessage::fromJSON(json));
|
||||
|
||||
json_decref(json);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SignalingClient::sendMessage(SignalingMessage msg)
|
||||
{
|
||||
outgoingMessages.push(msg);
|
||||
|
|
Loading…
Add table
Reference in a new issue