merge 506de22 from master

Dynamic stream creation and deletion via JSON-RPC API #443
This commit is contained in:
Pablo I. Pousada Rial 2019-01-22 09:46:20 +01:00 committed by badaix
parent 5680d331c5
commit b26d892950
4 changed files with 78 additions and 0 deletions

View file

@ -494,6 +494,41 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
// Setup response
result["id"] = streamId;
}
else if (request->method() == "Stream.AddStream")
{
/// Request: {"id":4,"jsonrpc":"2.0","method":"Stream.AddStream","params":{"streamUri":"uri"}}
///
/// Response: {"id":4,"jsonrpc":"2.0","result":{"stream_id":"Spotify"}}
/// Call onMetaChanged(const PcmStream* pcmStream) for updates and notifications
LOG(INFO) << "Stream.AddStream(" << request->params().get("streamUri") << ")"
<< "\n";
// Find stream
string streamUri_ = request->params().get("streamUri");
PcmStreamPtr stream = streamManager_->addStream(streamUri_);
if (stream == nullptr)
throw jsonrpcpp::InternalErrorException("Stream not created", request->id());
stream->start(); // We start the stream, otherwise it would be silent
// Setup response
result["id"] = stream->getId();
}
else if (request->method() == "Stream.RemoveStream")
{
/// Request: {"id":4,"jsonrpc":"2.0","method":"Stream.RemoveStream","params":{"id":"Spotify"}}
///
/// Response: {"id":4,"jsonrpc":"2.0","result":{"stream_id":"Spotify"}}
/// Call onMetaChanged(const PcmStream* pcmStream) for updates and notifications
LOG(INFO) << "Stream.RemoveStream(" << request->params().get("id") << ")"
<< "\n";
// Find stream
string streamId = request->params().get("id");
streamManager_->removeStream(streamId);
// Setup response
result["id"] = streamId;
}
else
throw jsonrpcpp::MethodNotFoundException(request->id());
}