diff --git a/src/GroovePlayer.cpp b/src/GroovePlayer.cpp index f72fe0aa92ef30c259eca0bfa1b85aae6c9692a3..56892cca1920cb29e7f5ff8f02fa88865b20eb16 100644 --- a/src/GroovePlayer.cpp +++ b/src/GroovePlayer.cpp @@ -22,6 +22,9 @@ #include "db/AudioTrack.h" #include "db/UserAction.h" #include <Wt/WLogger> +#include <Wt/WServer> +#include <Wt/WApplication> +#include "WebInterface.h" GroovePlayer::GroovePlayer(std::string dbFile) : sqliteConnection(dbFile) { @@ -37,3 +40,14 @@ GroovePlayer::GroovePlayer(std::string dbFile) : sqliteConnection(dbFile) Wt::log("info") << "Using Existing DB."; } } + + //TODO:use this code when sending to UI. +// Wt::WServer::instance()->postAll([]() { +// Wt::WApplication* app = Wt::WApplication::instance(); +// if(app != nullptr) +// { +// static_cast<WebInterface*>(app)->updateUIFromServer(); +// } +// } +// ); + diff --git a/src/GroovePlayer.h b/src/GroovePlayer.h index 3dc26eb169205c169350df0ca60c65a9c85981c6..702fd4c2d387ef70a2bf7eee28ba3ab51f2e9f1b 100644 --- a/src/GroovePlayer.h +++ b/src/GroovePlayer.h @@ -36,6 +36,7 @@ private: GroovePlayer(std::string dbFile); Wt::Dbo::backend::Sqlite3 sqliteConnection; Wt::Dbo::Session sqlSession; + }; #endif // GROOVEPLAYER_H diff --git a/src/WebInterface.cpp b/src/WebInterface.cpp index 3f8f09a9fd134bc3f2e8f0d0c63575acdf4ad8a2..497e5b862912b26569b27e6b189ecbe7e08ad32b 100644 --- a/src/WebInterface.cpp +++ b/src/WebInterface.cpp @@ -33,6 +33,7 @@ WebInterface::WebInterface(const Wt::WEnvironment& env) : Wt::WApplication(env) { priv_int = new internal; setTitle("Arbitrateor - Audio Jukebox"); + enableUpdates(true); priv_int->playerUI = new PlayerInterface(this); priv_int->playerUI->hide(); priv_int->loginUI = new LoginInterface(this); @@ -53,5 +54,29 @@ void WebInterface::loginCompleted() //Login completed, now bring up main inteface. priv_int->loginUI->animateHide(Wt::WAnimation(Wt::WAnimation::AnimationEffect::Fade)); priv_int->playerUI->animateShow(Wt::WAnimation(Wt::WAnimation::AnimationEffect::Fade, Wt::WAnimation::TimingFunction::EaseIn, 500)); - //TODO: set up player to dynamically update? + //TODO: request current player state. +} + +void WebInterface::playPauseActionFromServer(User* userPausing) +{ + priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"play"); + triggerUpdate(); +} + +void WebInterface::songChangedFromServer(AudioTrack* nextTrack) +{ + priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"change"); + triggerUpdate(); +} + +void WebInterface::skipVotedFromServer(User* userRequestingToSkipCurrentTrack) +{ + priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"skip"); + triggerUpdate(); +} + +void WebInterface::voteUpdateFromServer(User* userVoting, bool forSkip) +{ + priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"vote"); + triggerUpdate(); } diff --git a/src/WebInterface.h b/src/WebInterface.h index ca5c0b5f278b33855dfcf8df3f3fbb960323573d..752a26e668dd9baa942c610ec58feff4cd7d23ff 100644 --- a/src/WebInterface.h +++ b/src/WebInterface.h @@ -22,6 +22,8 @@ #include <Wt/WApplication> #include "GroovePlayer.h" +#include "db/AudioTrack.h" +#include "db/User.h" class WebInterface : public Wt::WApplication { @@ -29,6 +31,10 @@ public: WebInterface(const Wt::WEnvironment& env); ~WebInterface(); void loginCompleted(); + void playPauseActionFromServer(User* userPausing); + void songChangedFromServer(AudioTrack* nextTrack); + void skipVotedFromServer(User* userRequestingToSkipCurrentTrack); + void voteUpdateFromServer(User* userVoting, bool forSkip); private: struct internal; internal* priv_int = 0; diff --git a/src/db/UserAction.h b/src/db/UserAction.h index 93e5d0bd7565e32120628843580fb24fd7c997d4..e720e86bde09a51e6701dd10a86618a54bbbd09d 100644 --- a/src/db/UserAction.h +++ b/src/db/UserAction.h @@ -29,7 +29,7 @@ class UserAction { public: - enum UAction {Login = 0, Logout = 1, RequestTrack = 2, VoteTrack = 3, UploadTrack = 4, RequestSkip = 5, Pause = 6}; + enum UAction {Login = 0, Logout = 1, RequestTrack = 2, VoteTrack = 3, UploadTrack = 4, RequestSkip = 5, PlayPause = 6}; Wt::Dbo::ptr<User> user; UAction action; diff --git a/src/main.cpp b/src/main.cpp index 2f6bf9dd6556b80de59cf590b987586fb465f565..62d3171dc68297b11d9f2bb205bf00ba6dc8a5ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ int main ( int argc, char** argv ) server.addEntryPoint(Wt::Application, createApplication); if(server.start()) { + GroovePlayer::getInstance(); int sig = Wt::WServer::waitForShutdown(argv[0]); server.stop(); } diff --git a/src/ui/PlayerInterface.cpp b/src/ui/PlayerInterface.cpp index f6f7ff91d2f9a3f4baed657c4dc52f28a59f5aa8..a12c73fde561716852363859425c2738b35a84ec 100644 --- a/src/ui/PlayerInterface.cpp +++ b/src/ui/PlayerInterface.cpp @@ -23,5 +23,6 @@ PlayerInterface::PlayerInterface(WebInterface* app) { this->app = app; - addChild(new Wt::WText("You did it.")); + tempText = new Wt::WText("You did it."); + addChild(tempText); } diff --git a/src/ui/PlayerInterface.h b/src/ui/PlayerInterface.h index 84ed2d1774d53125f7b136bc0a8ade51fa69f85d..e8df3f47349a0c2c6957f1bc9610c6fd1cac6be2 100644 --- a/src/ui/PlayerInterface.h +++ b/src/ui/PlayerInterface.h @@ -22,12 +22,14 @@ #include <Wt/WContainerWidget> #include "../WebInterface.h" +#include <Wt/WText> class PlayerInterface : public Wt::WContainerWidget { public: PlayerInterface(WebInterface* app); WebInterface* app; + Wt::WText* tempText; }; #endif // PLAYERINTERFACE_H