Commit 24e4b233 authored by Ghislain MARY's avatar Ghislain MARY

Handle joining an existing group chat room when receiving a REFER inviting us to join.

parent 6394230a
......@@ -715,11 +715,18 @@ static void on_notify_response(SalOp *op){
}
static void refer_received(SalOp *op, const SalAddress *refer_to){
/*if processing is ok*/
dynamic_cast<SalReferOp*>(op)->reply(SalReasonNone);
/*otherwise*/
//dynamic_cast<SalReferOp*>(op)->reply(SalReasonDeclined);
if (sal_address_has_param(refer_to, "text")) {
LinphonePrivate::Address addr(sal_address_as_string(refer_to));
if (addr.isValid()) {
LinphoneCore *lc = reinterpret_cast<LinphoneCore *>(op->get_sal()->get_user_pointer());
LinphoneChatRoom *cr = _linphone_core_join_client_group_chat_room(lc, addr);
if (cr) {
static_cast<SalReferOp *>(op)->reply(SalReasonNone);
return;
}
}
}
static_cast<SalReferOp *>(op)->reply(SalReasonDeclined);
}
Sal::Callbacks linphone_sal_callbacks={
......
......@@ -127,7 +127,17 @@ LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAd
}
LinphoneChatRoom * linphone_core_create_client_group_chat_room(LinphoneCore *lc, const char *subject) {
LinphoneChatRoom *cr = _linphone_client_group_chat_room_new(lc, subject);
const char *factoryUri = linphone_core_get_conference_factory_uri(lc);
if (!factoryUri)
return nullptr;
LinphoneChatRoom *cr = _linphone_client_group_chat_room_new(lc, factoryUri, subject);
lc->chatrooms = bctbx_list_append(lc->chatrooms, cr);
return cr;
}
LinphoneChatRoom *_linphone_core_join_client_group_chat_room (LinphoneCore *lc, const LinphonePrivate::Address &addr) {
LinphoneChatRoom *cr = _linphone_client_group_chat_room_new(lc, addr.asString().c_str(), nullptr);
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->join();
lc->chatrooms = bctbx_list_append(lc->chatrooms, cr);
return cr;
}
......
......@@ -31,6 +31,7 @@
#include "linphone/tunnel.h"
#include "linphone/core_utils.h"
#include "linphone/conference.h"
#include "address/address.h"
#include "c-wrapper/internal/c-sal.h"
#include "sal/call-op.h"
#include "sal/event-op.h"
......@@ -462,7 +463,8 @@ void _linphone_proxy_config_release_ops(LinphoneProxyConfig *obj);
/*chat*/
LinphoneChatRoom * linphone_chat_room_new(LinphoneCore *core, const LinphoneAddress *addr);
LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, const char *subject);
LinphoneChatRoom *_linphone_core_join_client_group_chat_room (LinphoneCore *core, const LinphonePrivate::Address &addr);
LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, const char *uri, const char *subject);
void linphone_chat_room_release(LinphoneChatRoom *cr);
void linphone_chat_room_set_call(LinphoneChatRoom *cr, LinphoneCall *call);
bctbx_list_t * linphone_chat_room_get_transient_messages(const LinphoneChatRoom *cr);
......
......@@ -300,13 +300,10 @@ LinphoneChatRoom *linphone_chat_room_new (LinphoneCore *core, const LinphoneAddr
return cr;
}
LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, const char *subject) {
const char *factoryUri = linphone_core_get_conference_factory_uri(core);
if (!factoryUri)
return nullptr;
LinphoneAddress *factoryAddr = linphone_address_new(factoryUri);
LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(core, factoryAddr);
linphone_address_unref(factoryAddr);
LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, const char *uri, const char *subject) {
LinphoneAddress *addr = linphone_address_new(uri);
LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(core, addr);
linphone_address_unref(addr);
string from;
if (proxy)
from = L_GET_CPP_PTR_FROM_C_OBJECT(linphone_proxy_config_get_identity_address(proxy))->asString();
......@@ -314,7 +311,7 @@ LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, cons
from = linphone_core_get_primary_contact(core);
LinphonePrivate::Address me(from);
LinphoneChatRoom *cr = L_INIT(ChatRoom);
L_SET_CPP_PTR_FROM_C_OBJECT(cr, LinphonePrivate::ObjectFactory::create<LinphonePrivate::ClientGroupChatRoom>(core, me, L_C_TO_STRING(subject)));
L_SET_CPP_PTR_FROM_C_OBJECT(cr, LinphonePrivate::ObjectFactory::create<LinphonePrivate::ClientGroupChatRoom>(core, me, L_C_TO_STRING(uri), L_C_TO_STRING(subject)));
L_GET_PRIVATE_FROM_C_OBJECT(cr)->setState(LinphonePrivate::ChatRoom::State::Instantiated);
return cr;
}
......
......@@ -69,7 +69,13 @@ const string &BasicChatRoom::getSubject () const {
return d->subject;
}
void BasicChatRoom::leave () {}
void BasicChatRoom::join () {
lError() << "join() is not allowed on a BasicChatRoom";
}
void BasicChatRoom::leave () {
lError() << "leave() is not allowed on a BasicChatRoom";
}
void BasicChatRoom::removeParticipant (const shared_ptr<const Participant> &participant) {
lError() << "removeParticipant() is not allowed on a BasicChatRoom";
......
......@@ -41,6 +41,7 @@ public:
int getNbParticipants () const override;
std::list<std::shared_ptr<Participant>> getParticipants () const override;
const std::string &getSubject () const override;
void join () override;
void leave () override;
void removeParticipant (const std::shared_ptr<const Participant> &participant) override;
void removeParticipants (const std::list<std::shared_ptr<Participant>> &participants) override;
......
......@@ -52,9 +52,9 @@ shared_ptr<CallSession> ClientGroupChatRoomPrivate::createSession () {
// =============================================================================
ClientGroupChatRoom::ClientGroupChatRoom (LinphoneCore *core, const Address &me, const string &subject)
ClientGroupChatRoom::ClientGroupChatRoom (LinphoneCore *core, const Address &me, const string &uri, const string &subject)
: ChatRoom(*new ClientGroupChatRoomPrivate(core)), RemoteConference(core, me, nullptr) {
focus = ObjectFactory::create<Participant>(Address(linphone_core_get_conference_factory_uri(core)));
focus = ObjectFactory::create<Participant>(Address(uri));
this->subject = subject;
}
......@@ -113,6 +113,16 @@ const string &ClientGroupChatRoom::getSubject () const {
return RemoteConference::getSubject();
}
void ClientGroupChatRoom::join () {
L_D();
shared_ptr<CallSession> session = focus->getPrivate()->getSession();
if (!session && (d->state == ChatRoom::State::Instantiated)) {
session = d->createSession();
session->startInvite(nullptr, "", nullptr);
d->setState(ChatRoom::State::CreationPending);
}
}
void ClientGroupChatRoom::leave () {
L_D();
eventHandler->unsubscribe();
......
......@@ -37,7 +37,7 @@ class ClientGroupChatRoomPrivate;
class LINPHONE_PUBLIC ClientGroupChatRoom : public ChatRoom, public RemoteConference {
public:
ClientGroupChatRoom (LinphoneCore *core, const Address &me, const std::string &subject);
ClientGroupChatRoom (LinphoneCore *core, const Address &me, const std::string &uri, const std::string &subject);
virtual ~ClientGroupChatRoom () = default;
public:
......@@ -49,6 +49,7 @@ public:
int getNbParticipants () const override;
std::list<std::shared_ptr<Participant>> getParticipants () const override;
const std::string &getSubject () const override;
void join () override;
void leave () override;
void removeParticipant (const std::shared_ptr<const Participant> &participant) override;
void removeParticipants (const std::list<std::shared_ptr<Participant>> &participants) override;
......
......@@ -165,7 +165,13 @@ const string &RealTimeTextChatRoom::getSubject () const {
return d->subject;
}
void RealTimeTextChatRoom::leave () {}
void RealTimeTextChatRoom::join () {
lError() << "join() is not allowed on a RealTimeTextChatRoom";
}
void RealTimeTextChatRoom::leave () {
lError() << "leave() is not allowed on a RealTimeTextChatRoom";
}
void RealTimeTextChatRoom::removeParticipant (const shared_ptr<const Participant> &participant) {
lError() << "removeParticipant() is not allowed on a RealTimeTextChatRoom";
......
......@@ -51,6 +51,7 @@ public:
int getNbParticipants () const override;
std::list<std::shared_ptr<Participant>> getParticipants () const override;
const std::string &getSubject () const override;
void join () override;
void leave () override;
void removeParticipant (const std::shared_ptr<const Participant> &participant) override;
void removeParticipants (const std::list<std::shared_ptr<Participant>> &participants) override;
......
......@@ -42,6 +42,7 @@ public:
virtual int getNbParticipants () const = 0;
virtual std::list<std::shared_ptr<Participant>> getParticipants () const = 0;
virtual const std::string &getSubject () const = 0;
virtual void join () = 0;
virtual void leave () = 0;
virtual void removeParticipant (const std::shared_ptr<const Participant> &participant) = 0;
virtual void removeParticipants (const std::list<std::shared_ptr<Participant>> &participants) = 0;
......
......@@ -20,6 +20,7 @@
#include "participant-p.h"
#include "conference.h"
#include "conference/session/call-session-p.h"
#include "logger/logger.h"
using namespace std;
......@@ -76,6 +77,8 @@ const string &Conference::getSubject () const {
return subject;
}
void Conference::join () {}
void Conference::leave () {}
void Conference::removeParticipant (const shared_ptr<const Participant> &participant) {
......@@ -166,14 +169,18 @@ void Conference::onResetFirstVideoFrameDecoded (const std::shared_ptr<const Call
// -----------------------------------------------------------------------------
shared_ptr<Participant> Conference::findParticipant (const Address &addr) const {
Address testedAddr = addr;
testedAddr.setPort(0);
for (const auto &participant : participants) {
if (addr.equal(participant->getAddress()))
Address participantAddr = participant->getAddress();
participantAddr.setPort(0);
if (testedAddr.equal(participantAddr))
return participant;
}
return nullptr;
}
shared_ptr<Participant> Conference::findParticipant (const shared_ptr<const CallSession> &session) {
shared_ptr<Participant> Conference::findParticipant (const shared_ptr<const CallSession> &session) const {
for (const auto &participant : participants) {
if (participant->getPrivate()->getSession() == session)
return participant;
......
......@@ -55,6 +55,7 @@ public:
int getNbParticipants () const override;
std::list<std::shared_ptr<Participant>> getParticipants () const override;
const std::string &getSubject () const override;
void join () override;
void leave () override;
void removeParticipant (const std::shared_ptr<const Participant> &participant) override;
void removeParticipants (const std::list<std::shared_ptr<Participant>> &participants) override;
......@@ -81,7 +82,7 @@ protected:
explicit Conference (LinphoneCore *core, const Address &myAddress, CallListener *listener = nullptr);
std::shared_ptr<Participant> findParticipant (const Address &addr) const;
std::shared_ptr<Participant> findParticipant (const std::shared_ptr<const CallSession> &session);
std::shared_ptr<Participant> findParticipant (const std::shared_ptr<const CallSession> &session) const;
bool isMe (const Address &addr) const ;
protected:
......
......@@ -44,7 +44,6 @@ void LocalConference::addParticipant (const Address &addr, const CallSessionPara
if (participant)
return;
participant = ObjectFactory::create<Participant>(addr);
participant->getPrivate()->createSession(*this, params, hasMedia, this);
participants.push_back(participant);
if (!activeParticipant)
activeParticipant = participant;
......
......@@ -39,6 +39,7 @@ class LINPHONE_PUBLIC CallSession : public Object {
friend class CallPrivate;
friend class ClientGroupChatRoom;
friend class ClientGroupChatRoomPrivate;
friend class Conference;
public:
L_OVERRIDE_SHARED_FROM_THIS(CallSession);
......
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