/* * 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 #include #include #include namespace Swift { ScreenSharingManagerImpl::ScreenSharingManagerImpl(const JID& ownFullJID, JingleSessionManager *jingleSessionManager, IQRouter *iqRouter, UDPSocketFactory* udpSocketFactory, TimerFactory* timerFactory, PresenceOracle* presenceOrable, EntityCapsProvider* capsProvider) : ownJID(ownFullJID), capsProvider(capsProvider), presenceOracle(presenceOrable) { incomingSSManager = new IncomingScreenSharingManager(jingleSessionManager, iqRouter, udpSocketFactory, timerFactory); outgoingSSManager = new OutgoingScreenSharingManager(jingleSessionManager, iqRouter, udpSocketFactory, timerFactory); responder = new InputEventResponder(this, iqRouter); responder->start(); incomingSSManager->onIncomingScreenSharing.connect(onIncomingScreenSharing); } ScreenSharingManagerImpl::~ScreenSharingManagerImpl() { responder->stop(); delete responder; delete incomingSSManager; delete outgoingSSManager; } 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(); } } OutgoingScreenSharing::ref oss = outgoingSSManager->createOutgoingScreenSharing(ownJID, recipient); outgoingSharings.push_back(oss); return oss; } void ScreenSharingManagerImpl::handleInputEvent(const JID& from, boost::shared_ptr payload) { foreach (OutgoingScreenSharing::ref oss, outgoingSharings) { if (oss->getRecipient() == from) { oss->onNewInputEvent(payload); } } } 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(); } }