diff --git a/src/CallManager.cpp b/src/CallManager.cpp index b5c59e08..37b150b4 100644 --- a/src/CallManager.cpp +++ b/src/CallManager.cpp @@ -15,6 +15,7 @@ #include "dialogs/AcceptCall.h" Q_DECLARE_METATYPE(std::vector) +Q_DECLARE_METATYPE(mtx::events::msg::CallCandidates::Candidate) Q_DECLARE_METATYPE(mtx::responses::TurnServer) using namespace mtx::events; @@ -30,11 +31,12 @@ CallManager::CallManager(QSharedPointer userSettings) settings_(userSettings) { qRegisterMetaType>(); + qRegisterMetaType(); qRegisterMetaType(); connect(&session_, &WebRTCSession::offerCreated, this, [this](const std::string &sdp, - const std::vector& candidates) + const std::vector &candidates) { nhlog::ui()->debug("Offer created with callid_ and roomid_: {} {}", callid_, roomid_.toStdString()); emit newMessage(roomid_, CallInvite{callid_, sdp, 0, timeoutms_}); @@ -43,13 +45,20 @@ CallManager::CallManager(QSharedPointer userSettings) connect(&session_, &WebRTCSession::answerCreated, this, [this](const std::string &sdp, - const std::vector& candidates) + const std::vector &candidates) { nhlog::ui()->debug("Answer created with callid_ and roomid_: {} {}", callid_, roomid_.toStdString()); emit newMessage(roomid_, CallAnswer{callid_, sdp, 0}); emit newMessage(roomid_, CallCandidates{callid_, candidates, 0}); }); + connect(&session_, &WebRTCSession::newICECandidate, this, + [this](const CallCandidates::Candidate &candidate) + { + nhlog::ui()->debug("New ICE candidate created with callid_ and roomid_: {} {}", callid_, roomid_.toStdString()); + emit newMessage(roomid_, CallCandidates{callid_, {candidate}, 0}); + }); + connect(&turnServerTimer_, &QTimer::timeout, this, &CallManager::retrieveTurnServer); turnServerTimer_.start(2000); diff --git a/src/WebRTCSession.cpp b/src/WebRTCSession.cpp index 5baed72e..c3f5341a 100644 --- a/src/WebRTCSession.cpp +++ b/src/WebRTCSession.cpp @@ -358,6 +358,11 @@ setLocalDescription(GstPromise *promise, gpointer webrtc) void addLocalICECandidate(GstElement *webrtc G_GNUC_UNUSED, guint mlineIndex, gchar *candidate, gpointer G_GNUC_UNUSED) { + if (WebRTCSession::instance().state() == WebRTCSession::State::CONNECTED) { + emit WebRTCSession::instance().newICECandidate({"audio", (uint16_t)mlineIndex, candidate}); + return; + } + gcandidates.push_back({"audio", (uint16_t)mlineIndex, candidate}); // GStreamer v1.16: webrtcbin's notify::ice-gathering-state triggers GST_WEBRTC_ICE_GATHERING_STATE_COMPLETE too early diff --git a/src/WebRTCSession.h b/src/WebRTCSession.h index 42db204d..f9882089 100644 --- a/src/WebRTCSession.h +++ b/src/WebRTCSession.h @@ -46,6 +46,7 @@ public: signals: void offerCreated(const std::string &sdp, const std::vector&); void answerCreated(const std::string &sdp, const std::vector&); + void newICECandidate(const mtx::events::msg::CallCandidates::Candidate&); void stateChanged(WebRTCSession::State); // explicit qualifier necessary for Qt private slots: