mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-30 15:32:37 +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) {
|
if (name == request::pause_or_resume) {
|
||||||
context.playback->PauseOrResume();
|
context.playback->PauseOrResume();
|
||||||
|
this->RespondWithSuccess(connection, request);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (name == request::stop) {
|
else if (name == request::stop) {
|
||||||
context.playback->Stop();
|
context.playback->Stop();
|
||||||
|
this->RespondWithSuccess(connection, request);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (name == request::previous) {
|
else if (name == request::previous) {
|
||||||
context.playback->Previous();
|
if (context.playback->Previous()) {
|
||||||
|
this->RespondWithSuccess(connection, request);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->RespondWithFailure(connection, request);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (name == request::next) {
|
else if (name == request::next) {
|
||||||
context.playback->Next();
|
if (context.playback->Next()) {
|
||||||
|
this->RespondWithSuccess(connection, request);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->RespondWithFailure(connection, request);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (name == request::play_at_index) {
|
else if (name == request::play_at_index) {
|
||||||
if (options.find(key::index) != options.end()) {
|
if (options.find(key::index) != options.end()) {
|
||||||
context.playback->Play(options[key::index]);
|
context.playback->Play(options[key::index]);
|
||||||
|
this->RespondWithSuccess(connection, request);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->RespondWithFailure(connection, request);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (name == request::toggle_shuffle) {
|
else if (name == request::toggle_shuffle) {
|
||||||
context.playback->ToggleShuffle();
|
context.playback->ToggleShuffle();
|
||||||
|
this->RespondWithSuccess(connection, request);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (name == request::toggle_repeat) {
|
else if (name == request::toggle_repeat) {
|
||||||
context.playback->ToggleRepeatMode();
|
context.playback->ToggleRepeatMode();
|
||||||
|
this->RespondWithSuccess(connection, request);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (name == request::toggle_mute) {
|
else if (name == request::toggle_mute) {
|
||||||
context.playback->ToggleMute();
|
context.playback->ToggleMute();
|
||||||
|
this->RespondWithSuccess(connection, request);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (name == request::set_volume) {
|
else if (name == request::set_volume) {
|
||||||
@ -237,6 +256,10 @@ void WebSocketServer::HandleRequest(connection_hdl connection, json& request) {
|
|||||||
else if (name == request::seek_to) {
|
else if (name == request::seek_to) {
|
||||||
if (options.find(key::position) != options.end()) {
|
if (options.find(key::position) != options.end()) {
|
||||||
context.playback->SetPosition(options[key::position]);
|
context.playback->SetPosition(options[key::position]);
|
||||||
|
this->RespondWithSuccess(connection, request);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->RespondWithFailure(connection, request);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -244,6 +267,10 @@ void WebSocketServer::HandleRequest(connection_hdl connection, json& request) {
|
|||||||
double delta = options.value(key::delta, 0.0f);
|
double delta = options.value(key::delta, 0.0f);
|
||||||
if (delta != 0.0f) {
|
if (delta != 0.0f) {
|
||||||
context.playback->SetPosition(context.playback->GetPosition() + delta);
|
context.playback->SetPosition(context.playback->GetPosition() + delta);
|
||||||
|
this->RespondWithSuccess(connection, request);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->RespondWithFailure(connection, request);
|
||||||
}
|
}
|
||||||
return;
|
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)
|
void WebSocketServer::RespondWithSuccess(connection_hdl connection, const std::string& name, const std::string& id)
|
||||||
{
|
{
|
||||||
json error = {
|
json success = {
|
||||||
{ message::name, name },
|
{ message::name, name },
|
||||||
{ message::id, id },
|
{ message::id, id },
|
||||||
{ message::type, type::response },
|
{ message::type, type::response },
|
||||||
{ message::options,{ key::success, true } }
|
{ 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);
|
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 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);
|
||||||
void RespondWithOptions(connection_hdl connection, json& request, json&& options = json({}));
|
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 RespondWithSetVolume(connection_hdl connection, json& request);
|
||||||
void RespondWithPlaybackOverview(connection_hdl connection, json& reuest);
|
void RespondWithPlaybackOverview(connection_hdl connection, json& reuest);
|
||||||
bool RespondWithTracks(connection_hdl connection, json& request, ITrackList* tracks, int limit, int offset);
|
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 RespondWithPlayQueueTracks(connection_hdl connection, json& request);
|
||||||
void RespondWithQueryAlbums(connection_hdl connection, json& request);
|
void RespondWithQueryAlbums(connection_hdl connection, json& request);
|
||||||
void RespondWithPlayTracks(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 RespondWithQueryTracksByCategory(connection_hdl connection, json& request);
|
||||||
void RespondWithQueryCategory(connection_hdl connection, json& request);
|
void RespondWithQueryCategory(connection_hdl connection, json& request);
|
||||||
void RespondWithPlayAllTracks(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 RespondWithEnvironment(connection_hdl connection, json& request);
|
||||||
void BroadcastPlaybackOverview();
|
void BroadcastPlaybackOverview();
|
||||||
void BroadcastPlayQueueChanged();
|
void BroadcastPlayQueueChanged();
|
||||||
|
ITrackList* QueryTracksByCategory(json& request, int& limit, int& offset);
|
||||||
json ReadTrackMetadata(IRetainedTrack* track);
|
json ReadTrackMetadata(IRetainedTrack* track);
|
||||||
void BuildPlaybackOverview(json& options);
|
void BuildPlaybackOverview(json& options);
|
||||||
|
|
||||||
void OnOpen(connection_hdl connection);
|
void OnOpen(connection_hdl connection);
|
||||||
void OnClose(connection_hdl connection);
|
void OnClose(connection_hdl connection);
|
||||||
void OnMessage(server* s, connection_hdl hdl, message_ptr msg);
|
void OnMessage(server* s, connection_hdl hdl, message_ptr msg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user