Skip to content

Commit

Permalink
Add and build WebRTC submodule on native
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Apr 11, 2024
1 parent 99069aa commit 20accd9
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
[submodule "src/3rdparty/rapidjson"]
path = src/3rdparty/rapidjson
url = https://github.com/Tencent/rapidjson
[submodule "src/3rdparty/libdatachannel"]
path = src/3rdparty/libdatachannel
url = https://github.com/paullouisageneau/libdatachannel.git
33 changes: 32 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ endif()

option(BUILD_OPENAL "Build OpenAL Soft." ${DEFAULT_OPT})
option(BUILD_OPENGL "Build OpenGL-related code." ${DEFAULT_OPT})
option(BUILD_NETWORKING "Build the networking backend." ${DEFAULT_NET_OPT})
option(BUILD_NETWORKING "Build networking." ${DEFAULT_NET_OPT})
option(BUILD_WEBRTC "Build WebRTC for client and server. This will enable networking on the Web and cross-play between web and native clients." ${DEFAULT_NET_OPT})
option(BUILD_OPENSSL "Build SSL support. Required for secure automatic application updates." ${DEFAULT_NET_OPT})
option(BUILD_FREETYPE "Build FreeType library responsible for loading fonts." ${DEFAULT_OPT})
option(BUILD_WINDOW_FRAMEWORK "Build code specific to a given platfom, e.g. window management done by WinAPI." ${DEFAULT_OPT})
Expand Down Expand Up @@ -245,6 +246,10 @@ else()
message("Building without debugger setup.")
endif()

if (NOT BUILD_NETWORKING)
set(BUILD_WEBRTC OFF)
endif()

if (BUILD_FOR_WEB OR HYPERSOMNIA_BARE)
# Slowly enabling one by one
set(BUILD_FREETYPE ON)
Expand Down Expand Up @@ -1717,6 +1722,10 @@ if(BUILD_NETWORKING)
add_definitions(-DBUILD_NETWORKING=1)
endif()

if(BUILD_WEBRTC)
add_definitions(-DBUILD_WEBRTC=1)
endif()

if(BUILD_FREETYPE)
add_definitions(-DBUILD_FREETYPE=1)
endif()
Expand Down Expand Up @@ -1963,6 +1972,28 @@ if(BUILD_WINDOW_FRAMEWORK)
endif()
endif()

if(BUILD_WEBRTC)
set(USE_GNUTLS OFF CACHE BOOL "" FORCE)
set(USE_MBEDTLS OFF CACHE BOOL "" FORCE)

set(NO_MEDIA ON CACHE BOOL "" FORCE)
set(NO_WEBSOCKET ON CACHE BOOL "" FORCE)
set(NO_EXAMPLES ON CACHE BOOL "" FORCE)
set(NO_TESTS ON CACHE BOOL "" FORCE)

if(BUILD_FOR_WEB)
add_subdirectory("${PROJECT_SOURCE_DIR}/src/3rdparty/datachannel-wasm" EXCLUDE_FROM_ALL)
list(APPEND HYPERSOMNIA_LIBS datachannel-wasm)
else()
add_subdirectory("${PROJECT_SOURCE_DIR}/src/3rdparty/libdatachannel" EXCLUDE_FROM_ALL)

# Would otherwise give error on src/3rdparty/libdatachannel/src/rtp.cpp
target_compile_options(datachannel-static PRIVATE -Wno-cast-align)

list(APPEND HYPERSOMNIA_LIBS datachannel-static)
endif()
endif()

if(BUILD_OPENAL AND NOT BUILD_FOR_WEB)
list(APPEND HYPERSOMNIA_LIBS OpenAL)
endif()
Expand Down
3 changes: 3 additions & 0 deletions docs/pages/todo/brainstorm_now.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ permalink: brainstorm_now
summary: That which we are brainstorming at the moment.
---

- fix spawn prediction on connect to prevent the unpleasant glitch
- might just have to make it predictable instead of dependent on cosmos step?

- "download native client" in the right top

- clicking outside should close buy menu too
Expand Down
1 change: 1 addition & 0 deletions src/3rdparty/libdatachannel
Submodule libdatachannel added at fbd8f2
19 changes: 19 additions & 0 deletions src/augs/network/network_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <cstdio>
#include <stdarg.h>

#if BUILD_WEBRTC
#include "rtc/rtc.hpp"
#endif

bool InitializeYojimbo();
void ShutdownYojimbo();

Expand All @@ -25,6 +29,12 @@ LOG_NOFORMAT(Buffer); // finaly print the text
return 0;
}

#if BUILD_WEBRTC
void rtc_log_callback(rtc::LogLevel, std::string message) {
LOG_NOFORMAT(message);
}
#endif

namespace augs {
namespace network {
void enable_detailed_logs(const bool flag) {
Expand All @@ -38,11 +48,20 @@ namespace augs {
yojimbo_log_level(YOJIMBO_LOG_LEVEL_INFO);
yojimbo_set_printf_function(custom_print);
yojimbo_set_assert_function(log_ensure);

#if BUILD_WEBRTC
rtc::InitLogger(rtc::LogLevel::Info, rtc_log_callback);
rtc::Preload();
#endif

return result;
}

bool deinit() {
LOG("Shutting down the network library.");
#if BUILD_WEBRTC
rtc::Cleanup();
#endif
ShutdownYojimbo();
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions src/work.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
#include "application/setups/editor/packaged_official_content.h"
#include "augs/string/parse_url.h"

#if BUILD_WEBRTC
#include "rtc/rtc.hpp"
#endif

#include "work_result.h"

namespace augs {
Expand Down

0 comments on commit 20accd9

Please sign in to comment.