1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

node-webrtc: Fix logging

- Move send log before lws_write because it clobbers the buffer.
- Add raw receive log.
- Check json_dumpb return value.

Signed-off-by: Philipp Jungkamp <Philipp.Jungkamp@opal-rt.com>
This commit is contained in:
Philipp Jungkamp 2023-06-21 13:52:05 +02:00
parent c687396a28
commit 498b8aebdf
2 changed files with 9 additions and 5 deletions

View file

@ -153,7 +153,7 @@ int WebRTCNode::prepare()
if (ret < 0) // TODO log
return;
this->logger->debug("onMessage(rtc::binary) callback finished pushing {} samples", ret);
this->logger->trace("onMessage(rtc::binary) callback finished pushing {} samples", ret);
});
return 0;

View file

@ -120,6 +120,8 @@ 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());
auto *json = buffer.decode();
if (json == nullptr) {
logger->error("Failed to decode JSON");
@ -194,15 +196,17 @@ int SignalingClient::writable()
return 0;
}
char buf[LWS_PRE + 1024];
auto len = json_dumpb(jsonMsg, buf + LWS_PRE, 1024, JSON_INDENT(2));
char buf[LWS_PRE + 4096];
auto len = json_dumpb(jsonMsg, buf + LWS_PRE, 4096, JSON_INDENT(2));
if (len > sizeof(buf) - LWS_PRE)
return -1;
logger->trace("Sending signaling message: {:.{}}", buf + LWS_PRE, len);
auto ret = lws_write(wsi, (unsigned char *) buf + LWS_PRE, len, LWS_WRITE_TEXT);
if (ret < 0)
return ret;
logger->debug("Signaling message sent: {:.{}}", buf + LWS_PRE, len);
// Reschedule callback if there are more messages to be send
if (!outgoingMessages.empty())
lws_callback_on_writable(wsi);