diff --git a/Cargo.lock b/Cargo.lock index 72c40032..a11986ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1159,6 +1159,7 @@ dependencies = [ "env_logger", "futures-util", "imgproc", + "jni", "lazy_static", "livekit", "livekit-api", diff --git a/livekit-ffi/Cargo.toml b/livekit-ffi/Cargo.toml index f111bfa9..4d7dc8f4 100644 --- a/livekit-ffi/Cargo.toml +++ b/livekit-ffi/Cargo.toml @@ -34,6 +34,9 @@ downcast-rs = "1.2" console-subscriber = { version = "0.1", features = ["parking_lot"], optional = true } imgproc = "0.3.11" +[target.'cfg(target_os = "android")'.dependencies] +jni = "0.21.1" + [build-dependencies] webrtc-sys-build = { path = "../webrtc-sys/build", version = "0.3.0" } diff --git a/livekit-ffi/src/cabi.rs b/livekit-ffi/src/cabi.rs index 517ce992..a56c8f8c 100644 --- a/livekit-ffi/src/cabi.rs +++ b/livekit-ffi/src/cabi.rs @@ -84,3 +84,20 @@ pub unsafe extern "C" fn livekit_ffi_request( pub extern "C" fn livekit_ffi_drop_handle(handle_id: FfiHandleId) -> bool { FFI_SERVER.drop_handle(handle_id) } + +#[cfg(target_os = "android")] +pub mod android { + use jni::{ + sys::{jint, JNI_VERSION_1_6}, + JavaVM, + }; + use std::os::raw::c_void; + + #[allow(non_snake_case)] + #[no_mangle] + pub extern "C" fn JNI_OnLoad(vm: JavaVM, _: *mut c_void) -> jint { + println!("JNI_OnLoad, initializing LiveKit"); + livekit::webrtc::android::initialize_android(&vm); + JNI_VERSION_1_6 + } +}