Skip to content

Option to build without SCTP/ICE/DTLS/NICE/JUICE #1490

@ungive

Description

@ungive

I'm using this library only for WebSocket connectivity and it would be nice to be able to use it without all of the WebRTC-specific initialization and background threads. This mainly creates two SCTP background threads that aren't needed for WebSockets. I was at least able to compile it and all my tests that used WebSockets passed without it.

To keep a record, here are the changes I made:

src/impl/init.cpp

:100644 100644 0a332feb 00000000 M	src/impl/init.cpp

diff --git a/src/impl/init.cpp b/src/impl/init.cpp
index 0a332feb..dca78540 100644
--- a/src/impl/init.cpp
+++ b/src/impl/init.cpp
@@ -9,10 +9,10 @@
 #include "init.hpp"
 #include "certificate.hpp"
 #include "dtlstransport.hpp"
-#include "icetransport.hpp"
+// #include "icetransport.hpp"
 #include "internals.hpp"
 #include "pollservice.hpp"
-#include "sctptransport.hpp"
+// #include "sctptransport.hpp"
 #include "threadpool.hpp"
 #include "tls.hpp"
 #include "utils.hpp"
@@ -99,13 +99,12 @@ std::shared_future<void> Init::cleanup() {
 void Init::setThreadPoolSize(unsigned int count) {
 	std::lock_guard lock(mMutex);
 	mThreadPoolSize = count;
-
 }
 
 void Init::setSctpSettings(SctpSettings s) {
 	std::lock_guard lock(mMutex);
-	if (mGlobal)
-		SctpTransport::SetSettings(s);
+	// if (mGlobal)
+	// 	SctpTransport::SetSettings(s);
 
 	mCurrentSctpSettings = std::move(s); // store for next init
 }
@@ -124,7 +123,8 @@ void Init::doInit() {
 		throw std::runtime_error("WSAStartup failed, error=" + std::to_string(WSAGetLastError()));
 #endif
 
-	unsigned int count = mThreadPoolSize > 0 ? mThreadPoolSize : std::thread::hardware_concurrency();
+	unsigned int count =
+	    mThreadPoolSize > 0 ? mThreadPoolSize : std::thread::hardware_concurrency();
 	count = std::max(count, MIN_THREADPOOL_SIZE);
 	PLOG_DEBUG << "Spawning " << count << " threads";
 	ThreadPool::Instance().spawn(count);
@@ -141,16 +141,19 @@ void Init::doInit() {
 	openssl::init();
 #endif
 
-	SctpTransport::Init();
-	SctpTransport::SetSettings(mCurrentSctpSettings);
-	DtlsTransport::Init();
+	// SctpTransport::Init();
+	// SctpTransport::SetSettings(mCurrentSctpSettings);
+
+	// DtlsTransport::Init();
+
 #if RTC_ENABLE_WEBSOCKET
 	TlsTransport::Init();
 #endif
 #if RTC_ENABLE_MEDIA
 	DtlsSrtpTransport::Init();
 #endif
-	IceTransport::Init();
+
+	// IceTransport::Init();
 }
 
 void Init::doCleanup() {
@@ -169,15 +172,17 @@ void Init::doCleanup() {
 	PollService::Instance().join();
 #endif
 
-	SctpTransport::Cleanup();
-	DtlsTransport::Cleanup();
+	// SctpTransport::Cleanup();
+	// DtlsTransport::Cleanup();
+
 #if RTC_ENABLE_WEBSOCKET
 	TlsTransport::Cleanup();
 #endif
 #if RTC_ENABLE_MEDIA
 	DtlsSrtpTransport::Cleanup();
 #endif
-	IceTransport::Cleanup();
+
+	// IceTransport::Cleanup();
 
 #ifdef _WIN32
 	WSACleanup();

In CMakeLists.txt I commented out these lines:

if(USE_SYSTEM_USRSCTP)
	find_package(Usrsctp REQUIRED)
else()
	option(sctp_build_shared_lib OFF)
	option(sctp_build_programs OFF)
	option(sctp_inet OFF)
	option(sctp_inet6 OFF)
	option(sctp_werror OFF)
	set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
	add_subdirectory(deps/usrsctp EXCLUDE_FROM_ALL)
	if (MSYS OR MINGW)
		target_compile_definitions(usrsctp PUBLIC -DSCTP_STDINT_INCLUDE=<stdint.h>)
	endif()
	add_library(Usrsctp::Usrsctp ALIAS usrsctp)

	if(INSTALL_DEPS_LIBS)
		install(TARGETS usrsctp EXPORT LibDataChannelTargets)
		# Fix directories
		set_target_properties(usrsctp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
		target_include_directories(usrsctp INTERFACE
			$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/usrsctp/usrsctplib>
			$<INSTALL_INTERFACE:>)
	endif()
endif()

if (USE_NICE)
	find_package(LibNice REQUIRED)
	target_compile_definitions(datachannel PRIVATE USE_NICE=1)
	target_compile_definitions(datachannel-static PRIVATE USE_NICE=1)
	target_link_libraries(datachannel PRIVATE LibNice::LibNice)
	target_link_libraries(datachannel-static PRIVATE LibNice::LibNice)
else()
	target_compile_definitions(datachannel PRIVATE USE_NICE=0)
	target_compile_definitions(datachannel-static PRIVATE USE_NICE=0)
	if(USE_SYSTEM_JUICE)
		find_package(LibJuice 1.7.0 REQUIRED)
		target_compile_definitions(datachannel PRIVATE RTC_SYSTEM_JUICE=1)
		target_compile_definitions(datachannel-static PRIVATE RTC_SYSTEM_JUICE=1)
		target_link_libraries(datachannel PRIVATE LibJuice::LibJuice)
		target_link_libraries(datachannel-static PRIVATE LibJuice::LibJuice)
	else()
		add_subdirectory(deps/libjuice EXCLUDE_FROM_ALL)
		if(INSTALL_DEPS_LIBS)
			install(TARGETS juice EXPORT LibDataChannelTargets)
		endif()
		target_compile_definitions(datachannel PRIVATE RTC_SYSTEM_JUICE=0)
		target_compile_definitions(datachannel-static PRIVATE RTC_SYSTEM_JUICE=0)
		target_link_libraries(datachannel PRIVATE LibJuice::LibJuice)
		target_link_libraries(datachannel-static PRIVATE LibJuice::LibJuiceStatic)
	endif()
endif()

I also removed any linking with Usrsctp::Usrsctp.

I think it's very possible to add a few CMake options to exclude all of these things. I'm happy to make a PR, but someone would definitely have to look over it as I'm not very well versed with WebRTC.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions