libdatachannel-java

Java wrappers for libdatachannel, a WebRTC Data Channels standalone implementation in C++.
Usage
Gradle (build.gradle.kts)
implementation("tel.schich:libdatachannel-java:0.24.1.0")
Maven (pom.xml)
<dependency>
<groupId>tel.schich</groupId>
<artifactId>libdatachannel-java</artifactId>
<version>0.24.1.0</version>
</dependency>
Additionally, pull the architecture-specific native components using their the architecture-specific classifier.
Alternatively, use the libdatachannel-java-arch-detect module, which includes common architectures and has
code to detect which one to apply.
Offerer example
var cfg = RTCConfiguration.of("stun.l.google.com:19302");
try (var peer = RTCPeerConnection.createPeer(cfg)) {
peer.onGatheringStateChange((pc, state) -> {
if (RTC_GATHERING_COMPLETE == state) {
var sdp = pc.localDescription();
System.out.println(sdp);
}
});
var channel = peer.createDataChannel("test");
peer.setAnswer(readInput());
channel.onMessage((c, message, size) -> System.out.println("Incoming message: " + new String(message)));
CompletableFuture<Void> future = new CompletableFuture<>();
channel.onClose(c -> future.completeAsync(() -> null));
future.join();
}
Android
For Android apps an additional module exists: libdatachannel-java-android, which has an Android archive (.aar file) as
its main artifact. This artifact contains the native components in the correct file layouts, such that the library works
without any additional initialization code. The arch-detect module will not work on Android without changes!
Permissions
To use libdatachannel on Android, the following permissions are required:
android.permission.INTERNET
Examples
See tests for more examples