diff options
author | dknn <yoann.blein@free.fr> | 2012-07-08 20:27:27 (GMT) |
---|---|---|
committer | dknn <yoann.blein@free.fr> | 2012-09-22 09:00:01 (GMT) |
commit | 1b2d23c160b4c120a364ff9e86b54e2d8caeaaa4 (patch) | |
tree | 94c9884d7746786568d0da2d6e122dd0f0b5ca9c /Swiften/ScreenSharing/ScreenSharing.cpp | |
parent | 4e0236b08d3914d24af32f45bc99663a73c6d83a (diff) | |
download | swift-contrib-1b2d23c160b4c120a364ff9e86b54e2d8caeaaa4.zip swift-contrib-1b2d23c160b4c120a364ff9e86b54e2d8caeaaa4.tar.bz2 |
Screen sharing managing
Diffstat (limited to 'Swiften/ScreenSharing/ScreenSharing.cpp')
-rw-r--r-- | Swiften/ScreenSharing/ScreenSharing.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Swiften/ScreenSharing/ScreenSharing.cpp b/Swiften/ScreenSharing/ScreenSharing.cpp new file mode 100644 index 0000000..fc7f672 --- /dev/null +++ b/Swiften/ScreenSharing/ScreenSharing.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/ScreenSharing/ScreenSharing.h> + +#include <Swiften/Network/PlatformNetworkEnvironment.h> +#include <Swiften/Elements/JingleRawUDPTransportPayload.h> +#include <Swiften/Base/foreach.h> + +#include <Swiften/Network/UDPSocketFactory.h> +#include <Swiften/Network/UDPSocket.h> + +namespace Swift { + +ScreenSharing::ScreenSharing(boost::shared_ptr<JingleSession> session, UDPSocketFactory* udpSocketFactory) + : session(session), udpSocketFactory(udpSocketFactory) +{ +} + +ScreenSharing::~ScreenSharing() +{ +} + +bool ScreenSharing::addBestCandidate(boost::shared_ptr<JingleRawUDPTransportPayload> transport) +{ + // TODO: NAT traversal + + JingleRawUDPTransportPayload::Candidate candidate; + candidate.cid = idGenerator.generateID(); + candidate.component = 1; + candidate.generation = 0; + + PlatformNetworkEnvironment env; + std::vector<NetworkInterface> interfaces = env.getNetworkInterfaces(); + + // Find the first ip which is not loopback + foreach (const NetworkInterface& interface, interfaces) { + if (!interface.isLoopback()) { // exclude loopback + candidate.hostAddressPort = HostAddressPort(interface.getAddresses().front(), listeningPort); + candidate.type = JingleRawUDPTransportPayload::Candidate::Host; + transport->addCandidate(candidate); + + serverSocket = udpSocketFactory->createUDPSocket(); + serverSocket->bind(listeningPort); + + return true; + } + } + + // else loopback for self sharing + if (!interfaces.empty()) { + candidate.hostAddressPort = HostAddressPort(interfaces.front().getAddresses().front(), listeningPort); + candidate.type = JingleRawUDPTransportPayload::Candidate::Host; + transport->addCandidate(candidate); + + serverSocket = udpSocketFactory->createUDPSocket(); + serverSocket->bind(listeningPort); + + return true; + } + + return false; +} + +} |