summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/ScreenSharing/ScreenSharing.cpp')
-rw-r--r--Swiften/ScreenSharing/ScreenSharing.cpp68
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;
+}
+
+}