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
11 changes: 11 additions & 0 deletions examples/mobile/android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea/AndroidProjectSystem.xml
/.idea/migrations.xml
/.idea/misc.xml
/.idea/vcs.xml
/.idea/codeStyles
/.idea/runConfigurations.xml
/.idea/gradle.xml
/.idea/deploymentTargetSelector.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

# Generated native libraries (built via cargo-ndk)
/app/src/main/jniLibs/
6 changes: 6 additions & 0 deletions examples/mobile/android/.idea/AndroidProjectSystem.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions examples/mobile/android/.idea/gradle.xml

This file was deleted.

10 changes: 0 additions & 10 deletions examples/mobile/android/.idea/misc.xml

This file was deleted.

6 changes: 0 additions & 6 deletions examples/mobile/android/.idea/vcs.xml

This file was deleted.

24 changes: 12 additions & 12 deletions examples/mobile/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {

android {
namespace 'io.livekit.rustexample'
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "io.livekit.rustexample"
minSdk 24
targetSdk 33
targetSdk 34
versionCode 1
versionName "1.0"

Expand All @@ -27,17 +27,17 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.3.2'
kotlinCompilerExtensionVersion '1.5.8'
}
packagingOptions {
resources {
Expand All @@ -48,19 +48,19 @@ android {

dependencies {
implementation files('libs/libwebrtc.jar')
implementation 'androidx.core:core-ktx:1.8.0'
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.5.1'
implementation platform('androidx.compose:compose-bom:2022.10.00')
implementation 'androidx.core:core-ktx:1.12.0'
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.9.22')
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0'
implementation 'androidx.activity:activity-compose:1.8.2'
implementation platform('androidx.compose:compose-bom:2024.02.01')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
androidTestImplementation platform('androidx.compose:compose-bom:2024.02.01')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
Expand Down
Binary file modified examples/mobile/android/app/libs/libwebrtc.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/mobile/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,91 @@
package io.livekit.rustexample

import android.util.Log

class App {
private val nativeAvailable: Boolean

init {
System.loadLibrary("mobile")
nativeAvailable = try {
System.loadLibrary("mobile")
true
} catch (error: UnsatisfiedLinkError) {
Log.w(TAG, "Native library not found; skipping LiveKit init.", error)
false
}
}

// Connection methods
private external fun connectNative(url: String, token: String)
private external fun disconnectNative()
private external fun isConnectedNative(): Boolean

// Audio methods
private external fun pushAudioNative(samples: ShortArray): Int
private external fun pullAudioNative(buffer: ShortArray): Int
private external fun getPlaybackBufferSizeNative(): Int

fun connect(url: String, token: String) {
if (!nativeAvailable) {
Log.w(TAG, "LiveKit native library unavailable; connect() ignored.")
return
}
connectNative(url, token)
}

fun disconnect() {
if (!nativeAvailable) {
Log.w(TAG, "LiveKit native library unavailable; disconnect() ignored.")
return
}
disconnectNative()
}

fun isConnected(): Boolean {
if (!nativeAvailable) {
return false
}
return isConnectedNative()
}

/**
* Push captured microphone audio to LiveKit.
* @param samples 16-bit PCM samples (mono, 48kHz expected)
* @return Number of samples consumed
*/
fun pushAudio(samples: ShortArray): Int {
if (!nativeAvailable) {
return 0
}
return pushAudioNative(samples)
}

/**
* Pull playback audio from LiveKit (remote participants).
* @param buffer Buffer to fill with 16-bit PCM samples
* @return Number of actual samples written (rest is silence)
*/
fun pullAudio(buffer: ShortArray): Int {
if (!nativeAvailable) {
return 0
}
return pullAudioNative(buffer)
}

external fun connect(url: String, token: String)
}
/**
* Get the number of samples available in the playback buffer.
* Useful for monitoring buffer health.
*/
fun getPlaybackBufferSize(): Int {
if (!nativeAvailable) {
return 0
}
return getPlaybackBufferSizeNative()
}

fun isNativeAvailable(): Boolean = nativeAvailable

private companion object {
private const val TAG = "LiveKitApp"
}
}
Loading
Loading