From 2243783c16095ebc9b2b364dc7f955fccea232e7 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Wed, 25 Oct 2017 11:50:10 +0200 Subject: [PATCH] add possibility to notify conference event to only one participant --- .../local-conference-event-handler-p.h | 17 ++--- .../local-conference-event-handler.cpp | 64 +++++++++++++------ 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/conference/local-conference-event-handler-p.h b/src/conference/local-conference-event-handler-p.h index 82b11f083..b194d65c4 100644 --- a/src/conference/local-conference-event-handler-p.h +++ b/src/conference/local-conference-event-handler-p.h @@ -33,13 +33,14 @@ public: void notifyFullState (const std::string ¬ify, LinphoneEvent *lev); void notifyAllExcept (const std::string ¬ify, const Address &addr); void notifyAll (const std::string ¬ify); - std::string createNotifyFullState (); - std::string createNotifyParticipantAdded (const Address &addr); - std::string createNotifyParticipantRemoved (const Address &addr); - std::string createNotifyParticipantAdmined (const Address &addr, bool isAdmin); - std::string createNotifySubjectChanged (); - std::string createNotifyParticipantDeviceAdded (const Address &addr, const Address &gruu); - std::string createNotifyParticipantDeviceRemoved (const Address &addr, const Address &gruu); + void notifyParticipant (const std::string ¬ify, const Address &addr); + std::string createNotifyFullState (int notifyId = -1); + std::string createNotifyParticipantAdded (const Address &addr, int notifyId = -1); + std::string createNotifyParticipantRemoved (const Address &addr, int notifyId = -1); + std::string createNotifyParticipantAdmined (const Address &addr, bool isAdmin, int notifyId = -1); + std::string createNotifySubjectChanged (int notifyId = -1); + std::string createNotifyParticipantDeviceAdded (const Address &addr, const Address &gruu, int notifyId = -1); + std::string createNotifyParticipantDeviceRemoved (const Address &addr, const Address &gruu, int notifyId = -1); inline unsigned int getLastNotify () const { return lastNotify; }; @@ -48,7 +49,7 @@ private: LocalConference *conf = nullptr; unsigned int lastNotify = 0; - std::string createNotify (Xsd::ConferenceInfo::ConferenceType confInfo); + std::string createNotify (Xsd::ConferenceInfo::ConferenceType confInfo, int notifyId = -1); void sendNotify (const std::string ¬ify, const Address &addr); L_DECLARE_PUBLIC(LocalConferenceEventHandler); diff --git a/src/conference/local-conference-event-handler.cpp b/src/conference/local-conference-event-handler.cpp index 94ca0c870..0eb844d3d 100644 --- a/src/conference/local-conference-event-handler.cpp +++ b/src/conference/local-conference-event-handler.cpp @@ -23,6 +23,7 @@ #include "conference/participant-p.h" #include "linphone/utils/utils.h" #include "local-conference-event-handler-p.h" +#include "logger/logger.h" #include "object/object-p.h" #include "private.h" @@ -67,9 +68,22 @@ void LocalConferenceEventHandlerPrivate::notifyAll (const string ¬ify) { } } -string LocalConferenceEventHandlerPrivate::createNotify (ConferenceType confInfo) { - lastNotify = lastNotify + 1; - confInfo.setVersion(lastNotify); +void LocalConferenceEventHandlerPrivate::notifyParticipant (const string ¬ify, const Address &addr) { + Address cleanedAddr(addr); + cleanedAddr.setPort(0); + shared_ptr participant = conf->findParticipant(cleanedAddr); + if (participant->getPrivate()->isSubscribedToConferenceEventPackage()) + sendNotify(notify, participant->getAddress()); +} + +string LocalConferenceEventHandlerPrivate::createNotify (ConferenceType confInfo, int notifyId) { + if (notifyId == -1) { + lastNotify = lastNotify + 1; + confInfo.setVersion(lastNotify); + } else { + confInfo.setVersion(static_cast(notifyId)); + } + if (!confInfo.getConferenceDescription()) { ConferenceDescriptionType description = ConferenceDescriptionType(); confInfo.setConferenceDescription(description); @@ -85,7 +99,7 @@ string LocalConferenceEventHandlerPrivate::createNotify (ConferenceType confInfo return notify.str(); } -string LocalConferenceEventHandlerPrivate::createNotifyFullState () { +string LocalConferenceEventHandlerPrivate::createNotifyFullState (int notifyId) { string entity = conf->getConferenceAddress().asStringUriOnly(); string subject = conf->getSubject(); ConferenceType confInfo = ConferenceType(entity); @@ -116,10 +130,10 @@ string LocalConferenceEventHandlerPrivate::createNotifyFullState () { confInfo.getUsers()->getUser().push_back(user); } - return createNotify(confInfo); + return createNotify(confInfo, notifyId); } -string LocalConferenceEventHandlerPrivate::createNotifyParticipantAdded (const Address &addr) { +string LocalConferenceEventHandlerPrivate::createNotifyParticipantAdded (const Address &addr, int notifyId) { string entity = conf->getConferenceAddress().asStringUriOnly(); ConferenceType confInfo = ConferenceType(entity); UsersType users; @@ -146,10 +160,10 @@ string LocalConferenceEventHandlerPrivate::createNotifyParticipantAdded (const A confInfo.getUsers()->getUser().push_back(user); - return createNotify(confInfo); + return createNotify(confInfo, notifyId); } -string LocalConferenceEventHandlerPrivate::createNotifyParticipantRemoved (const Address &addr) { +string LocalConferenceEventHandlerPrivate::createNotifyParticipantRemoved (const Address &addr, int notifyId) { string entity = conf->getConferenceAddress().asStringUriOnly(); ConferenceType confInfo = ConferenceType(entity); UsersType users; @@ -160,10 +174,10 @@ string LocalConferenceEventHandlerPrivate::createNotifyParticipantRemoved (const user.setState("deleted"); confInfo.getUsers()->getUser().push_back(user); - return createNotify(confInfo); + return createNotify(confInfo, notifyId); } -string LocalConferenceEventHandlerPrivate::createNotifyParticipantAdmined (const Address &addr, bool isAdmin) { +string LocalConferenceEventHandlerPrivate::createNotifyParticipantAdmined (const Address &addr, bool isAdmin, int notifyId) { string entity = conf->getConferenceAddress().asStringUriOnly(); ConferenceType confInfo = ConferenceType(entity); UsersType users; @@ -177,10 +191,10 @@ string LocalConferenceEventHandlerPrivate::createNotifyParticipantAdmined (const user.setState("partial"); confInfo.getUsers()->getUser().push_back(user); - return createNotify(confInfo); + return createNotify(confInfo, notifyId); } -string LocalConferenceEventHandlerPrivate::createNotifySubjectChanged () { +string LocalConferenceEventHandlerPrivate::createNotifySubjectChanged (int notifyId) { string entity = conf->getConferenceAddress().asStringUriOnly(); string subject = conf->getSubject(); ConferenceType confInfo = ConferenceType(entity); @@ -188,10 +202,10 @@ string LocalConferenceEventHandlerPrivate::createNotifySubjectChanged () { confDescr.setSubject(subject); confInfo.setConferenceDescription((const ConferenceDescriptionType)confDescr); - return createNotify(confInfo); + return createNotify(confInfo, notifyId); } -string LocalConferenceEventHandlerPrivate::createNotifyParticipantDeviceAdded (const Address &addr, const Address &gruu) { +string LocalConferenceEventHandlerPrivate::createNotifyParticipantDeviceAdded (const Address &addr, const Address &gruu, int notifyId) { string entity = conf->getConferenceAddress().asStringUriOnly(); ConferenceType confInfo = ConferenceType(entity); UsersType users; @@ -212,10 +226,10 @@ string LocalConferenceEventHandlerPrivate::createNotifyParticipantDeviceAdded (c confInfo.getUsers()->getUser().push_back(user); - return createNotify(confInfo); + return createNotify(confInfo, notifyId); } -string LocalConferenceEventHandlerPrivate::createNotifyParticipantDeviceRemoved (const Address &addr, const Address &gruu) { +string LocalConferenceEventHandlerPrivate::createNotifyParticipantDeviceRemoved (const Address &addr, const Address &gruu, int notifyId) { string entity = conf->getConferenceAddress().asStringUriOnly(); ConferenceType confInfo = ConferenceType(entity); UsersType users; @@ -236,7 +250,7 @@ string LocalConferenceEventHandlerPrivate::createNotifyParticipantDeviceRemoved confInfo.getUsers()->getUser().push_back(user); - return createNotify(confInfo); + return createNotify(confInfo, notifyId); } void LocalConferenceEventHandlerPrivate::sendNotify (const string ¬ify, const Address &addr) { @@ -250,7 +264,8 @@ void LocalConferenceEventHandlerPrivate::sendNotify (const string ¬ify, const // ============================================================================= -LocalConferenceEventHandler::LocalConferenceEventHandler (LinphoneCore *core, LocalConference *localConf) : Object(*new LocalConferenceEventHandlerPrivate) { +LocalConferenceEventHandler::LocalConferenceEventHandler (LinphoneCore *core, LocalConference *localConf) : + Object(*new LocalConferenceEventHandlerPrivate) { L_D(); xercesc::XMLPlatformUtils::Initialize(); d->conf = localConf; @@ -272,12 +287,19 @@ void LocalConferenceEventHandler::subscribeReceived (LinphoneEvent *lev) { bctbx_free(addrStr); if (participant) { if (linphone_event_get_subscription_state(lev) == LinphoneSubscriptionActive) { - int lastNotify = Utils::stoi(linphone_event_get_custom_header(lev, "Last-Notify-Version")); - if(lastNotify == 0) { + unsigned int lastNotify = static_cast(Utils::stoi(linphone_event_get_custom_header(lev, "Last-Notify-Version"))); + if (lastNotify == 0) { + lInfo() << "Sending initial notify of conference:" << d->conf->getConferenceAddress().asStringUriOnly() << " to: " << addrStr; participant->getPrivate()->subscribeToConferenceEventPackage(true); d->notifyFullState(d->createNotifyFullState(), lev); - } else { + } else if (lastNotify < d->lastNotify) { + lInfo() << "Sending all missed notify for conference:" << d->conf->getConferenceAddress().asStringUriOnly() << + " from: " << lastNotify << " to: " << addrStr; // TODO : send all missed notify from lastNotify to d->lastNotify + } else if (lastNotify > d->lastNotify) { + lError() << "last notify received by client: [" << lastNotify <<"] for confernce:" << + d->conf->getConferenceAddress().asStringUriOnly() << + " should not be higher than last notify sent by server: [" << d->lastNotify << "]."; } } else if (linphone_event_get_subscription_state(lev) == LinphoneSubscriptionTerminated) participant->getPrivate()->subscribeToConferenceEventPackage(false);