Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions webrtc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ tasks.named<Jar>("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<MavenPublication>("maven") {
artifactId = "webrtc-java"
Expand Down
Loading