diff --git a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp index cbc5a8ff6e8..a0d5958e705 100644 --- a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp +++ b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp @@ -12,6 +12,9 @@ #include #include +#include + +#include #include "../NetworkLogging.h" @@ -20,10 +23,11 @@ // - https://webrtc.github.io/webrtc-org/native-code/native-apis/ // - https://webrtc.googlesource.com/src/+/master/api/peer_connection_interface.h -const std::string ICE_SERVER_URI = "stun://ice.vircadia.com:7337"; +//const std::string ICE_SERVER_URI = "stun:ice.vircadia.com:7337"; +const std::string ICE_SERVER_URI = "stun1.l.google.com:19302"; const int MAX_WEBRTC_BUFFER_SIZE = 16777216; // 16MB -// #define WEBRTC_DEBUG +#define WEBRTC_DEBUG using namespace webrtc; @@ -388,6 +392,16 @@ WebRTCDataChannels::WebRTCDataChannels(QObject* parent) : // Create a peer connection factory. #ifdef WEBRTC_DEBUG + // Report environment variable values. + qCDebug(networking_webrtc) << "VIRCADIA_WEBRTC_STUN:" + << QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_STUN"); + qCDebug(networking_webrtc) << "VIRCADIA_WEBRTC_INITSSL:" + << QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_INITSSL"); + qCDebug(networking_webrtc) << "VIRCADIA_WEBRTC_CRYPTO:" + << QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_CRYPTO"); + qCDebug(networking_webrtc) << "VIRCADIA_WEBRTC_SCTP:" + << QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_SCTP"); + // Numbers are per WebRTC's peer_connection_interface.h. qCDebug(networking_webrtc) << "1. Create a new PeerConnectionFactoryInterface"; #endif @@ -401,8 +415,30 @@ WebRTCDataChannels::WebRTCDataChannels(QObject* parent) : dependencies.network_thread = _rtcNetworkThread.get(); dependencies.worker_thread = _rtcWorkerThread.get(); dependencies.signaling_thread = _rtcSignalingThread.get(); + + auto initializeSSL = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_INITSSL", "0") == "1"; + if (initializeSSL) { +#ifdef WEBRTC_DEBUG + qCDebug(networking_webrtc) << "InitializeSSL()"; +#endif + rtc::InitializeSSL(); + } + _peerConnectionFactory = CreateModularPeerConnectionFactory(std::move(dependencies)); - if (!_peerConnectionFactory) { + if (_peerConnectionFactory) { + + auto enableEncryption = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_CRYPTO", "1") == "1"; + auto enableSCTP = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_SCTP", "1") == "1"; +#ifdef WEBRTC_DEBUG + qCDebug(networking_webrtc) << "Peer connection encryption enabled =" << enableEncryption; + qCDebug(networking_webrtc) << "SCTP enabled =" << enableSCTP; +#endif + PeerConnectionFactoryInterface::Options pc_options; + pc_options.disable_encryption = !enableEncryption; + pc_options.disable_sctp_data_channels = !enableSCTP; + + _peerConnectionFactory->SetOptions(pc_options); + } else { qCWarning(networking_webrtc) << "Failed to create WebRTC peer connection factory"; } @@ -415,6 +451,15 @@ WebRTCDataChannels::~WebRTCDataChannels() { qCDebug(networking_webrtc) << "WebRTCDataChannels::~WebRTCDataChannels()"; #endif reset(); + + auto initializeSSL = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_INITSSL", "1") == "1"; + if (initializeSSL) { +#ifdef WEBRTC_DEBUG + qCDebug(networking_webrtc) << "CleanupSSL()"; +#endif + rtc::CleanupSSL(); + } + _peerConnectionFactory = nullptr; _rtcSignalingThread->Stop(); _rtcSignalingThread = nullptr; @@ -546,7 +591,17 @@ rtc::scoped_refptr WebRTCDataChannels::createPeerConnec PeerConnectionInterface::RTCConfiguration configuration; PeerConnectionInterface::IceServer iceServer; - iceServer.uri = ICE_SERVER_URI; + + auto stunURI = QProcessEnvironment::systemEnvironment().value("VIRCADIA_WEBRTC_STUN", ""); + if (!stunURI.isEmpty()) { + iceServer.uri = stunURI.toStdString(); + } else { + iceServer.uri = ICE_SERVER_URI; + } +#ifdef WEBRTC_DEBUG + qCDebug(networking_webrtc) << "Using ICE server:" << QString::fromStdString(iceServer.uri); +#endif + configuration.servers.push_back(iceServer); #ifdef WEBRTC_DEBUG