Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
IceSignalQxmpp.cpp
1
2
3#include "IceSignalQxmpp.h"
4#include "QXmppUtils.h"
5#include <QCoreApplication>
6
7int g_CIceSignalQXmppIq = qRegisterMetaType<CIceSignalQXmppIq>("CIceSignalQXmppIq");
8
9CIceSignalQxmpp::CIceSignalQxmpp(QObject *parent)
10 : CIceSignal(parent),
11 m_Manager(this)
12{
13 bool check = false;
14
15 //m_Client.logger()->setLoggingType(QXmppLogger::StdoutLogging);
16 m_Client.addExtension(&m_Manager);
17
18 check = connect(&m_Client, SIGNAL(connected()),
19 this, SIGNAL(sigConnected()));
20 Q_ASSERT(check);
21 check = connect(&m_Client, SIGNAL(disconnected()),
22 this, SIGNAL(sigDisconnected()));
23 Q_ASSERT(check);
24 check = connect(&m_Client, SIGNAL(error(QXmppClient::Error)),
25 this, SLOT(slotError(QXmppClient::Error)));
26 Q_ASSERT(check);
27
28 check = connect(this, SIGNAL(sigSendPackage(CIceSignalQXmppIq)),
29 this, SLOT(slotSendPackage(CIceSignalQXmppIq)));
30 Q_ASSERT(check);
31}
32
33int CIceSignalQxmpp::Open(const QString &szServer, quint16 nPort, const QString &user, const QString &password)
34{
35 QXmppConfiguration conf;
36
37 if(QXmppUtils::jidToDomain(user).isEmpty())
38 {
39 QString szMsg = "The user name is error. please use format: user@domain/resource";
40 qCritical(m_Log) << szMsg;
41 emit sigError(-100, szMsg);
42 return -1;
43 }
44 if(QXmppUtils::jidToResource(user).isEmpty())
45 {
46 qWarning(m_Log) << "The user name is error. please use format: user@domain/resource";
47 conf.setResource(qApp->applicationName()
48 #if defined(Q_OS_ANDROID)
49 + "_android"
50 #elif defined(Q_OS_LINUX)
51 + "_linux"
52 #elif defined(Q_OS_WIN)
53 + "_windows"
54 #elif defined(Q_OS_OSX)
55 + "_osx"
56 #elif defined(Q_OS_IOS)
57 + "_ios"
58 #endif
59 );
60 }
61
62 conf.setHost(szServer);
63 conf.setPort(nPort);
64 conf.setJid(user);
65 conf.setPassword(password);
66 /*
67 conf.setUser(QXmppUtils::jidToUser(user.c_str()));
68 conf.setDomain(QXmppUtils::jidToDomain(user.c_str()));
69 conf.setResource(QXmppUtils::jidToResource(user.c_str()));
70 //*/
71 m_Client.connectToServer(conf);
72 return 0;
73}
74
75int CIceSignalQxmpp::Close()
76{
77 m_Client.disconnectFromServer();
78 return 0;
79}
80
81bool CIceSignalQxmpp::IsConnected()
82{
83 return m_Client.isConnected();
84}
85
86bool CIceSignalQxmpp::proecssIq(CIceSignalQXmppIq iq)
87{
88 /*
89 qDebug(m_Log) << "from:" << iq.from()
90 << ";to:" << iq.to()
91 << ";type:" << iq.SignalType();//*/
92 if(iq.SignalType() == "offer")
93 {
94 /*
95 qDebug(m_Log) << "type:" << iq.SignalType()
96 << "SDP:" << iq.Description();//*/
97 emit sigOffer(iq.from(),
98 iq.to(),
99 iq.ChannelId(),
100 iq.SignalType(),
101 iq.Description());
102 } else if(iq.SignalType() == "answer") {
103 /*
104 qDebug(m_Log) << "type:" << iq.SignalType()
105 << "Description:" << iq.Description();//*/
106 emit sigDescription(iq.from(),
107 iq.to(),
108 iq.ChannelId(),
109 iq.SignalType(),
110 iq.Description());
111 } else if (iq.SignalType() == "candidate") {
112 /*
113 qDebug(m_Log) << "type:" << iq.SignalType()
114 << "Mid:" << iq.mid()
115 << "Candidate:" << iq.Candidate();//*/
116 emit sigCandidate(iq.from(),
117 iq.to(),
118 iq.ChannelId(),
119 iq.mid(),
120 iq.Candidate());
121 } else {
122 qCritical(m_Log) << "iq type error:" << iq.SignalType();
123 return false;
124 }
125 return true;
126}
127
128int CIceSignalQxmpp::SendDescription(const QString &toUser,
129 const QString &channelId,
130 const rtc::Description &description,
131 const QString &fromUser)
132{
134 iq.setType(QXmppIq::Set);
135 iq.setTo(toUser);
136 iq.setChannelId(channelId);
137 iq.setSignalType(description.typeString().c_str());
138 iq.setDescription(std::string(description).c_str());
139 emit sigSendPackage(iq);
140 return 0;
141}
142
143int CIceSignalQxmpp::SendCandidate(const QString &toUser,
144 const QString &channelId,
145 const rtc::Candidate &candidate,
146 const QString &fromUser)
147{
149 iq.setType(QXmppIq::Set);
150 iq.setTo(toUser);
151 iq.setChannelId(channelId);
152 iq.setSignalType("candidate");
153 iq.setMid(candidate.mid().c_str());
154 iq.setCandidate(std::string(candidate).c_str());
155 emit sigSendPackage(iq);
156 return 0;
157}
158
159void CIceSignalQxmpp::slotSendPackage(CIceSignalQXmppIq iq)
160{
161 m_Manager.sendPacket(iq);
162}
163
164void CIceSignalQxmpp::slotError(QXmppClient::Error e)
165{
166 QString szError;
167 switch (e) {
168 case QXmppClient::Error::SocketError:
169 szError = tr("Socket error");
170 break;
171 case QXmppClient::Error::KeepAliveError:
172 szError = tr("Keep alive error");
173 break;
174 case QXmppClient::Error::XmppStreamError:
175 szError = tr("xmpp stream error");
176 break;
177 default:
178 break;
179 }
180 qCritical(m_Log) << "Error:" << szError;
181 emit sigError(e, szError);
182}
The ICE signal interface class.
Definition IceSignal.h:26
void sigOffer(const QString &fromUser, const QString &toUser, const QString &channelId, const QString &type, const QString &sdp)
sigOffer
void sigDescription(const QString &fromUser, const QString &toUser, const QString &channelId, const QString &type, const QString &sdp)
sigDescription
void sigCandidate(const QString &fromUser, const QString &toUser, const QString &channelId, const QString &mid, const QString &sdp)
sigCandiate