mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-29 21:32:41 +00:00
Fixed a bunch of missing (currently unused) responses discovered while
working on documentation.
This commit is contained in:
parent
2c6dcb907f
commit
32f3b965e8
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user