Commit dda4649f authored by Guillaume Roguez's avatar Guillaume Roguez

daemon: move sendTextMessage API to Call class

Refs #51555

Change-Id: I9e433dfba59f269973bf40e0f9fad7697ed64803
parent 6491a44f
......@@ -289,6 +289,17 @@ class Call : public Recordable {
*/
virtual void carryingDTMFdigits(char code) = 0;
#if HAVE_INSTANT_MESSAGING
/**
* Send a message to a call identified by its callid
*
* @param The actual message to be transmitted
* @param The sender of this message (could be another participant of a conference)
*/
virtual void sendTextMessage(const std::string &message,
const std::string &from) = 0;
#endif
private:
bool validTransition(CallState newState);
......
......@@ -40,6 +40,10 @@
#include "manager.h"
#include "iaxvoiplink.h"
#if HAVE_INSTANT_MESSAGING
#include "im/instant_messaging.h"
#endif
static int
codecToASTFormat(int c)
{
......@@ -226,3 +230,12 @@ IAXCall::carryingDTMFdigits(char code)
std::lock_guard<std::mutex> lock(IAXVoIPLink::mutexIAX);
iax_send_dtmf(session, code);
}
#if HAVE_INSTANT_MESSAGING
void
IAXCall::sendTextMessage(const std::string& message, const std::string& /*from*/)
{
std::lock_guard<std::mutex> lock(IAXVoIPLink::mutexIAX);
sfl::InstantMessaging::send_iax_message(session, getCallId(), message.c_str());
}
#endif
......@@ -31,6 +31,10 @@
#ifndef IAXCALL_H
#define IAXCALL_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "call.h"
#include "noncopyable.h"
......@@ -98,6 +102,11 @@ class IAXCall : public Call {
void carryingDTMFdigits(char code);
#if HAVE_INSTANT_MESSAGING
void sendTextMessage(const std::string& message,
const std::string& from);
#endif
private:
NON_COPYABLE(IAXCall);
......
......@@ -35,7 +35,6 @@
#include "iaxcall.h"
#include "eventthread.h"
#include "im/instant_messaging.h"
#include "iaxaccount.h"
#include "logger.h"
#include "manager.h"
......@@ -313,24 +312,6 @@ IAXVoIPLink::newOutgoingCall(const std::string& id, const std::string& toUrl, co
return call;
}
#if HAVE_INSTANT_MESSAGING
void
IAXVoIPLink::sendTextMessage(const std::string& callID,
const std::string& message,
const std::string& /*from*/)
{
std::lock_guard<std::mutex> lock(iaxCallMapMutex_);
auto call = getIAXCall(callID);
if (!call)
return;
{
std::lock_guard<std::mutex> lock(mutexIAX);
sfl::InstantMessaging::send_iax_message(call->session, callID, message.c_str());
}
}
#endif
void
IAXVoIPLink::clearIaxCallMap()
{
......
......@@ -127,9 +127,6 @@ class IAXVoIPLink : public VoIPLink {
*/
virtual void cancel(const std::string& /*id*/) {}
#if HAVE_INSTANT_MESSAGING
virtual void sendTextMessage(const std::string& callID, const std::string& message, const std::string& from);
#endif
static void clearIaxCallMap();
static void addIaxCall(std::shared_ptr<IAXCall>& call);
// must be called while holding iaxCallMapMutex
......
......@@ -1467,18 +1467,14 @@ void ManagerImpl::incomingMessage(const std::string& callID,
if (item_p == callID)
continue;
std::string accountId(getAccountFromCall(item_p));
DEBUG("Send message to %s", item_p.c_str());
DEBUG("Send message to %s, (%s)", item_p.c_str(), accountId.c_str());
Account *account = getAccount(accountId);
if (!account) {
ERROR("Failed to get account while sending instant message");
if (auto call = getCallFromCallID(item_p)) {
call->sendTextMessage(message, from);
} else {
ERROR("Failed to get call while sending instant message");
return;
}
account->getVoIPLink()->sendTextMessage(callID, message, from);
}
// in case of a conference we must notify client using conference id
......@@ -1505,18 +1501,14 @@ bool ManagerImpl::sendTextMessage(const std::string& callID, const std::string&
ParticipantSet participants(conf->getParticipantList());
for (const auto &participant : participants) {
std::string accountId = getAccountFromCall(participant);
for (const auto &participant_id : participants) {
Account *account = getAccount(accountId);
if (!account) {
DEBUG("Failed to get account while sending instant message");
if (auto call = getCallFromCallID(participant_id)) {
call->sendTextMessage(message, from);
} else {
ERROR("Failed to get call while sending instant message");
return false;
}
account->getVoIPLink()->sendTextMessage(participant, message, from);
}
return true;
......@@ -1531,28 +1523,22 @@ bool ManagerImpl::sendTextMessage(const std::string& callID, const std::string&
ParticipantSet participants(conf->getParticipantList());
for (const auto &item_p : participants) {
for (const auto &participant_id : participants) {
const std::string accountId(getAccountFromCall(item_p));
Account *account = getAccount(accountId);
if (!account) {
DEBUG("Failed to get account while sending instant message");
if (auto call = getCallFromCallID(participant_id)) {
call->sendTextMessage(message, from);
} else {
ERROR("Failed to get call while sending instant message");
return false;
}
account->getVoIPLink()->sendTextMessage(item_p, message, from);
}
} else {
Account *account = getAccount(getAccountFromCall(callID));
if (!account) {
DEBUG("Failed to get account while sending instant message");
if (auto call = getCallFromCallID(callID)) {
call->sendTextMessage(message, from);
} else {
ERROR("Failed to get call while sending instant message");
return false;
}
account->getVoIPLink()->sendTextMessage(callID, message, from);
}
return true;
}
......
......@@ -40,6 +40,10 @@
#include "audio/audiortp/audio_rtp_factory.h" // for AudioRtpFactoryException
#if HAVE_INSTANT_MESSAGING
#include "im/instant_messaging.h"
#endif
#ifdef SFL_VIDEO
#include "client/videomanager.h"
......@@ -648,3 +652,18 @@ SIPCall::carryingDTMFdigits(char code)
dtmfSend(*this, code, account->getDtmfType());
}
#if HAVE_INSTANT_MESSAGING
void
SIPCall::sendTextMessage(const std::string &message, const std::string &from)
{
using namespace sfl::InstantMessaging;
/* Send IM message */
UriList list;
UriEntry entry;
entry[sfl::IM_XML_URI] = std::string("\"" + from + "\""); // add double quotes for xml formating
list.push_front(entry);
send_sip_message(inv, getCallId(), appendUriList(message, list));
}
#endif // HAVE_INSTANT_MESSAGING
......@@ -132,6 +132,11 @@ class SIPCall : public Call {
void carryingDTMFdigits(char code);
#if HAVE_INSTANT_MESSAGING
void sendTextMessage(const std::string& message,
const std::string& from);
#endif
private:
// override of Call::createHistoryEntry
......
......@@ -1025,25 +1025,6 @@ stopRtpIfCurrent(const std::string &id, SIPCall &call)
}
}
#if HAVE_INSTANT_MESSAGING
void SIPVoIPLink::sendTextMessage(const std::string &callID,
const std::string &message,
const std::string &from)
{
using namespace sfl::InstantMessaging;
auto call = getSipCall(callID);
if (!call)
return;
/* Send IM message */
UriList list;
UriEntry entry;
entry[sfl::IM_XML_URI] = std::string("\"" + from + "\""); // add double quotes for xml formating
list.push_front(entry);
send_sip_message(call->inv, callID, appendUriList(message, list));
}
#endif // HAVE_INSTANT_MESSAGING
void
SIPVoIPLink::clearSipCallMap()
{
......@@ -1051,7 +1032,6 @@ SIPVoIPLink::clearSipCallMap()
sipCallMap_.clear();
}
std::vector<std::string>
SIPVoIPLink::getCallIDs()
{
......
......@@ -187,18 +187,6 @@ class SIPVoIPLink : public VoIPLink {
*/
std::string getUseragentName(SIPAccount *) const;
/**
* Send a SIP message to a call identified by its callid
*
* @param The Id of the call to send the message to
* @param The actual message to be transmitted
* @param The sender of this message (could be another participant of a conference)
*/
#if HAVE_INSTANT_MESSAGING
void sendTextMessage(const std::string& callID,
const std::string& message,
const std::string& from);
#endif
void clearSipCallMap();
void addSipCall(std::shared_ptr<SIPCall>& call);
......
......@@ -93,19 +93,6 @@ class VoIPLink {
*/
virtual std::vector<std::shared_ptr<Call> > getCalls(const std::string &account_id) const = 0;
/**
* Send a message to a call identified by its callid
*
* @param The Id of the call to send the message to
* @param The actual message to be transmitted
* @param The sender of this message (could be another participant of a conference)
*/
#if HAVE_INSTANT_MESSAGING
virtual void sendTextMessage(const std::string &callID,
const std::string &message,
const std::string &from) = 0;
#endif
protected:
static void unloadAccount(std::pair<const std::string, Account*> &item);
bool handlingEvents_;
......
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