diff options
Diffstat (limited to 'src/server.cc')
| -rw-r--r-- | src/server.cc | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/server.cc b/src/server.cc index 9b556b0..ab3e12a 100644 --- a/src/server.cc +++ b/src/server.cc @@ -80,7 +80,7 @@ class HttpServerDelegate : public http::Server::Delegate { } if (path.starts_with("device/")) { - if (request.method() != "GET") { + if (request.method() != "POST" && request.method() != "GET") { return http::Response::status(http::StatusCode::kMethodNotAllowed); } @@ -90,9 +90,28 @@ class HttpServerDelegate : public http::Server::Delegate { if (adapter) { for (auto* device : adapter->devices()) { if (device->address() == address) { - json_writer_->clear(); - write_device(*device); - return http::Response::content(json_tmp_, *json_mimetype_); + if (request.method() == "GET") { + json_writer_->clear(); + write_device(*device); + return http::Response::content(json_tmp_, *json_mimetype_); + } + + auto* player = device->player(); + if (request.body() == "play") { + if (player) { + player->play(); + return status_ok(); + } + return status_error("Bad state"); + } + if (request.body() == "pause") { + if (player) { + player->pause(); + return status_ok(); + } + return status_error("Bad state"); + } + return status_error("Unknown action"); } } } |
