Skip to content

pschichtel/libdatachannel-java

Repository files navigation

libdatachannel-java

License: MPL 2.0

Java wrappers for libdatachannel, a WebRTC Data Channels standalone implementation in C++.

Usage

Gradle (build.gradle.kts)

implementation("tel.schich.libdatachannel:libdatachannel-java:0.21.1")

Maven (pom.xml)

<dependency>
    <groupId>tel.schich.libdatachannel</groupId>
    <artifactId>libdatachannel-java</artifactId>
    <version>0.21.1</version>
</dependency>

Offerer example

var cfg = RTCConfiguration.of("stun.l.google.com:19302");
// try with resources to cleanup peer when done
try (var peer = RTCPeerConnection.createPeer(cfg)) {
        // when complete send sdp to remote peer
        peer.onGatheringStateChange((pc, state) -> {
        if (RTC_GATHERING_COMPLETE == state) {
var sdp = pc.localDescription();
            System.out.println(sdp);
        }
                });
// create data channel
var channel = peer.createDataChannel("test");
// wait for local sdp...
// then set answer from remote peer
    peer.setAnswer(readInput());
        // register message callback
        channel.onMessage((c, message, size) -> 
            System.out.println("Incoming message: " + new String(message)));
// block until channel is closed
CompletableFuture<Void> future = new CompletableFuture<>();
    channel.onClose(c -> future.completeAsync(() -> null));
        future.join();
}

Examples

See tests for more examples

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published