Skip to content

Commit

Permalink
Merge pull request #1238 from ctrlaltdavid/dev/webrtc-datachannel
Browse files Browse the repository at this point in the history
WebRTC Data Channel
  • Loading branch information
digisomni authored Jul 7, 2021
2 parents a673eba + 7ecd9b6 commit 5a2ca48
Show file tree
Hide file tree
Showing 10 changed files with 926 additions and 21 deletions.
19 changes: 18 additions & 1 deletion domain-server/src/DomainServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ bool DomainServer::forwardMetaverseAPIRequest(HTTPConnection* connection,
DomainServer::DomainServer(int argc, char* argv[]) :
QCoreApplication(argc, argv),
_gatekeeper(this),
#ifdef WEBRTC_DATA_CHANNEL
#ifdef WEBRTC_DATA_CHANNELS
_webrtcSignalingServer(QHostAddress::AnyIPv4, DEFAULT_DOMAIN_SERVER_WS_PORT, this),
_webrtcDataChannels(NodeType::DomainServer, this),
#endif
_httpManager(QHostAddress::AnyIPv4, DOMAIN_SERVER_HTTP_PORT,
QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this)
Expand Down Expand Up @@ -251,6 +252,8 @@ DomainServer::DomainServer(int argc, char* argv[]) :
updateDownstreamNodes();
updateUpstreamNodes();

setUpWebRTC();

if (_type != NonMetaverse) {
// if we have a metaverse domain, we'll use an access token for API calls
resetAccountManagerAccessToken();
Expand Down Expand Up @@ -3136,6 +3139,20 @@ void DomainServer::updateUpstreamNodes() {
updateReplicationNodes(Upstream);
}

void DomainServer::setUpWebRTC() {
#ifdef WEBRTC_DATA_CHANNELS

// Inbound WebRTC signaling messages received from a client.
connect(&_webrtcSignalingServer, &WebRTCSignalingServer::messageReceived,
&_webrtcDataChannels, &WebRTCDataChannels::onSignalingMessage);

// Outbound WebRTC signaling messages being sent to a client.
connect(&_webrtcDataChannels, &WebRTCDataChannels::signalingMessage,
&_webrtcSignalingServer, &WebRTCSignalingServer::sendMessage);

#endif
}

void DomainServer::initializeExporter() {
static const QString ENABLE_EXPORTER = "monitoring.enable_prometheus_exporter";
static const QString EXPORTER_PORT = "monitoring.prometheus_exporter_port";
Expand Down
9 changes: 7 additions & 2 deletions domain-server/src/DomainServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
#include <HTTPSConnection.h>
#include <LimitedNodeList.h>
#include <shared/WebRTC.h>
#if defined(WEBRTC_DATA_CHANNEL)
#if defined(WEBRTC_DATA_CHANNELS)
#include <webrtc/WebRTCDataChannels.h>
#include <webrtc/WebRTCSignalingServer.h>
#endif

Expand Down Expand Up @@ -145,6 +146,9 @@ private slots:
void updateReplicatedNodes();
void updateDownstreamNodes();
void updateUpstreamNodes();

void setUpWebRTC();

void initializeExporter();
void initializeMetadataExporter();

Expand Down Expand Up @@ -316,8 +320,9 @@ private slots:

QThread _assetClientThread;

#ifdef WEBRTC_DATA_CHANNEL
#ifdef WEBRTC_DATA_CHANNELS
WebRTCSignalingServer _webrtcSignalingServer;
WebRTCDataChannels _webrtcDataChannels;
#endif
};

Expand Down
3 changes: 2 additions & 1 deletion libraries/networking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ endif ()

if (WIN32)
# we need ws2_32.lib on windows, but it's static so we don't bubble it up
target_link_libraries(${TARGET_NAME} ws2_32.lib)
# Libraries needed for WebRTC: security.lib winmm.lib
target_link_libraries(${TARGET_NAME} ws2_32.lib security.lib winmm.lib)
elseif(APPLE)
# IOKit is needed for getting machine fingerprint
find_library(FRAMEWORK_IOKIT IOKit)
Expand Down
6 changes: 5 additions & 1 deletion libraries/networking/src/NodeType.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// Created by Stephen Birarda on 05/29/15.
// Copyright 2015 High Fidelity, Inc.
// Copyright 2021 Vircadia contributors.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
Expand All @@ -14,6 +15,10 @@

#pragma once

/// @file
/// @brief NodeType

/// @brief An 8-bit value identifying the type of a node - domain server, audio mixer, etc.
typedef quint8 NodeType_t;

namespace NodeType {
Expand All @@ -37,7 +42,6 @@ namespace NodeType {
NodeType_t upstreamType(NodeType_t primaryType);
NodeType_t downstreamType(NodeType_t primaryType);


NodeType_t fromString(QString type);
}

Expand Down
Loading

0 comments on commit 5a2ca48

Please sign in to comment.