diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index 4a3b6d93f..0f11648e8 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -23,7 +23,8 @@ #include "basic-to-client-group-chat-room.h" #include "c-wrapper/c-wrapper.h" #include "client-group-chat-room-p.h" -#include "conference/handlers/remote-conference-event-handler.h" +#include "conference/handlers/remote-conference-event-handler-p.h" +#include "conference/handlers/remote-conference-list-event-handler.h" #include "conference/participant-p.h" #include "conference/remote-conference-p.h" #include "conference/session/call-session-p.h" @@ -214,8 +215,9 @@ RemoteConference(core, me->getAddress(), nullptr) { getMe()->getPrivate()->setAdmin(me->isAdmin()); + dConference->eventHandler->setChatRoomId(chatRoomId); dConference->eventHandler->setLastNotify(lastNotifyId); - // dConference->eventHandler->subscribe(getChatRoomId()); + getCore()->getPrivate()->remoteListEventHandler->addHandler(dConference->eventHandler); } ClientGroupChatRoom::~ClientGroupChatRoom () { diff --git a/src/conference/handlers/remote-conference-event-handler.cpp b/src/conference/handlers/remote-conference-event-handler.cpp index 090c81ff6..cd1d04992 100644 --- a/src/conference/handlers/remote-conference-event-handler.cpp +++ b/src/conference/handlers/remote-conference-event-handler.cpp @@ -299,6 +299,11 @@ void RemoteConferenceEventHandler::multipartNotifyReceived (const string &xmlBod // ----------------------------------------------------------------------------- +void RemoteConferenceEventHandler::setChatRoomId (ChatRoomId chatRoomId) { + L_D(); + d->chatRoomId = chatRoomId; +} + const ChatRoomId &RemoteConferenceEventHandler::getChatRoomId () const { L_D(); return d->chatRoomId; diff --git a/src/conference/handlers/remote-conference-event-handler.h b/src/conference/handlers/remote-conference-event-handler.h index c7dae40ac..e5e1cfbff 100644 --- a/src/conference/handlers/remote-conference-event-handler.h +++ b/src/conference/handlers/remote-conference-event-handler.h @@ -40,6 +40,7 @@ public: void multipartNotifyReceived (const std::string &xmlBody); void unsubscribe (); + void setChatRoomId (ChatRoomId chatRoomId); const ChatRoomId &getChatRoomId () const; unsigned int getLastNotify () const; diff --git a/src/conference/handlers/remote-conference-list-event-handler.cpp b/src/conference/handlers/remote-conference-list-event-handler.cpp index aef6184da..9293128b1 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.cpp +++ b/src/conference/handlers/remote-conference-list-event-handler.cpp @@ -44,6 +44,23 @@ LINPHONE_BEGIN_NAMESPACE // ----------------------------------------------------------------------------- +RemoteConferenceListEventHandler::RemoteConferenceListEventHandler (const std::shared_ptr &core) : CoreAccessor(core) { + getCore()->getPrivate()->registerListener(this); +} + +RemoteConferenceListEventHandler::~RemoteConferenceListEventHandler () { + try { + getCore()->getPrivate()->unregisterListener(this); + } catch (const bad_weak_ptr &) { + // Unable to unregister listener here. Core is destroyed and the listener doesn't exist. + } + + if (lev) + unsubscribe(); +} + +// ----------------------------------------------------------------------------- + void RemoteConferenceListEventHandler::subscribe () { if (lev) return; @@ -56,7 +73,7 @@ void RemoteConferenceListEventHandler::subscribe () { for (const auto &handler : handlers) { Address addr = handler->getChatRoomId().getPeerAddress(); addr.setUriParam("Last-Notify", Utils::toString(handler->getLastNotify())); - Xsd::ResourceLists::EntryType entry = Xsd::ResourceLists::EntryType(addr.asString()); + Xsd::ResourceLists::EntryType entry = Xsd::ResourceLists::EntryType(addr.asStringUriOnly()); l.getEntry().push_back(entry); } rl.getList().push_back(l); @@ -123,6 +140,25 @@ void RemoteConferenceListEventHandler::notifyReceived (Content *multipart) { } } +// ----------------------------------------------------------------------------- + +shared_ptr RemoteConferenceListEventHandler::findHandler (const ChatRoomId &chatRoomId) const { + for (const auto &handler : handlers) { + if (handler->getChatRoomId() == chatRoomId) + return handler; + } + + return nullptr; +} + +const list> &RemoteConferenceListEventHandler::getHandlers () const { + return handlers; +} + +void RemoteConferenceListEventHandler::addHandler (std::shared_ptr handler) { + handlers.push_back(handler); +} + map RemoteConferenceListEventHandler::parseRlmi (const string &xmlBody) const { istringstream data(xmlBody); unique_ptr rlmi(Xsd::Rlmi::parseList( @@ -146,21 +182,16 @@ map RemoteConferenceListEventHandler::parseRlmi (const string return addresses; } -void RemoteConferenceListEventHandler::addHandler (std::shared_ptr handler) { - handlers.push_back(handler); +// ----------------------------------------------------------------------------- + +void RemoteConferenceListEventHandler::onNetworkReachable (bool sipNetworkReachable, bool mediaNetworkReachable) { + if (!sipNetworkReachable) + unsubscribe(); } -shared_ptr RemoteConferenceListEventHandler::findHandler (const ChatRoomId &chatRoomId) const { - for (const auto &handler : handlers) { - if (handler->getChatRoomId() == chatRoomId) - return handler; - } - - return nullptr; -} - -const list> &RemoteConferenceListEventHandler::getHandlers () const { - return handlers; +void RemoteConferenceListEventHandler::onRegistrationStateChanged (LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const std::string &message) { + if (state == LinphoneRegistrationOk) + subscribe(); } LINPHONE_END_NAMESPACE diff --git a/src/conference/handlers/remote-conference-list-event-handler.h b/src/conference/handlers/remote-conference-list-event-handler.h index 43a25e6a1..6b606c305 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.h +++ b/src/conference/handlers/remote-conference-list-event-handler.h @@ -30,6 +30,7 @@ #include "chat/chat-room/chat-room-id.h" #include "content/content.h" #include "core/core-accessor.h" +#include "core/core-listener.h" // ============================================================================= @@ -38,8 +39,11 @@ LINPHONE_BEGIN_NAMESPACE class Address; class RemoteConferenceEventHandler; -class RemoteConferenceListEventHandler : public Object, public CoreAccessor { +class RemoteConferenceListEventHandler : public CoreAccessor , public CoreListener { public: + RemoteConferenceListEventHandler (const std::shared_ptr &core); + ~RemoteConferenceListEventHandler (); + void subscribe (); void unsubscribe (); void notifyReceived (Content *multipart); @@ -52,6 +56,10 @@ private: LinphoneEvent *lev = nullptr; std::map parseRlmi (const std::string &xmlBody) const; + + // CoreListener + void onNetworkReachable (bool sipNetworkReachable, bool mediaNetworkReachable) override; + void onRegistrationStateChanged (LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const std::string &message) override; }; LINPHONE_END_NAMESPACE diff --git a/src/conference/remote-conference-p.h b/src/conference/remote-conference-p.h index 01c09bef3..9d256af10 100644 --- a/src/conference/remote-conference-p.h +++ b/src/conference/remote-conference-p.h @@ -32,7 +32,7 @@ class RemoteConferenceEventHandler; class RemoteConferencePrivate : public ConferencePrivate { public: std::shared_ptr focus; - std::unique_ptr eventHandler; + std::shared_ptr eventHandler; private: L_DECLARE_PUBLIC(RemoteConference); diff --git a/src/content/content.cpp b/src/content/content.cpp index 78aabcf4b..161ffe1cf 100644 --- a/src/content/content.cpp +++ b/src/content/content.cpp @@ -234,6 +234,7 @@ LinphoneContent *Content::toLinphoneContent () const { LinphoneContent *content = linphone_core_create_content(nullptr); linphone_content_set_type(content, getContentType().getType().c_str()); linphone_content_set_subtype(content, getContentType().getSubType().c_str()); + linphone_content_set_buffer(content, (const uint8_t *)getBodyAsUtf8String().c_str(), getBodyAsUtf8String().size()); return content; } diff --git a/src/core/core-p.h b/src/core/core-p.h index 0106dd502..a3f6b5049 100644 --- a/src/core/core-p.h +++ b/src/core/core-p.h @@ -31,6 +31,7 @@ LINPHONE_BEGIN_NAMESPACE class CoreListener; +class RemoteConferenceListEventHandler; class CorePrivate : public ObjectPrivate { public: @@ -65,6 +66,7 @@ public: void replaceChatRoom (const std::shared_ptr &replacedChatRoom, const std::shared_ptr &newChatRoom); std::unique_ptr mainDb; + std::unique_ptr remoteListEventHandler; private: std::list listeners; diff --git a/src/core/core.cpp b/src/core/core.cpp index 9e9d94cc6..039dba557 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -20,8 +20,11 @@ #include #include +//#include "linphone/utils/general.h" + #include "address/address-p.h" #include "call/call.h" +#include "conference/handlers/remote-conference-list-event-handler.h" #include "core/core-listener.h" #include "core/core-p.h" #include "logger/logger.h" @@ -42,6 +45,7 @@ LINPHONE_BEGIN_NAMESPACE void CorePrivate::init () { L_Q(); mainDb.reset(new MainDb(q->getSharedFromThis())); + remoteListEventHandler = makeUnique(q->getSharedFromThis()); AbstractDb::Backend backend; string uri = L_C_TO_STRING(lp_config_get_string(linphone_core_get_config(L_GET_C_BACK_PTR(q)), "storage", "uri", nullptr)); diff --git a/src/core/core.h b/src/core/core.h index a8a15630a..f79082d30 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -56,6 +56,7 @@ class LINPHONE_PUBLIC Core : public Object { friend class MainDbEventKey; friend class MediaSessionPrivate; friend class RemoteConferenceEventHandler; + friend class RemoteConferenceListEventHandler; friend class ServerGroupChatRoom; friend class ServerGroupChatRoomPrivate;