blob: 532b73dc12b5bfad6cea726920e57814e5719115 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
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;
}
}
|