Commit 5cf97bd3 authored by Adrien Béraud's avatar Adrien Béraud

sipcall: multidevice text messages improvements

Tuleap: #938
Change-Id: I28d690aacbbf9a20fa50891a7a330c5c9feeb36b
parent cd959c9f
......@@ -165,8 +165,13 @@ Call::setState(CallState call_state, ConnectionState cnx_state, signed code)
auto subs = std::move(subcalls);
for (auto c : subs)
c->hangup(0);
pendingMessages_.clear();
pendingInMessages_.clear();
pendingOutMessages_.clear();
}
} else if (call_state == CallState::ACTIVE and not pendingOutMessages_.empty()) {
for (const auto& msg : pendingOutMessages_)
sendTextMessage(msg.first, msg.second);
pendingOutMessages_.clear();
}
for (auto& l : stateChangedListeners_)
......@@ -365,7 +370,7 @@ void
Call::onTextMessage(std::map<std::string, std::string>&& messages)
{
if (quiet)
pendingMessages_.emplace_back(std::move(messages), "");
pendingInMessages_.emplace_back(std::move(messages), "");
else
Manager::instance().incomingMessage(getCallId(), getPeerNumber(), messages);
}
......@@ -392,7 +397,7 @@ Call::addSubCall(const std::shared_ptr<Call>& call)
return;
call->quiet = true;
for (auto& pmsg : pendingMessages_)
for (auto& pmsg : pendingOutMessages_)
call->sendTextMessage(pmsg.first, pmsg.second);
std::weak_ptr<Call> wthis = shared_from_this();
......@@ -440,7 +445,7 @@ Call::addSubCall(const std::shared_ptr<Call>& call)
}
RING_WARN("[call %s] Remaining %d subcalls", this_.getCallId().c_str(), this_.subcalls.size());
if (this_.subcalls.empty())
this_.pendingMessages_.clear();
this_.pendingOutMessages_.clear();
} else {
RING_WARN("DeviceCall IGNORED call %s state changed %d %d", call->getCallId().c_str(), new_state, new_cstate);
}
......@@ -458,7 +463,7 @@ Call::merge(std::shared_ptr<Call> scall)
std::lock(callMutex_, call.callMutex_);
std::lock_guard<std::recursive_mutex> lk1 (callMutex_, std::adopt_lock);
std::lock_guard<std::recursive_mutex> lk2 (call.callMutex_, std::adopt_lock);
auto pendingMessages = std::move(call.pendingMessages_);
auto pendingInMessages = std::move(call.pendingInMessages_);
iceTransport_ = std::move(call.iceTransport_);
peerDisplayName_ = std::move(call.peerDisplayName_);
localAddr_ = call.localAddr_;
......@@ -466,9 +471,9 @@ Call::merge(std::shared_ptr<Call> scall)
localVideoPort_ = call.localVideoPort_;
setState(call.getState());
setState(call.getConnectionState());
scall->removeCall();
for (const auto& msg : pendingMessages)
for (const auto& msg : pendingInMessages)
Manager::instance().incomingMessage(getCallId(), getPeerNumber(), msg.first);
scall->removeCall();
}
......
......@@ -360,7 +360,8 @@ class Call : public Recordable, public std::enable_shared_from_this<Call> {
bool isVideoMuted_{false};
bool quiet {false};
std::set<std::shared_ptr<Call>> subcalls {};
std::list<std::pair<std::map<std::string, std::string>, std::string>> pendingMessages_ {};
std::list<std::pair<std::map<std::string, std::string>, std::string>> pendingInMessages_ {};
std::list<std::pair<std::map<std::string, std::string>, std::string>> pendingOutMessages_ {};
private:
......
......@@ -665,18 +665,29 @@ SIPCall::sendTextMessage(const std::map<std::string, std::string>& messages,
//TODO: for now we ignore the "from" (the previous implementation for sending this info was
// buggy and verbose), another way to send the original message sender will be implemented
// in the future
if (inv)
im::sendSipMessage(inv.get(), messages);
else {
if (not subcalls.empty()) {
pendingMessages_.emplace_back(messages, from);
for (auto& c : subcalls)
c->sendTextMessage(messages, from);
} else
throw VoipLinkException("[call:" + getCallId() + "] sendTextMessage: no invite session for this call");
if (not subcalls.empty()) {
pendingOutMessages_.emplace_back(messages, from);
for (auto& c : subcalls)
c->sendTextMessage(messages, from);
} else {
if (inv) {
im::sendSipMessage(inv.get(), messages);
} else {
pendingOutMessages_.emplace_back(messages, from);
RING_ERR("[call:%s] sendTextMessage: no invite session for this call", getCallId().c_str());
}
}
}
void
SIPCall::removeCall()
{
RING_WARN("[call:%s] removeCall()", getCallId().c_str());
Call::removeCall();
inv.reset();
setTransport({});
}
void
SIPCall::onFailure(signed cause)
{
......@@ -1107,7 +1118,6 @@ SIPCall::initIceTransport(bool master, unsigned channel_num)
void
SIPCall::merge(std::shared_ptr<SIPCall> scall)
{
Call::merge(scall);
RING_WARN("SIPCall::merge %s -> %s", scall->getCallId().c_str(), getCallId().c_str());
inv = std::move(scall->inv);
inv->mod_data[getSIPVoIPLink()->getModId()] = this;
......@@ -1117,6 +1127,7 @@ SIPCall::merge(std::shared_ptr<SIPCall> scall)
upnp_ = std::move(scall->upnp_);
std::copy_n(scall->contactBuffer_, PJSIP_MAX_URL_SIZE, contactBuffer_);
pj_strcpy(&contactHeader_, &scall->contactHeader_);
Call::merge(scall);
if (iceTransport_->isStarted())
waitForIceAndStartMedia();
}
......
......@@ -159,6 +159,8 @@ class SIPCall : public Call
void sendTextMessage(const std::map<std::string, std::string>& messages,
const std::string& from) override;
void removeCall() override;
SIPAccountBase& getSIPAccount() const;
void updateSDPFromSTUN();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment