3#include "ServiceRabbitVNC.h"
4#include "RabbitCommonTools.h"
5#include "network/Socket.h"
9#include "ParameterServiceRabbitVNC.h"
11 #include "FrmParameterRabbitVNC.h"
13#include "Connection.h"
14#include "PluginService.h"
17#include "ICE/ChannelIce.h"
21#include <QLoggingCategory>
22Q_DECLARE_LOGGING_CATEGORY(RabbitVNC)
27 check = connect(&m_Lister, SIGNAL(newConnection()),
28 this, SLOT(slotNewConnection()));
34CServiceRabbitVNC::~CServiceRabbitVNC()
36 qDebug(RabbitVNC) <<
"CServiceRabbitVNC::~CServiceRabbitVNC";
40QWidget* CServiceRabbitVNC::GetParameterWidget(QWidget *parent)
55 if(p->GetEnableSocket())
57 if(!m_Lister.listen(QHostAddress::Any, p->getPort()))
59 qCritical(RabbitVNC) <<
"Lister fail: Port" << GetParameters()->getPort()
60 <<
"; %s" << m_Lister.errorString().toStdString().c_str();
63 qInfo(RabbitVNC) <<
"Lister at:", p->getPort();
81 check = connect(m_Signal.data(), SIGNAL(sigOffer(
const QString&,
86 this, SLOT(slotSignalOffer(
const QString&,
92 qInfo(RabbitVNC) <<
"Connect ICE signal";
109 m_Signal->disconnect(
this);
114 m_lstConnection.clear();
118void CServiceRabbitVNC::slotNewConnection()
120 if(!m_Lister.hasPendingConnections())
122 QTcpSocket* pSocket = m_Lister.nextPendingConnection();
124 qInfo(RabbitVNC) <<
"New connection:"
125 << pSocket->peerAddress() <<
":" << pSocket->peerPort();
127 QSharedPointer<CChannel> channel(
new CChannel(pSocket), &QObject::deleteLater);
128 if(!channel->isOpen())
129 if(!channel->open(QIODevice::ReadWrite))
131 qCritical(RabbitVNC) <<
"Don't open channel";
132 throw std::runtime_error(
"Don't open channel");
134 QSharedPointer<CConnection> c(
new CConnection(channel,
136 &QObject::deleteLater);
137 m_lstConnection.push_back(c);
138 bool check = connect(c.data(), SIGNAL(sigDisconnected()),
139 this, SLOT(slotDisconnected()));
141 check = connect(c.data(), SIGNAL(sigError(
int, QString)),
142 this, SLOT(slotError(
int, QString)));
145 emit channel->sigConnected();
146 }
catch (std::exception e) {
147 qCritical(RabbitVNC) <<
"New connection exception:" << e.what();
149 qCritical(RabbitVNC) <<
"New connection exception";
153void CServiceRabbitVNC::slotDisconnected()
156 pConnect->close(tr(
"Exit").toStdString().c_str());
157 foreach(
auto c, m_lstConnection)
159 m_lstConnection.removeOne(c);
162void CServiceRabbitVNC::slotError(
int nErr, QString szErr)
168void CServiceRabbitVNC::slotSignalConnected()
172 qInfo(RabbitVNC,
"Connected to signal server: %s:%d; user:%s",
173 p->getSignalServer().toStdString().c_str(),
175 p->getSignalUser().toStdString().c_str());
178void CServiceRabbitVNC::slotSignalDisConnected()
182 qInfo(RabbitVNC,
"Disconnect signal server: %s:%d; user:%s",
183 p->getSignalServer().toStdString().c_str(),
185 p->getSignalUser().toStdString().c_str());
188void CServiceRabbitVNC::slotSignalError(
int nErr,
const QString& szErr)
192 qCritical(RabbitVNC,
"signal: %s:%d; user:%s; error: %d: %s",
193 p->getSignalServer().toStdString().c_str(),
195 p->getSignalUser().toStdString().c_str(),
196 nErr, szErr.toStdString().c_str());
199void CServiceRabbitVNC::slotSignalOffer(
const QString& fromUser,
200 const QString& toUser,
201 const QString& channelId,
207 "New connection: from:%s; to:%s; channelId:%s",
208 fromUser.toStdString().c_str(),
209 toUser.toStdString().c_str(),
210 channelId.toStdString().c_str());
213 QSharedPointer<CChannelIce> channel(
new CChannelIce(m_Signal.data()),
214 &QObject::deleteLater);
215 if(!channel->isOpen())
217 rtc::IceServer stun(p->getStunServer().toStdString().c_str(),
219 rtc::IceServer turn(p->getTurnServer().toStdString().c_str(),
221 p->getTurnUser().toStdString().c_str(),
222 p->getTurnPassword().toStdString().c_str());
223 rtc::Configuration config;
224 config.iceServers.push_back(stun);
225 config.iceServers.push_back(turn);
226 channel->SetConfigure(config);
227 if(!channel->open(fromUser, toUser, channelId, type, sdp))
229 qCritical(RabbitVNC) <<
"Don't open channel";
230 throw std::runtime_error(
"Don't open channel");
233 QSharedPointer<CConnection> c(
new CConnection(channel,
235 &QObject::deleteLater);
236 m_lstConnection.push_back(c);
237 bool check = connect(c.data(), SIGNAL(sigDisconnected()),
238 this, SLOT(slotDisconnected()));
240 check = connect(c.data(), SIGNAL(sigError(
int, QString)),
241 this, SLOT(slotError(
int, QString)));
243 }
catch (std::exception e) {
244 qCritical(RabbitVNC) <<
"New connection exception" << e.what();
246 qCritical(RabbitVNC) <<
"New connection exception";
The ICE channel interface class.
The channel interface class.
static CICE * Instance()
Single instance.
ICE parameter helper class.
The service plugin interface.
virtual int OnInit() override
Init service.
virtual int OnClean() override
Clean service.