Add JVM Support - #103
Conversation
|
@aschulz90 great job. Let me take some time to review. |
shepeliev
left a comment
There was a problem hiding this comment.
LGTM. I left a couple of comments.
| name = deps.webrtc.java.get().name, | ||
| version = deps.webrtc.java.get().version, | ||
| classifier = "macos-x86_64" | ||
| ) |
There was a problem hiding this comment.
I've got on my Mac M2
java.lang.UnsatisfiedLinkError: /private/var/folders/sp/8h47vr6s72v4hngsrxrfwpzm0000gn/T/libwebrtc-java1779612920915696582.dylib: dlopen(/private/var/folders/sp/8h47vr6s72v4hngsrxrfwpzm0000gn/T/libwebrtc-java1779612920915696582.dylib, 0x0001): tried: '/private/var/folders/sp/8h47vr6s72v4hngsrxrfwpzm0000gn/T/libwebrtc-java1779612920915696582.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/sp/8h47vr6s72v4hngsrxrfwpzm0000gn/T/libwebrtc-java1779612920915696582.dylib' (no such file), '/private/var/folders/sp/8h47vr6s72v4hngsrxrfwpzm0000gn/T/libwebrtc-java1779612920915696582.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
But it's okay if I comment this declaration. I'll try to figure out how to solve this if you don't have M1/M2 at the moment.
There was a problem hiding this comment.
I only have a M1 Mac Mini, so no camera or microphone to test. But also got it at least running, by, like you mentioned, removing the x86 dependency.
I think adding this native dependencies would need to be done by the implementing application. It still worked after I removed the import from the library build.gradle and added it to the sample app build.gradle.
I will remove the import from the library and update the README to reflect that it is neccessary for implementing applications to add the right dependency on their own (like you need to add the WebRTC pod to iOS apps right now).
There was a problem hiding this comment.
I think we have to leave import with classifier in order to run JVM tests in CI. I guess we could solve it as following:
val osName = System.getProperty("os.name").lowercase()
val hostOS = if (osName.contains("mac")) {
"macos"
} else if (osName.contains("linux")) {
"linux"
} else if (osName.contains("windows")) {
"windows"
} else {
throw IllegalStateException("Unsupported OS: $osName")
}
val hostArch = System.getProperty("os.arch").lowercase()
jvmMainApi(deps.webrtc.java)
jvmMainImplementation(
group = deps.webrtc.java.get().group!!,
name = deps.webrtc.java.get().name,
version = deps.webrtc.java.get().version,
classifier = "$hostOS-$hostArch"
)It works well on my Mac. However, I'd like to test it on Windows/Linux too. What do you think?
There was a problem hiding this comment.
For the CI tests in this repo? Then as jvmTestImplementation? I am not that familiar with publishing artifacts and am not sure what the published artifact with one of them defined as a dependency would look like.
But maybe the webrtc-kmp jvm artifact could also be published with every classifier and dependency separately instead?
There was a problem hiding this comment.
I had to add a switch for the architecture, because "os.arch" returned "amd64" on my windows device.
val hostArch = when(val arch = System.getProperty("os.arch").lowercase()) {
"amd64" -> "x86_64"
else -> arch
}
There was a problem hiding this comment.
Let's move tests to the commonTest source set so that they run on all platforms in CI.
However, I think we'll have problem with MediaDevicesTests. It will fail on different platforms as Android, iOS and Mac require permissions to access microphone or camera. Perhaps, we could leave it but add @Ignore annotation for now.
There was a problem hiding this comment.
Sounds good. The MediaDevicesTests where just fo testing the implementation.
|
I've tried to run the JVM sample app on Mac. Unfortunately, there is exception getting user media: Also, JVM tests fail on Mac with It's really great to add JVM platform, however I think we should make it work properly on any OS (windows, macos, linux). |
|
@shepeliev @aschulz90 Any updates on this? |
|
@tamimattafi |
|
@aschulz90 Hello! I have both Mac on Intel and M1, I can help on Saturday if it's suitable for you |
|
@aschulz90 We tried on both M1 and Intel macs, here's a report: 1. Sample run from
|
|
@tamimattafi thanks for the tests. Unfortunately, I don't have any quick answer for these issues on mac. It definitely requires more researching. I'll back to this as soon as be able. |
|
Yeah, I haven't accounted for permissions on desktop. A quick search wasn't that conclusive on how to request them for java applications on macOS. Unfortunately I don't think I can be of much help in that area. |
|
@tamimattafi - Are you using OpenJDK by any chance? And perhaps running this from the IDE and not a built package? Check this: https://bugs.openjdk.org/browse/JDK-8272639 They've used the |
|
@tricknology Yes indeed, I'm using OpenJDK 20 on my machine, and JetBrains Runtime version 17 on the IDE. And indeed I run the sample from My guess is, as you stated that it is better to build a package and install it properly for proper testing with permissions. |
|
@tamimattafi I feel like there should be a way to pass options to the compiler in run config. You might also specify a makefile to do the same.. unfortunately I'm not exactly sure on the step-by-step. |
This should be fixed now. |
|
@its-Chiedu There is a way to pass every detail including info.plist However, I'm having some issues building a .dmg using java 17 and java 20, I will look through the issue when I find some free time. |
|
@shepeliev I have merged the latest changes from |
|
Unfortunately, still have an exception on both of Intel and M2 macs: I guess some problem is in native WebRTC SDK that embeded with WebRTC java lib.
I think we could start with the first option for now. Java background devs help is appreciated :) |
|
Any updates? 🤔 |
|
Probably still blocked by requiring a way to request camera/microphone permissions on macOS JVM. |
|
@aschulz90, good work, do you have a working sample for JVM? |
|
The sample app has JVM desktop support and can be run like described in the Readme. |
|
oh my bad, this may be of discussion but, it runs locally if you actually try in a real scenario, say with a turn server, and you try sending or/and receiving an offer it won't work |
|
Signaling is out of scope of this libary and it shouldn't matter what medium you choose for it: memory, like the sample; HTTP/WebSocket; or avian carrier. TURN works fine in an app I created, but I can't show the source. |
|
I’m not very familiar with this topic, which is why I asked the question. I’m currently learning and noticed that I couldn’t find Firebase.firestore anywhere in the project. Could you please show me where in the code it’s being used for signaling? I have a small sample using Turn signaling, but I can’t figure out why it’s not working. Could you please take a look and help me understand the issue? |
|
Hi @shepeliev and @aschulz90, I’ve spent some time investigating the behavior on macOS and would like to highlight a few points: You need to choose the correct JDK to avoid crashes. I used Amazon Corretto 17, and it has been stable. It appears the sample app needs to request microphone and camera permissions on macOS. I think it could be implemented using a native bridge. |
|
Is there any progress |
… publish 0.125.11-jvm1 Rebase the jvmMain implementation from aschulz90's stale (2024-11-15) upstream PR onto current main: 24 files under webrtc-kmp/src/jvmMain wrapping dev.onvoid.webrtc 0.14.0 (webrtc-java), adapted to the API drift since 2024 -- VideoStreamTrack -> VideoTrack rename, AudioTrack.setVolume (no native equivalent in webrtc-java, implemented as documented no-op), RTCStats.members -> .attributes, MediaDeviceKind losing its AudioOutput variant (WebRtc.getDefaultAudioOutput now returns the native AudioDevice type directly instead of a MediaDeviceInfo). Gradle wrapper 8.11.1 -> 9.6.1 (JDK 25 compat). Wire a local mvn-repo publish repository (signing disabled) for consumption until upstream ships jvm support. Known gaps carried over, left for follow-up: - iOS targets (arm64/simulatorArm64/x64) can't build/publish on this host: Xcode 26.5's iPhoneOS SDK fails cinterop module compilation for WebRTC-SDK.pod (pre-existing environment issue, unrelated to this change -- verified it also fails on unmodified main). Only jvm/android/js/wasmJs published. - 8 of 23 commonTest tests fail on jvmTest: dev.onvoid.webrtc's RTCOfferOptions has no offerToReceiveAudio/offerToReceiveVideo equivalent (only iceRestart) -- commonTest's DefaultOfferAnswerOptions relies on that legacy Plan-B constraint, which Android's org.webrtc still honors via MediaConstraints but webrtc-java dropped entirely. Needs addTransceiver()-based recv-only transceivers instead, or a jvm-specific test adjustment. - Camera/mic capture (getUserMedia) crashes on macOS per the open upstream PR thread (VideoDeviceSource.start, believed to be a permission-request gap) -- never resolved by shepeliev or aschulz90. Untested here since no consumer exercises real device capture yet.
|
This would be a huge improvement for the project. Many of us are looking for a truly multiplatform WebRTC solution, and JVM/Desktop support is one of the biggest missing pieces. Having the same API work across Android, iOS, JS/WasmJs, and Desktop would unlock many real-world Compose Multiplatform applications. I really hope this PR gets merged. Thanks for the work! |
I only tested this on a Windows PC connecting with an Android device. Video/Screensharing and Audio works with the sample apps. DataChannel was only tested via Junit.
Since this relies on webrtc-java for native interop, it should theoretically work on any platform it supports as well.