Commit 234e867a authored by Kevin Whitaker's avatar Kevin Whitaker

Add code to publish/republish once network is reachable. Fixes #1.

parent 6afebb70
......@@ -76,8 +76,9 @@ signals:
void error(QTcpSocket::SocketError socketError);
};
SimpleCastTcpService::SimpleCastTcpService(MiniMediaPlayer *player,QObject *parent) : QTcpServer(parent),player(player)
SimpleCastTcpService::SimpleCastTcpService(MiniMediaPlayer *player,QObject *parent) : QTcpServer(parent),player(player),manager(new QNetworkAccessManager(this))
{
connect(manager,SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)),this,SLOT(networkAccessChanged(QNetworkAccessManager::NetworkAccessibility)));
}
bool SimpleCastTcpService::listen(const QHostAddress& address, quint16 port)
......@@ -87,10 +88,23 @@ bool SimpleCastTcpService::listen(const QHostAddress& address, quint16 port)
//Setup DNSSD
dnsService = new KDNSSD::PublicService(QString(),"_simplecast._tcp",this->serverPort(),"local");
dnsService->setParent(this);
dnsService->publishAsync();
//Start publishing now and if not, wait for networkAccessibleManager to let us know.
if(manager->networkAccessible() == QNetworkAccessManager::Accessible && !dnsService->isPublished())
{
dnsService->publishAsync();
}
return listening;
}
void SimpleCastTcpService::networkAccessChanged(QNetworkAccessManager::NetworkAccessibility accessible)
{
if(accessible == QNetworkAccessManager::Accessible)
{
dnsService->publishAsync();
}
}
void SimpleCastTcpService::close()
{
QTcpServer::close();
......
......@@ -21,6 +21,7 @@
#include <QTcpServer>
#include <KDNSSD/DNSSD/PublicService>
#include "minimediaplayer.h"
#include <QNetworkAccessManager>
/**
* Tcp Server that responds to simple client requests and can be found over DNSSD.
......@@ -37,9 +38,13 @@ public:
protected:
void incomingConnection(qintptr handle) override;
private slots:
void networkAccessChanged(QNetworkAccessManager::NetworkAccessibility accessible);
private:
MiniMediaPlayer *player;
KDNSSD::PublicService *dnsService;
QNetworkAccessManager *manager;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment