Fixed a bunch of missing (currently unused) responses discovered while

working on documentation.
This commit is contained in:
casey langen 2017-05-27 22:36:16 -07:00
parent 2c6dcb907f
commit 32f3b965e8
2 changed files with 49 additions and 7 deletions

View File

@ -198,36 +198,55 @@ void WebSocketServer::HandleRequest(connection_hdl connection, json& request) {
}
if (name == request::pause_or_resume) {
context.playback->PauseOrResume();
this->RespondWithSuccess(connection, request);
return;
}
else if (name == request::stop) {
context.playback->Stop();
this->RespondWithSuccess(connection, request);
return;
}
else if (name == request::previous) {
context.playback->Previous();
if (context.playback->Previous()) {
this->RespondWithSuccess(connection, request);
}
else {
this->RespondWithFailure(connection, request);
}
return;
}
else if (name == request::next) {
context.playback->Next();
if (context.playback->Next()) {
this->RespondWithSuccess(connection, request);
}
else {
this->RespondWithFailure(connection, request);
}
return;
}
else if (name == request::play_at_index) {
if (options.find(key::index) != options.end()) {
context.playback->Play(options[key::index]);
this->RespondWithSuccess(connection, request);
}
else {
this->RespondWithFailure(connection, request);
}
return;
}
else if (name == request::toggle_shuffle) {
context.playback->ToggleShuffle();
this->RespondWithSuccess(connection, request);
return;
}
else if (name == request::toggle_repeat) {
context.playback->ToggleRepeatMode();
this->RespondWithSuccess(connection, request);
return;
}
else if (name == request::toggle_mute) {
context.playback->ToggleMute();
this->RespondWithSuccess(connection, request);
return;
}
else if (name == request::set_volume) {
@ -237,6 +256,10 @@ void WebSocketServer::HandleRequest(connection_hdl connection, json& request) {
else if (name == request::seek_to) {
if (options.find(key::position) != options.end()) {
context.playback->SetPosition(options[key::position]);
this->RespondWithSuccess(connection, request);
}
else {
this->RespondWithFailure(connection, request);
}
return;
}
@ -244,6 +267,10 @@ void WebSocketServer::HandleRequest(connection_hdl connection, json& request) {
double delta = options.value(key::delta, 0.0f);
if (delta != 0.0f) {
context.playback->SetPosition(context.playback->GetPosition() + delta);
this->RespondWithSuccess(connection, request);
}
else {
this->RespondWithFailure(connection, request);
}
return;
}
@ -348,13 +375,24 @@ void WebSocketServer::RespondWithSuccess(connection_hdl connection, json& reques
void WebSocketServer::RespondWithSuccess(connection_hdl connection, const std::string& name, const std::string& id)
{
json error = {
json success = {
{ message::name, name },
{ message::id, id },
{ message::type, type::response },
{ message::options,{ key::success, true } }
};
wss.send(connection, success.dump().c_str(), websocketpp::frame::opcode::text);
}
void WebSocketServer::RespondWithFailure(connection_hdl connection, json& request) {
json error = {
{ message::name, request[message::name] },
{ message::id, request[message::id] },
{ message::type, type::response },
{ message::options,{ key::success, false } }
};
wss.send(connection, error.dump().c_str(), websocketpp::frame::opcode::text);
}

View File

@ -126,9 +126,6 @@ class WebSocketServer {
void Broadcast(const std::string& name, json& options);
void RespondWithOptions(connection_hdl connection, json& request, json& options);
void RespondWithOptions(connection_hdl connection, json& request, json&& options = json({}));
void RespondWithInvalidRequest(connection_hdl connection, const std::string& name, const std::string& id);
void RespondWithSuccess(connection_hdl connection, json& request);
void RespondWithSuccess(connection_hdl connection, const std::string& name, const std::string& id);
void RespondWithSetVolume(connection_hdl connection, json& request);
void RespondWithPlaybackOverview(connection_hdl connection, json& reuest);
bool RespondWithTracks(connection_hdl connection, json& request, ITrackList* tracks, int limit, int offset);
@ -137,7 +134,12 @@ class WebSocketServer {
void RespondWithPlayQueueTracks(connection_hdl connection, json& request);
void RespondWithQueryAlbums(connection_hdl connection, json& request);
void RespondWithPlayTracks(connection_hdl connection, json& request);
ITrackList* QueryTracksByCategory(json& request, int& limit, int& offset);
void RespondWithInvalidRequest(connection_hdl connection, const std::string& name, const std::string& id);
void RespondWithSuccess(connection_hdl connection, json& request);
void RespondWithFailure(connection_hdl connection, json& request);
void RespondWithSuccess(connection_hdl connection, const std::string& name, const std::string& id);
void RespondWithQueryTracksByCategory(connection_hdl connection, json& request);
void RespondWithQueryCategory(connection_hdl connection, json& request);
void RespondWithPlayAllTracks(connection_hdl connection, json& request);
@ -145,8 +147,10 @@ class WebSocketServer {
void RespondWithEnvironment(connection_hdl connection, json& request);
void BroadcastPlaybackOverview();
void BroadcastPlayQueueChanged();
ITrackList* QueryTracksByCategory(json& request, int& limit, int& offset);
json ReadTrackMetadata(IRetainedTrack* track);
void BuildPlaybackOverview(json& options);
void OnOpen(connection_hdl connection);
void OnClose(connection_hdl connection);
void OnMessage(server* s, connection_hdl hdl, message_ptr msg);