/* * 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 namespace Swift { ScreenSharing::ScreenSharing(boost::shared_ptr session, UDPSocketFactory* udpSocketFactory) : session(session), udpSocketFactory(udpSocketFactory) { } ScreenSharing::~ScreenSharing() { } bool ScreenSharing::addBestCandidate(boost::shared_ptr transport) { // TODO: NAT traversal JingleRawUDPTransportPayload::Candidate candidate; candidate.cid = idGenerator.generateID(); candidate.component = 1; candidate.generation = 0; PlatformNetworkEnvironment env; std::vector interfaces = env.getNetworkInterfaces(); // Find the first ip which is not loopback foreach (const NetworkInterface& interface, interfaces) { if (!interface.isLoopback()) { // exclude loopback serverSocket = udpSocketFactory->createUDPSocket(); serverSocket->bind(0); candidate.hostAddressPort = HostAddressPort(interface.getAddresses().front(), serverSocket->getLocalAddress().getPort()); candidate.type = JingleRawUDPTransportPayload::Candidate::Host; transport->addCandidate(candidate); return true; } } // else loopback for self sharing if (!interfaces.empty()) { serverSocket = udpSocketFactory->createUDPSocket(); serverSocket->bind(0); candidate.hostAddressPort = HostAddressPort(interfaces.front().getAddresses().front(), serverSocket->getLocalAddress().getPort()); candidate.type = JingleRawUDPTransportPayload::Candidate::Host; transport->addCandidate(candidate); return true; } return false; } }