Sound Info sent

This commit is contained in:
Poldi 2024-03-08 14:18:29 +11:00
parent 711316c5db
commit 809027f26d
5 changed files with 74 additions and 36 deletions

View File

@ -7,27 +7,32 @@ package nw.remote;
enum MsgType {
MSG_TYPE_UNSPECIFIED = 0;
// Client messages
MSG_TYPE_CONNECT = 1;
MSG_TYPE_DISCONNECT = 2;
MSG_TYPE_REQUEST_SONG_INFO = 3;
MSG_TYPE_PLAY = 4;
MSG_TYPE_NEXT = 5;
MSG_TYPE_PREVIOUS = 6;
MSG_TYPE_PAUSE = 7;
MSG_TYPE_STOP = 8;
// Client message
MSG_TYPE_REQUEST_SONG_INFO = 1;
MSG_TYPE_PLAY = 2;
MSG_TYPE_NEXT = 3;
MSG_TYPE_PREVIOUS = 4;
MSG_TYPE_PAUSE = 5;
MSG_TYPE_STOP = 6;
// Server messages
MSG_TYPE_CONNECT_OK = 9;
MSG_TYPE_REPLY_SONG_INFO = 7;
MSG_TYPE_ENGINE_STATE_CHANGE = 8;
// Bidirectional messages
MSG_TYPE_DISCONNECT = 9;
}
enum PlayerState{
PLAYER_STATUS_UNSPECIFIED = 0;
PLAYER_STATUS_PLAYING = 1;
}
message RequestConnect {
bool send_current_song = 1;
enum EngineState {
ENGINE_STATE_EMPTY = 0;
ENGINE_STATE_IDELE = 1;
ENGINE_STATE_PLAYING = 2;
ENGINE_STATE_PAUSED = 3;
}
enum ReasonDisconnect {
@ -52,7 +57,7 @@ message SongMetadata{
string songlength = 10;
}
message RequestSongMetadata {
SongMetadata song_metadata = 1;
bool send = 1;
}
message ResponseSongMetadata {
@ -79,17 +84,20 @@ message RequestPause {
message RequestStop {
bool stop = 1;
}
message EngineStateChange {
EngineState state = 1;
}
message Message {
uint32 version = 1;
MsgType type = 2;
RequestSongMetadata request_song_metadata = 3;
ResponseSongMetadata response_song_metadata = 4;
RequestNextTrack request_next_track = 5;
RequestPreviousTrack request_previous_track = 6;
RequestPlay request_play = 7;
RequestPause request_pause = 8;
RequestStop request_stop = 9;
RequestConnect request_connect = 10;
RequestDisconnect request_disconnect = 11;
MsgType type = 1;
RequestSongMetadata request_song_metadata = 2;
ResponseSongMetadata response_song_metadata = 3;
RequestNextTrack request_next_track = 4;
RequestPreviousTrack request_previous_track = 5;
RequestPlay request_play = 6;
RequestPause request_pause = 7;
RequestStop request_stop = 8;
EngineStateChange engine_state_change = 9;
RequestDisconnect request_disconnect = 10;
}

View File

@ -3,23 +3,23 @@
Client::Client(Application *app, QObject *parent)
: QObject{parent},
app_(app),
msgReceived_(new IncomingMsg(app)),
newMsg_(new OutgoingMsg(app))
incomingMsg_(new IncomingMsg(app)),
outgoingMsg_(new OutgoingMsg(app))
{
}
Client::~Client()
{
msgReceived_->deleteLater();
newMsg_->deleteLater();
incomingMsg_->deleteLater();
outgoingMsg_->deleteLater();
}
void Client::Init(QTcpSocket *socket)
{
socket_ = socket;
QObject::connect(msgReceived_,&IncomingMsg::InMsgParsed,this, &Client::Respond);
QObject::connect(incomingMsg_,&IncomingMsg::InMsgParsed,this, &Client::Respond);
msgReceived_->Init(socket_);
incomingMsg_->Init(socket_);
}
QTcpSocket* Client::GetSocket()
@ -29,6 +29,6 @@ QTcpSocket* Client::GetSocket()
void Client::Respond()
{
newMsg_->ProcessMsg(socket_, msgReceived_->GetMsgType());
outgoingMsg_->ProcessMsg(socket_, incomingMsg_->GetMsgType());
}

View File

@ -29,8 +29,8 @@ signals:
private:
Application *app_;
QTcpSocket *socket_;
IncomingMsg *msgReceived_;
OutgoingMsg *newMsg_;
IncomingMsg *incomingMsg_;
OutgoingMsg *outgoingMsg_;
};
#endif // CLIENT_H

View File

@ -11,6 +11,9 @@ OutgoingMsg::OutgoingMsg(Application *app, QObject *parent)
responeSong_(new nw::remote::ResponseSongMetadata),
player_(app_->player())
{
//QObject::connect(&*app_->player(), &Player::TrackSkipped, this, &MainWindow::TrackSkipped);
//QObject::connect(&*app_->player(), &Player::EngineChanged, this, &OutgoingMsg::EngineChanged);
QObject::connect(&*app_->player()->engine(), &EngineBase::StateChanged, this, &OutgoingMsg::EngineChanged);
}
OutgoingMsg::~OutgoingMsg()
@ -24,7 +27,7 @@ void OutgoingMsg::ProcessMsg(QTcpSocket * socket, qint32 msgType)
msg_->Clear();
switch (msgType_) {
case nw::remote::MSG_TYPE_CONNECT:
case nw::remote::MSG_TYPE_REQUEST_SONG_INFO:
SendCurrentTrackInfo();
break;
default:
@ -56,8 +59,10 @@ void OutgoingMsg::SendCurrentTrackInfo()
song_->set_playcount(currentSong.playcount());
song_->mutable_songlength()->assign(currentSong.PrettyLength().toStdString());
msg_->set_type(nw::remote::MSG_TYPE_PLAY);
msg_->set_type(nw::remote::MSG_TYPE_REPLY_SONG_INFO);
msg_->mutable_response_song_metadata()->set_player_state(nw::remote::PLAYER_STATUS_PLAYING);
msg_->mutable_response_song_metadata()->set_allocated_song_metadata(song_);
qLog(Debug) << "Current Title with Artist " << currentSong.PrettyTitleWithArtist();
}
else {
@ -68,9 +73,33 @@ void OutgoingMsg::SendCurrentTrackInfo()
msg_->set_type(nw::remote::MSG_TYPE_UNSPECIFIED);
msg_->mutable_response_song_metadata()->set_player_state(nw::remote::PLAYER_STATUS_UNSPECIFIED);
}
SendMsg();
}
void OutgoingMsg::SendMsg()
{
std::string msgOut;
msg_->SerializeToString(&msgOut);
bytesOut_ = msg_->ByteSizeLong();
if(socket_->isWritable())
{
socket_->write(QByteArray::fromStdString(msgOut));
qInfo() << socket_->bytesToWrite() << " bytes written to socket " << socket_->socketDescriptor();
statusOk_ = true;
msg_->Clear();
}
else
{
statusOk_ = false;
}
}
void OutgoingMsg::EngineChanged()
{
qInfo("Engine has changed");
}

View File

@ -19,7 +19,7 @@ public:
void SendMsg();
private slots:
void EngineChanged();
signals:
@ -38,6 +38,7 @@ private:
nw::remote::ResponseSongMetadata *responeSong_;
EngineBase::State playerState_;
SharedPtr<Player> player_ ;
bool statusOk_;
};
#endif // OUTGOINGMSG_H