mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-20 12:36:17 +02:00
json notifications
This commit is contained in:
parent
f546738d75
commit
3a0b856afe
3 changed files with 36 additions and 9 deletions
|
@ -117,6 +117,21 @@ bool JsonRequest::isParam(size_t idx, const std::string& param)
|
|||
}
|
||||
|
||||
|
||||
Json JsonNotification::getJson(const std::string& method, Json data)
|
||||
{
|
||||
Json notification = {
|
||||
{"jsonrpc", "2.0"},
|
||||
{"method", method},
|
||||
{"params", {
|
||||
{"data", data}
|
||||
}}
|
||||
};
|
||||
|
||||
return notification;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
if ((method == "get") || (method == "set"))
|
||||
|
|
|
@ -74,6 +74,14 @@ protected:
|
|||
|
||||
|
||||
|
||||
class JsonNotification
|
||||
{
|
||||
public:
|
||||
static Json getJson(const std::string& method, Json data);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
class JsonRequestException : public SnapException
|
||||
{
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "jsonrpc.h"
|
||||
#include "streamServer.h"
|
||||
#include "message/time.h"
|
||||
#include "message/ack.h"
|
||||
|
@ -23,7 +24,7 @@
|
|||
#include "message/command.h"
|
||||
#include "message/hello.h"
|
||||
#include "common/log.h"
|
||||
#include "json.hpp"
|
||||
#include "config.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
@ -134,14 +135,17 @@ void StreamServer::onMessageReceived(ServerSession* connection, const msg::BaseM
|
|||
helloMsg.deserialize(baseMessage, buffer);
|
||||
connection->macAddress = helloMsg.getMacAddress();
|
||||
logO << "Hello from " << connection->macAddress << ", host: " << helloMsg.getHostName() << ", v" << helloMsg.getVersion() << "\n";
|
||||
json j = {
|
||||
{"event", "newConnection"},
|
||||
{"client", {
|
||||
{"ip", connection->getIP()},
|
||||
{"mac", connection->macAddress}
|
||||
}}
|
||||
};
|
||||
controlServer->send(j.dump());
|
||||
|
||||
ClientInfoPtr client = Config::instance().getClientInfo(connection->macAddress);
|
||||
client->ipAddress = connection->getIP();
|
||||
client->hostName = helloMsg.getHostName();
|
||||
client->version = helloMsg.getVersion();
|
||||
client->connected = true;
|
||||
gettimeofday(&client->lastSeen, NULL);
|
||||
|
||||
json notification = JsonNotification::getJson("Client.OnConnect", client->toJson());
|
||||
logO << std::setw(4) << notification << std::endl;
|
||||
controlServer->send(notification.dump(4));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue