Updated call struct definitions

This commit is contained in:
r0hit05 2022-06-27 22:08:02 +05:30
parent 6663e5683d
commit a7bfaa4ef6
3 changed files with 24 additions and 11 deletions

View File

@ -77,7 +77,7 @@ struct CallType
{
if constexpr (std::is_same_v<mtx::events::RoomEvent<mtx::events::voip::CallInvite>, T>) {
const char video[] = "m=video";
const std::string &sdp = e.content.sdp;
const std::string &sdp = e.content.offer.sdp;
return std::search(sdp.cbegin(),
sdp.cend(),
std::cbegin(video),

View File

@ -44,6 +44,7 @@ using namespace mtx::events;
using namespace mtx::events::voip;
using webrtc::CallType;
typedef RTCSessionDescriptionInit SDO;
namespace {
std::vector<std::string>
@ -65,8 +66,8 @@ CallManager::CallManager(QObject *parent)
this,
[this](const std::string &sdp, const std::vector<CallCandidates::Candidate> &candidates) {
nhlog::ui()->debug("WebRTC: call id: {} - sending offer", callid_);
emit newMessage(roomid_, CallInvite{callid_, sdp, "0", timeoutms_});
emit newMessage(roomid_, CallCandidates{callid_, candidates, "0"});
emit newMessage(roomid_, CallInvite{callid_, partyid_, SDO{sdp, SDO::Type::Offer}, "0", timeoutms_, invitee_});
emit newMessage(roomid_, CallCandidates{callid_, partyid_, candidates, "0"});
std::string callid(callid_);
QTimer::singleShot(timeoutms_, this, [this, callid]() {
if (session_.state() == webrtc::State::OFFERSENT && callid == callid_) {
@ -83,8 +84,8 @@ CallManager::CallManager(QObject *parent)
this,
[this](const std::string &sdp, const std::vector<CallCandidates::Candidate> &candidates) {
nhlog::ui()->debug("WebRTC: call id: {} - sending answer", callid_);
emit newMessage(roomid_, CallAnswer{callid_, sdp, "0"});
emit newMessage(roomid_, CallCandidates{callid_, candidates, "0"});
emit newMessage(roomid_, CallAnswer{callid_, partyid_, "0", SDO{sdp, SDO::Type::Answer}});
emit newMessage(roomid_, CallCandidates{callid_, partyid_, candidates, "0"});
});
connect(&session_,
@ -92,7 +93,7 @@ CallManager::CallManager(QObject *parent)
this,
[this](const CallCandidates::Candidate &candidate) {
nhlog::ui()->debug("WebRTC: call id: {} - sending ice candidate", callid_);
emit newMessage(roomid_, CallCandidates{callid_, {candidate}, "0"});
emit newMessage(roomid_, CallCandidates{callid_, partyid_, {candidate}, "0"});
});
connect(&turnServerTimer_, &QTimer::timeout, this, &CallManager::retrieveTurnServer);
@ -223,6 +224,16 @@ callHangUpReasonString(CallHangUp::Reason reason)
return "ICE failed";
case CallHangUp::Reason::InviteTimeOut:
return "Invite time out";
case CallHangUp::Reason::ICETimeOut:
return "ICE time out";
case CallHangUp::Reason::UserHangUp:
return "User hung up";
case CallHangUp::Reason::UserMediaFailed:
return "User media failed";
case CallHangUp::Reason::UserBusy:
return "User busy";
case CallHangUp::Reason::UnknownError:
return "Unknown error";
default:
return "User";
}
@ -235,7 +246,7 @@ CallManager::hangUp(CallHangUp::Reason reason)
if (!callid_.empty()) {
nhlog::ui()->debug(
"WebRTC: call id: {} - hanging up ({})", callid_, callHangUpReasonString(reason));
emit newMessage(roomid_, CallHangUp{callid_, "0", reason});
emit newMessage(roomid_, CallHangUp{callid_, partyid_, "0", reason});
endCall();
}
}
@ -267,7 +278,7 @@ void
CallManager::handleEvent(const RoomEvent<CallInvite> &callInviteEvent)
{
const char video[] = "m=video";
const std::string &sdp = callInviteEvent.content.sdp;
const std::string &sdp = callInviteEvent.content.offer.sdp;
bool isVideo = std::search(sdp.cbegin(),
sdp.cend(),
std::cbegin(video),
@ -288,7 +299,7 @@ CallManager::handleEvent(const RoomEvent<CallInvite> &callInviteEvent)
if (isOnCall() || roomInfo.member_count != 2) {
emit newMessage(
QString::fromStdString(callInviteEvent.room_id),
CallHangUp{callInviteEvent.content.call_id, "0", CallHangUp::Reason::InviteTimeOut});
CallHangUp{callInviteEvent.content.call_id, partyid_, "0", CallHangUp::Reason::InviteTimeOut});
return;
}
@ -311,7 +322,7 @@ CallManager::handleEvent(const RoomEvent<CallInvite> &callInviteEvent)
haveCallInvite_ = true;
callType_ = isVideo ? CallType::VIDEO : CallType::VOICE;
inviteSDP_ = callInviteEvent.content.sdp;
inviteSDP_ = callInviteEvent.content.offer.sdp;
emit newInviteState();
}
@ -385,7 +396,7 @@ CallManager::handleEvent(const RoomEvent<CallAnswer> &callAnswerEvent)
if (isOnCall() && callid_ == callAnswerEvent.content.call_id) {
stopRingtone();
if (!session_.acceptAnswer(callAnswerEvent.content.sdp)) {
if (!session_.acceptAnswer(callAnswerEvent.content.answer.sdp)) {
emit ChatPage::instance()->showNotification(QStringLiteral("Problem setting up call."));
hangUp();
}

View File

@ -92,6 +92,8 @@ private:
QString callPartyDisplayName_;
QString callPartyAvatarUrl_;
std::string callid_;
std::string partyid_ = "";
std::string invitee_ = "";
const uint32_t timeoutms_ = 120000;
webrtc::CallType callType_ = webrtc::CallType::VOICE;
bool haveCallInvite_ = false;