Added base of code to allow sending backend updates to connected clients.
This commit is contained in:
@@ -22,6 +22,9 @@
|
|||||||
#include "db/AudioTrack.h"
|
#include "db/AudioTrack.h"
|
||||||
#include "db/UserAction.h"
|
#include "db/UserAction.h"
|
||||||
#include <Wt/WLogger>
|
#include <Wt/WLogger>
|
||||||
|
#include <Wt/WServer>
|
||||||
|
#include <Wt/WApplication>
|
||||||
|
#include "WebInterface.h"
|
||||||
|
|
||||||
GroovePlayer::GroovePlayer(std::string dbFile) : sqliteConnection(dbFile)
|
GroovePlayer::GroovePlayer(std::string dbFile) : sqliteConnection(dbFile)
|
||||||
{
|
{
|
||||||
@@ -37,3 +40,14 @@ GroovePlayer::GroovePlayer(std::string dbFile) : sqliteConnection(dbFile)
|
|||||||
Wt::log("info") << "Using Existing DB.";
|
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();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ private:
|
|||||||
GroovePlayer(std::string dbFile);
|
GroovePlayer(std::string dbFile);
|
||||||
Wt::Dbo::backend::Sqlite3 sqliteConnection;
|
Wt::Dbo::backend::Sqlite3 sqliteConnection;
|
||||||
Wt::Dbo::Session sqlSession;
|
Wt::Dbo::Session sqlSession;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GROOVEPLAYER_H
|
#endif // GROOVEPLAYER_H
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ WebInterface::WebInterface(const Wt::WEnvironment& env) : Wt::WApplication(env)
|
|||||||
{
|
{
|
||||||
priv_int = new internal;
|
priv_int = new internal;
|
||||||
setTitle("Arbitrateor - Audio Jukebox");
|
setTitle("Arbitrateor - Audio Jukebox");
|
||||||
|
enableUpdates(true);
|
||||||
priv_int->playerUI = new PlayerInterface(this);
|
priv_int->playerUI = new PlayerInterface(this);
|
||||||
priv_int->playerUI->hide();
|
priv_int->playerUI->hide();
|
||||||
priv_int->loginUI = new LoginInterface(this);
|
priv_int->loginUI = new LoginInterface(this);
|
||||||
@@ -53,5 +54,29 @@ void WebInterface::loginCompleted()
|
|||||||
//Login completed, now bring up main inteface.
|
//Login completed, now bring up main inteface.
|
||||||
priv_int->loginUI->animateHide(Wt::WAnimation(Wt::WAnimation::AnimationEffect::Fade));
|
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));
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include <Wt/WApplication>
|
#include <Wt/WApplication>
|
||||||
#include "GroovePlayer.h"
|
#include "GroovePlayer.h"
|
||||||
|
#include "db/AudioTrack.h"
|
||||||
|
#include "db/User.h"
|
||||||
|
|
||||||
class WebInterface : public Wt::WApplication
|
class WebInterface : public Wt::WApplication
|
||||||
{
|
{
|
||||||
@@ -29,6 +31,10 @@ public:
|
|||||||
WebInterface(const Wt::WEnvironment& env);
|
WebInterface(const Wt::WEnvironment& env);
|
||||||
~WebInterface();
|
~WebInterface();
|
||||||
void loginCompleted();
|
void loginCompleted();
|
||||||
|
void playPauseActionFromServer(User* userPausing);
|
||||||
|
void songChangedFromServer(AudioTrack* nextTrack);
|
||||||
|
void skipVotedFromServer(User* userRequestingToSkipCurrentTrack);
|
||||||
|
void voteUpdateFromServer(User* userVoting, bool forSkip);
|
||||||
private:
|
private:
|
||||||
struct internal;
|
struct internal;
|
||||||
internal* priv_int = 0;
|
internal* priv_int = 0;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
class UserAction
|
class UserAction
|
||||||
{
|
{
|
||||||
public:
|
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;
|
Wt::Dbo::ptr<User> user;
|
||||||
UAction action;
|
UAction action;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ int main ( int argc, char** argv )
|
|||||||
server.addEntryPoint(Wt::Application, createApplication);
|
server.addEntryPoint(Wt::Application, createApplication);
|
||||||
if(server.start())
|
if(server.start())
|
||||||
{
|
{
|
||||||
|
GroovePlayer::getInstance();
|
||||||
int sig = Wt::WServer::waitForShutdown(argv[0]);
|
int sig = Wt::WServer::waitForShutdown(argv[0]);
|
||||||
server.stop();
|
server.stop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,5 +23,6 @@
|
|||||||
PlayerInterface::PlayerInterface(WebInterface* app)
|
PlayerInterface::PlayerInterface(WebInterface* app)
|
||||||
{
|
{
|
||||||
this->app = app;
|
this->app = app;
|
||||||
addChild(new Wt::WText("You did it."));
|
tempText = new Wt::WText("You did it.");
|
||||||
|
addChild(tempText);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,12 +22,14 @@
|
|||||||
|
|
||||||
#include <Wt/WContainerWidget>
|
#include <Wt/WContainerWidget>
|
||||||
#include "../WebInterface.h"
|
#include "../WebInterface.h"
|
||||||
|
#include <Wt/WText>
|
||||||
|
|
||||||
class PlayerInterface : public Wt::WContainerWidget
|
class PlayerInterface : public Wt::WContainerWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PlayerInterface(WebInterface* app);
|
PlayerInterface(WebInterface* app);
|
||||||
WebInterface* app;
|
WebInterface* app;
|
||||||
|
Wt::WText* tempText;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYERINTERFACE_H
|
#endif // PLAYERINTERFACE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user