From 83d6277a265c6c9f0fa190b31041a6798673e2c7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 4 Oct 2026 01:45:12 +0000 Subject: [PATCH 1/2] Publish to this fork's GitHub Packages Geyser needs the leak fixes in its shaded native library, and upstream's release job only runs on Kas-tle/webrtc-java with Maven Central credentials. Add a GitHubPackages repository to the publication and a workflow that publishes to it. The workflow does not rebuild WebRTC, which takes hours: it downloads the native jars from a finished Build run. It runs on its own after a successful Build on master, or by hand with a Build run ID, and tags the version so the same version is not published twice. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015jA6r9hShSX7PhQWhVa1g1 --- .github/workflows/publish-packages.yml | 87 ++++++++++++++++++++++++++ webrtc/build.gradle.kts | 13 ++++ 2 files changed, 100 insertions(+) create mode 100644 .github/workflows/publish-packages.yml diff --git a/.github/workflows/publish-packages.yml b/.github/workflows/publish-packages.yml new file mode 100644 index 0000000..82b1252 --- /dev/null +++ b/.github/workflows/publish-packages.yml @@ -0,0 +1,87 @@ +name: Publish Packages + +# Publishes webrtc-java to this fork's GitHub Packages, so Geyser can use the fixed native library +# instead of the Maven Central release. Upstream's own release job in build.yml only runs on +# Kas-tle/webrtc-java. +# +# The native jars are not rebuilt here: they are downloaded from a finished Build run, because +# compiling WebRTC takes hours. Runs on its own after a successful Build on master, or by hand +# with the ID of any successful Build run of the same version. +on: + workflow_run: + workflows: + - Build + types: + - completed + branches: + - master + workflow_dispatch: + inputs: + run-id: + description: "ID of the successful Build run whose native jars to publish" + required: true + +permissions: + actions: read + contents: write + packages: write + +jobs: + publish: + if: ${{ github.repository == 'jlftt/webrtc-java' && (github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success') }} + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd + with: + ref: ${{ github.event.workflow_run.head_sha || github.sha }} + # Needed so the existing tags are present locally and the check below is meaningful. + fetch-depth: 0 + name: Checkout Repository + + - name: Read version + id: version + run: echo "version=$(cat gradle.properties | grep version= | cut -d'=' -f2)" >> $GITHUB_OUTPUT + shell: bash + + - name: Check whether the tag already exists + id: check + run: | + if git rev-parse "refs/tags/${{ steps.version.outputs.version }}" >/dev/null 2>&1; then + echo "exists=true" >> $GITHUB_OUTPUT + echo "Tag ${{ steps.version.outputs.version }} already exists - nothing to do." + else + echo "exists=false" >> $GITHUB_OUTPUT + fi + shell: bash + + - uses: ./.github/actions/setup-gradle + if: steps.check.outputs.exists == 'false' + name: Setup Gradle + + # The publication attaches every native jar it finds in native-staging; see + # webrtc/build.gradle.kts. + - name: Download the native jars + if: steps.check.outputs.exists == 'false' + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c + with: + run-id: ${{ github.event.workflow_run.id || inputs.run-id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + path: native-staging + + # Before the tag, so a failed publish can simply be run again: once the tag exists, the check + # above skips everything. + - name: Publish to GitHub Packages + if: steps.check.outputs.exists == 'false' + run: ./gradlew :webrtc:publishMavenPublicationToGitHubPackagesRepository + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash + + - name: Create and push the tag + if: steps.check.outputs.exists == 'false' + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git tag "${{ steps.version.outputs.version }}" + git push origin "${{ steps.version.outputs.version }}" + shell: bash diff --git a/webrtc/build.gradle.kts b/webrtc/build.gradle.kts index 09c226e..61aa0e2 100644 --- a/webrtc/build.gradle.kts +++ b/webrtc/build.gradle.kts @@ -63,6 +63,19 @@ tasks.named("jar") { } publishing { + // This fork's GitHub Packages, used by .github/workflows/publish-packages.yml. Upstream + // publishes to Maven Central instead, which needs credentials this fork does not have. + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/" + (System.getenv("GITHUB_REPOSITORY") ?: "jlftt/webrtc-java")) + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } + publications { create("maven") { artifactId = "webrtc-java" From 49d6994c383d2eabcbeceb4b8bdae4de8bed4c7b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 4 Oct 2026 01:47:44 +0000 Subject: [PATCH 2/2] Describe what this fork changes and how it is published Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015jA6r9hShSX7PhQWhVa1g1 --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index b68519c..31c5a86 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,18 @@ This is a fork of devopvoid's [webrtc-java](https://github.com/devopvoid/webrtc-java) library, a Java wrapper for the [WebRTC Native API](https://webrtc.github.io/webrtc-org/native-code/native-apis). You can join the [Discord](https://discord.gg/5z4GuSnqmQ) for help with this fork. +## This fork + +This is [jlftt](https://github.com/jlftt)'s fork of [Kas-tle/webrtc-java](https://github.com/Kas-tle/webrtc-java), used by the [Geyser](https://github.com/jlftt/Geyser) portal bridge through [NetworkCompatible](https://github.com/jlftt/NetworkCompatible). It fixes memory leaks that grew a busy Velocity proxy's heap by about 100 MB an hour: + +- **Every received message** leaked two Java objects, the `RTCDataChannelBuffer` handed to the observer and the direct `ByteBuffer` inside it. `OnMessage` runs on a native thread that stays attached to the JVM, so the JNI local references it created were never freed. They are now deleted after each message. +- **Every closed connection** leaked its native `PeerConnection`: `close()` cleared the Java handle without releasing the reference it owned. It now releases it. +- **Every registered data channel observer** leaked, along with the JNI global reference to the Java observer, which kept the whole closed channel reachable. It is now freed when it is replaced, unregistered, or the channel is disposed. A callback whose thread can no longer attach to the JVM is dropped instead of crashing. + +The last two are ported from devopvoid/webrtc-java@8b77ec8, the first matches devopvoid/webrtc-java@40e538b. + +Versions are named `1.0.4-ip.N`. The **Publish Packages** workflow publishes them to this repository's GitHub Packages, with the native jars of a finished **Build** run, so a release does not rebuild WebRTC. It runs after each successful Build on `master`, or by hand with a Build run ID. Reading the packages needs a token with `read:packages`; Geyser's release uses its `PACKAGES_TOKEN` secret. + ## Differences from the Original Project This stripped down version of the library removes audio and video support, focusing solely on data channels for peer-to-peer data exchange. It is intended for use cases where only data transfer is required, such as multiplayer gaming or real-time data synchronization. The removal of media capabilities results in a significantly smaller library size and increased portability.