From 402bba9df742fdd2e8be8150b54908278dd09968 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 6 Apr 2018 15:33:13 +0200 Subject: [PATCH] Use REFER to add a new participant to a client group chat room. --- src/chat/chat-room/client-group-chat-room.cpp | 79 ++++++++++++------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index 5a9639621..c36022e94 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -318,22 +318,7 @@ void ClientGroupChatRoom::deleteFromDb () { } void ClientGroupChatRoom::addParticipant (const IdentityAddress &addr, const CallSessionParams *params, bool hasMedia) { - list addresses; - addresses.push_back(addr); - addParticipants(addresses, params, hasMedia); -} - -void ClientGroupChatRoom::addParticipants ( - const list &addresses, - const CallSessionParams *params, - bool hasMedia -) { L_D(); - L_D_T(RemoteConference, dConference); - - list addressesList = d->cleanAddressesList(addresses); - if (addressesList.empty()) - return; if ((getState() != ChatRoom::State::Instantiated) && (getState() != ChatRoom::State::Created)) { lError() << "Cannot add participants to the ClientGroupChatRoom in a state other than Instantiated or Created"; @@ -345,6 +330,41 @@ void ClientGroupChatRoom::addParticipants ( return; } + LinphoneCore *cCore = getCore()->getCCore(); + if (getState() == ChatRoom::State::Instantiated) { + list addressesList; + addressesList.push_back(addr); + Content content; + content.setBody(getResourceLists(addressesList)); + content.setContentType(ContentType::ResourceLists); + content.setContentDisposition(ContentDisposition::RecipientList); + + auto session = d->createSession(); + session->startInvite(nullptr, getSubject(), &content); + d->setState(ChatRoom::State::CreationPending); + } else { + SalReferOp *referOp = new SalReferOp(cCore->sal); + LinphoneAddress *lAddr = linphone_address_new(getConferenceAddress().asString().c_str()); + linphone_configure_op(cCore, referOp, lAddr, nullptr, true); + linphone_address_unref(lAddr); + Address referToAddr = addr; + referToAddr.setParam("text"); + referOp->send_refer(referToAddr.getPrivate()->getInternalAddress()); + referOp->unref(); + } +} + +void ClientGroupChatRoom::addParticipants ( + const list &addresses, + const CallSessionParams *params, + bool hasMedia +) { + L_D(); + + list addressesList = d->cleanAddressesList(addresses); + if (addressesList.empty()) + return; + if ((getState() == ChatRoom::State::Instantiated) && (addressesList.size() == 1) && (linphone_config_get_bool(linphone_core_get_config(L_GET_C_BACK_PTR(getCore())), @@ -353,23 +373,22 @@ void ClientGroupChatRoom::addParticipants ( d->capabilities |= ClientGroupChatRoom::Capabilities::OneToOne; } - Content content; - content.setBody(getResourceLists(addressesList)); - content.setContentType(ContentType::ResourceLists); - content.setContentDisposition(ContentDisposition::RecipientList); - // TODO: Activate compression - //if (linphone_core_content_encoding_supported(getCore()->getCCore(), "deflate")) - // content.setContentEncoding("deflate"); - // TODO: Activate compression + if (getState() == ChatRoom::State::Instantiated) { + Content content; + content.setBody(getResourceLists(addressesList)); + content.setContentType(ContentType::ResourceLists); + content.setContentDisposition(ContentDisposition::RecipientList); + // TODO: Activate compression + //if (linphone_core_content_encoding_supported(getCore()->getCCore(), "deflate")) + // content.setContentEncoding("deflate"); + // TODO: Activate compression - shared_ptr session = dConference->focus->getPrivate()->getSession(); - if (session) - session->update(nullptr, getSubject(), &content); - else { - session = d->createSession(); + auto session = d->createSession(); session->startInvite(nullptr, getSubject(), &content); - if (getState() == ChatRoom::State::Instantiated) - d->setState(ChatRoom::State::CreationPending); + d->setState(ChatRoom::State::CreationPending); + } else { + for (const auto &addr : addresses) + addParticipant(addr, params, hasMedia); } }