diff options
Diffstat (limited to 'Swiften/ScreenSharing/ScreenSharingManagerImpl.cpp')
-rw-r--r-- | Swiften/ScreenSharing/ScreenSharingManagerImpl.cpp | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/Swiften/ScreenSharing/ScreenSharingManagerImpl.cpp b/Swiften/ScreenSharing/ScreenSharingManagerImpl.cpp index 4b88581..a747b81 100644 --- a/Swiften/ScreenSharing/ScreenSharingManagerImpl.cpp +++ b/Swiften/ScreenSharing/ScreenSharingManagerImpl.cpp @@ -6,14 +6,19 @@ #include <Swiften/ScreenSharing/ScreenSharingManagerImpl.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Disco/EntityCapsProvider.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Presence/PresenceOracle.h> #include <Swiften/ScreenSharing/IncomingScreenSharingManager.h> #include <Swiften/ScreenSharing/OutgoingScreenSharingManager.h> namespace Swift { ScreenSharingManagerImpl::ScreenSharingManagerImpl(const JID& ownFullJID, JingleSessionManager *jingleSessionManager, IQRouter *iqRouter, - UDPSocketFactory* udpSocketFactory, TimerFactory* timerFactory) - : ownJID(ownFullJID)/*, jingleSM(jingleSessionManager), iqRouter(iqRouter), udpSocketFactory(udpSocketFactory), timerFactory(timerFactory)*/ + UDPSocketFactory* udpSocketFactory, TimerFactory* timerFactory, PresenceOracle* presenceOrable, + EntityCapsProvider* capsProvider) + : ownJID(ownFullJID)/*, jingleSM(jingleSessionManager), iqRouter(iqRouter), udpSocketFactory(udpSocketFactory), timerFactory(timerFactory)*/, capsProvider(capsProvider), presenceOracle(presenceOrable) { incomingSSManager = new IncomingScreenSharingManager(jingleSessionManager, iqRouter, udpSocketFactory); outgoingSSManager = new OutgoingScreenSharingManager(jingleSessionManager, iqRouter, udpSocketFactory, timerFactory); @@ -27,18 +32,38 @@ ScreenSharingManagerImpl::~ScreenSharingManagerImpl() boost::shared_ptr<OutgoingScreenSharing> ScreenSharingManagerImpl::createOutgoingScreenSharing(const JID &to) { - JID receipient = to; - - if (receipient.isBare()) { - //boost::optional<JID> fullJID = highestPriorityJIDSupportingFileTransfer(receipient); - //if (fullJID.is_initialized()) { - // receipient = fullJID.get(); - //} else { - return boost::shared_ptr<OutgoingScreenSharing>(); - //} + JID recipient = to; + + if (recipient.isBare()) { + boost::optional<JID> fullJID = highestPriorityJIDSupportingScreenSharing(recipient); + if (fullJID.is_initialized()) { + recipient = fullJID.get(); + } else { + return boost::shared_ptr<OutgoingScreenSharing>(); + } + } + + return outgoingSSManager->createOutgoingScreenSharing(ownJID, recipient); +} + +boost::optional<JID> ScreenSharingManagerImpl::highestPriorityJIDSupportingScreenSharing(const JID& bareJID) { + int priority = INT_MIN; + JID fullRecipientJID; + + std::vector<Presence::ref> presences = presenceOracle->getAllPresence(bareJID); + foreach (Presence::ref pres, presences) { + if (pres->getPriority() > priority) { + DiscoInfo::ref info = capsProvider->getCaps(pres->getFrom()); // look up caps from the jid + if (info && info->hasFeature(DiscoInfo::JingleFeature) + && info->hasFeature(DiscoInfo::JingleRTPFeature) + && info->hasFeature(DiscoInfo::JingleTransportRawUDPFeature)) { + priority = pres->getPriority(); + fullRecipientJID = pres->getFrom(); + } + } } - return outgoingSSManager->createOutgoingScreenSharing(ownJID, receipient); + return fullRecipientJID.isValid() ? boost::optional<JID>(fullRecipientJID) : boost::optional<JID>(); } } |