diff --git a/libsrc/api/JsonAPI.cpp b/libsrc/api/JsonAPI.cpp index 3568a850..8b6d6159 100644 --- a/libsrc/api/JsonAPI.cpp +++ b/libsrc/api/JsonAPI.cpp @@ -98,6 +98,8 @@ void JsonAPI::initialize() { // init API, REQUIRED! API::init(); + // Initialise jsonCB with current instance + _jsonCB->setSubscriptionsTo(_hyperion); // setup auth interface connect(this, &API::onPendingTokenRequest, this, &JsonAPI::newPendingTokenRequest); @@ -129,6 +131,8 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut { const QString ident = "JsonRpc@" + _peerAddress; QJsonObject message; + //std::cout << "JsonAPI::handleMessage | [" << static_cast(_hyperion->getInstanceIndex()) << "] Received: ["<< messageString.toStdString() << "]" << std::endl; + // parse the message if (!JsonUtils::parse(ident, messageString, message, _log)) { diff --git a/libsrc/api/JsonCB.cpp b/libsrc/api/JsonCB.cpp index 5863d1cc..9dcb3950 100644 --- a/libsrc/api/JsonCB.cpp +++ b/libsrc/api/JsonCB.cpp @@ -73,7 +73,7 @@ bool JsonCB::subscribeFor(const QString& type, bool unsubscribe) if(type == "priorities-update") { if (unsubscribe) - disconnect(_prioMuxer,0 ,0 ,0); + disconnect(_prioMuxer, &PriorityMuxer::prioritiesChanged, this, &JsonCB::handlePriorityUpdate); else connect(_prioMuxer, &PriorityMuxer::prioritiesChanged, this, &JsonCB::handlePriorityUpdate, Qt::UniqueConnection); } @@ -156,6 +156,8 @@ void JsonCB::resetSubscriptions() void JsonCB::setSubscriptionsTo(Hyperion* hyperion) { + //std::cout << "JsonCB::setSubscriptions for instance [" << static_cast(hyperion->getInstanceIndex()) << "] " << std::endl; + // get current subs QStringList currSubs(getSubscribedCommands()); @@ -179,11 +181,13 @@ void JsonCB::doCallback(const QString& cmd, const QVariant& data) QJsonObject obj; obj["command"] = cmd; - if(static_cast(data.type()) == QMetaType::QJsonArray) + if(data.userType() == QMetaType::QJsonArray) obj["data"] = data.toJsonArray(); else obj["data"] = data.toJsonObject(); + //std::cout << "JsonCB::doCallback | [" << static_cast(_hyperion->getInstanceIndex()) << "] Send: [" << QJsonDocument(obj).toJson(QJsonDocument::Compact).toStdString() << "]" << std::endl; + emit newCallback(obj); } diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index e6457277..8af1346a 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -57,3 +57,8 @@ void JsonClientConnection::disconnected() { emit connectionClosed(); } + +QHostAddress JsonClientConnection::getClientAddress() +{ + return _socket->peerAddress(); +} diff --git a/libsrc/jsonserver/JsonClientConnection.h b/libsrc/jsonserver/JsonClientConnection.h index 81886884..1351e99a 100644 --- a/libsrc/jsonserver/JsonClientConnection.h +++ b/libsrc/jsonserver/JsonClientConnection.h @@ -4,6 +4,7 @@ #include #include #include +#include // util includes #include @@ -24,6 +25,7 @@ public: /// @param socket The Socket object for this connection /// JsonClientConnection(QTcpSocket * socket, bool localConnection); + QHostAddress getClientAddress(); signals: void connectionClosed(); diff --git a/libsrc/jsonserver/JsonServer.cpp b/libsrc/jsonserver/JsonServer.cpp index a9237da8..aeef23f5 100644 --- a/libsrc/jsonserver/JsonServer.cpp +++ b/libsrc/jsonserver/JsonServer.cpp @@ -102,7 +102,7 @@ void JsonServer::newConnection() { if(_netOrigin->accessAllowed(socket->peerAddress(), socket->localAddress())) { - Debug(_log, "New connection from: %s ",socket->localAddress().toString().toStdString().c_str()); + Debug(_log, "New connection from: %s",QSTRING_CSTR(socket->peerAddress().toString())); JsonClientConnection * connection = new JsonClientConnection(socket, _netOrigin->isLocalAddress(socket->peerAddress(), socket->localAddress())); _openConnections.insert(connection); @@ -118,7 +118,7 @@ void JsonServer::newConnection() void JsonServer::closedConnection() { JsonClientConnection* connection = qobject_cast(sender()); - Debug(_log, "Connection closed"); + Debug(_log, "Connection closed for %s", QSTRING_CSTR(connection->getClientAddress().toString())); _openConnections.remove(connection); // schedule to delete the connection object diff --git a/libsrc/webserver/WebSocketClient.cpp b/libsrc/webserver/WebSocketClient.cpp index c546ca97..ac8d77ad 100644 --- a/libsrc/webserver/WebSocketClient.cpp +++ b/libsrc/webserver/WebSocketClient.cpp @@ -212,7 +212,7 @@ void WebSocketClient::getWsFrameHeader(WebSocketHeader* header) /// See http://tools.ietf.org/html/rfc6455#section-5.2 for more information void WebSocketClient::sendClose(int status, QString reason) { - Debug(_log, "send close: %d %s", status, QSTRING_CSTR(reason)); + Debug(_log, "Send close to %s: %d %s", QSTRING_CSTR(_socket->peerAddress().toString()), status, QSTRING_CSTR(reason)); ErrorIf(!reason.isEmpty(), _log, QSTRING_CSTR(reason)); _receiveBuffer.clear(); QByteArray sendBuffer;