forked from KangLin/RabbitIm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCallObjectQXmppWebrtc.cpp
150 lines (134 loc) · 4.57 KB
/
CallObjectQXmppWebrtc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "WebrtcConductor.h"
#undef emit //google 库中定义了此关键字,所以需要undef
#include "CallObjectQXmppWebrtc.h"
#include "QXmppWebRtcIq.h"
#include "ManageCallWebrtcXmpp.h"
#include "QXmppCallWebrtcManager.h"
#include "qxmpp/QXmppUtils.h"
#include "Global/Global.h"
#include "MainWindow.h"
CCallObjectQXmppWebrtc::CCallObjectQXmppWebrtc(const QString &szJid, bool bVideo,
QXmppCallWebrtcManager *pManager,
QObject *parent)
: CCallObject(QXmppUtils::jidToBareJid(szJid), bVideo, parent),
m_Conductor(new rtc::RefCountedObject<CWebrtcConductor>(this))
{
m_szJid = szJid;
m_Manager = pManager;
bool check = connect(GET_MAINWINDOW, SIGNAL(sigRefresh()),
SLOT(slotUpdateOption()));
Q_ASSERT(check);
}
CCallObjectQXmppWebrtc::~CCallObjectQXmppWebrtc()
{
//LOG_MODEL_DEBUG("WEBRTC", "CCallObjectQXmppWebrtc::~CCallObjectQXmppWebrtc()");
GET_MAINWINDOW->disconnect(this);
}
int CCallObjectQXmppWebrtc::Call()
{
CCallObject::Call();
QXmppWebRtcIq iq;
iq.setTo(m_szJid);
iq.setType(QXmppIq::Set);
iq.SetAction(QXmppWebRtcIq::Call);
iq.SetVideo(IsVideo());
return m_Manager->sendPacket(iq);
}
int CCallObjectQXmppWebrtc::Accept()
{
int nRet = 0;
slotChanageState(CCallObject::ConnectingState);
nRet = m_Conductor->PeerConnect();
//发送接收请求
QXmppWebRtcIq iq;
iq.setTo(m_szJid);
iq.setType(QXmppIq::Set);
iq.SetAction(QXmppWebRtcIq::Accept);
return m_Manager->sendPacket(iq);
}
int CCallObjectQXmppWebrtc::ReciveAccept()
{
int nRet = 0;
slotChanageState(CCallObject::ConnectingState);
return nRet;
}
int CCallObjectQXmppWebrtc::Stop()
{
int nRet = 0;
//发送停止请求
QXmppWebRtcIq iq;
iq.setTo(m_szJid);
iq.setType(QXmppIq::Set);
iq.SetAction(QXmppWebRtcIq::Stop);
nRet = m_Manager->sendPacket(iq);
//@see CManageCall::slotRosterStatusChanged
//if(nRet)
// return nRet;
nRet = ReciveStop();
return nRet;
}
int CCallObjectQXmppWebrtc::ReciveStop()
{
int nRet = 0;
nRet = m_Conductor->PeerStop();
slotChanageState(CCallObject::FinishedState);
return nRet;
}
int CCallObjectQXmppWebrtc::SendSessionDescription(QString szSdp, QString szType, bool bSuccess)
{
LOG_MODEL_DEBUG("WEBRTC", "SendSessionDescription:%s", szSdp.toStdString().c_str());
QXmppWebRtcIq iq;
iq.setTo(m_szJid);
iq.setType(QXmppIq::Set);
iq.SetAction(QXmppWebRtcIq::DescriptionInfo);
iq.SetSessionDescription(szSdp, szType, bSuccess);
return m_Manager->sendPacket(iq);
}
int CCallObjectQXmppWebrtc::ReciveSeesionDescription(QXmppWebRtcIq &iq)
{
LOG_MODEL_DEBUG("WEBRTC", " CCallObjectQXmppWebrtc::ReciveSeesionDescription");
QString szSdp, szType;
bool bSuccess = false;
if(iq.GetSessionDescription(szSdp, szType, bSuccess))
{
LOG_MODEL_ERROR("WEBRTC", "iq.GetSessionDescription fail");
return -1;
}
//判断是否出错,如果出错,则需要做些清理
if(bSuccess)
return m_Conductor->AcceptConnect(szSdp.toStdString(), szType.toStdString());
else
return this->ReciveStop();
}
int CCallObjectQXmppWebrtc::SendTransportInfo(QString sdp_mid, int sdp_mline_index, QString sdp)
{
LOG_MODEL_INFO("WEBRTC", "SendTransportInfo:mid:%s;index:%d;sdp:%s",
sdp_mid.toStdString().c_str(), sdp_mline_index, sdp.toStdString().c_str());
QXmppWebRtcIq iq;
iq.setTo(m_szJid);
iq.setType(QXmppIq::Set);
iq.SetAction(QXmppWebRtcIq::TransportInfo);
iq.SetTransportInfo(sdp_mid, sdp_mline_index, sdp);
return m_Manager->sendPacket(iq);
}
int CCallObjectQXmppWebrtc::ReciveTransportInfo(QXmppWebRtcIq& iq)
{
QString sdp_mid;
int sdp_mline_index;
QString sdp;
iq.GetTransportInfo(sdp_mid, sdp_mline_index, sdp);
LOG_MODEL_INFO("WEBRTC", "ReciveTransportInfo:mid:%s;index:%d;sdp:%s",
sdp_mid.toStdString().c_str(), sdp_mline_index, sdp.toStdString().c_str());
return m_Conductor->ReciveIceCandidate(sdp_mid.toStdString(),
sdp_mline_index,
sdp.toStdString());
}
void CCallObjectQXmppWebrtc::slotUpdateOption()
{
if(CGlobal::Instance()->GetIsShowLocaleVideo())
{
m_Conductor->CloseLocaleRander(false);
} else {
m_Conductor->CloseLocaleRander(true);
}
}