/* * Copyright (c) 2012 Yoann Blein * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include #include #include #include #include #include #include namespace Swift { ScreenSharingManagerImpl::ScreenSharingManagerImpl(const JID& ownFullJID, JingleSessionManager *jingleSessionManager, IQRouter *iqRouter, 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); incomingSSManager->onIncomingScreenSharing.connect(onIncomingScreenSharing); } ScreenSharingManagerImpl::~ScreenSharingManagerImpl() { } boost::shared_ptr ScreenSharingManagerImpl::createOutgoingScreenSharing(const JID &to) { JID recipient = to; if (recipient.isBare()) { boost::optional fullJID = highestPriorityJIDSupportingScreenSharing(recipient); if (fullJID.is_initialized()) { recipient = fullJID.get(); } else { return boost::shared_ptr(); } } return outgoingSSManager->createOutgoingScreenSharing(ownJID, recipient); } boost::optional ScreenSharingManagerImpl::highestPriorityJIDSupportingScreenSharing(const JID& bareJID) { int priority = INT_MIN; JID fullRecipientJID; std::vector 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) && info->hasFeature(DiscoInfo::JingleScreenSharingFeature)) { priority = pres->getPriority(); fullRecipientJID = pres->getFrom(); } } } return fullRecipientJID.isValid() ? boost::optional(fullRecipientJID) : boost::optional(); } }