
Embed live WebRTC device streams with remote input, per-connection token provider, reconnect/recovery, task approvals, optional Compose UI, default navigation and customizable theme.
Kotlin library for embedding Mobilerun device streams in Android apps.
Live WebRTC video, remote input and task approvals, with optional Compose UI.
Building Mobilerun phones into your platform? Start with the Partner guide. It walks through the API key, one phone per user, stream keys and live viewing step by step.
Configure Maven Central in settings.gradle.kts:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}Add the Compose SDK to your app module with group ai.mobilerun and version 0.1.0:
dependencies {
implementation("ai.mobilerun:mobilerun-stream-compose:0.1.0")
}For a View host, use ai.mobilerun:mobilerun-stream-android:0.1.0 instead.
See package and artifacts for module details and headless JVM use.
client.streamTokens.create. Follow the Partner guide.tokenProvider asks your server for a key before each connection.On your Node server, install @mobilerun/sdk@6.3.0 and keep MOBILERUN_API_KEY in the server environment.
Return a fresh key to the authorized app for every connection:
import { MobilerunSDK } from '@mobilerun/sdk';
// Node server only. Authenticate the user and authorize this device before minting.
const client = new MobilerunSDK({
apiKey: process.env.MOBILERUN_API_KEY,
maxRetries: 0,
});
const allowedOrigins = ['https://app.example.com']; // optional browser origin policy
const { key, keyId, expiresAt } = await client.streamTokens.create({
deviceId,
ttlSeconds: 120,
allowedOrigins,
});
res.writeHead(201, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
res.end(JSON.stringify({ key, keyId, expiresAt }));REST fallback: POST /v1/identity/stream-keys with bearer API-key authentication on the server.
In your app, backend below is your own client for that server:
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
val session = DeviceStreamSession(context, credentials = {
StreamCredentials(url = streamUrl, tokenProvider = { backend.mintStreamKey(deviceId) })
}, scope = scope)
session.start()
// Inside your composable:
StreamTheme { DeviceStream(session, Modifier.fillMaxSize()) }
// On screen disposal:
session.close(); scope.cancel()To react to failures, collect session.errors: each failed attempt reports a reason
(CredentialsUnavailable, TokenRejected, ConnectionRefused, Disconnected, …), its attempt
and final once retries stop. See Stream keys.
Every user-visible string comes from StreamLabels. The static StreamCredentials(url, token) form is legacy and deprecated: it reuses the same token on reconnect, so single-use keys need tokenProvider.
Never ship an API key in the app. Never cache keys or automatically retry mint requests. For the runnable sample, see TESTING.md.
Coding agents: use the Mobilerun device stream skill for Kotlin integration.
| Guide | Covers |
|---|---|
| Stream keys | Token provider, deadlines, secure URLs and legacy credentials |
| Package | Modules, supported API, configuration and Maven Central artifacts |
| Video and input | View and Compose hosts, touch, keyboard, IME and navigation |
| Default UI | Chrome, labels, themes and white-label slots |
| Task approvals | Backend callbacks, polling, decisions and approval cards |
| Lifecycle | Session ownership, visibility, network recovery and credentials |
| Statistics | Stream stats, benchmark and hardening checks |
See CONTRIBUTING.md for builds, tests, conformance fixtures and release guidance. Report vulnerabilities privately as described in SECURITY.md.
Apache-2.0. App distributors must also retain applicable dependency licenses and notices; see third-party notices.
Supply per-device StreamConfig(publishCapabilities = …) from your backend to enable optional local
microphone/camera injection. After host runtime permission and viewer connection,
session.startPublish(PublishOptions(audio = true, video = true)) returns when active;
session.stopPublish() releases capture without stopping viewing. Observe session.publishState
and publish errors through session.errors (operation == "publish"). Reconnect never resumes
capture. The default Compose UI includes a hideable, labelled microphone/camera pill.
See Publishing for permissions, capabilities, errors and UI options.
Kotlin library for embedding Mobilerun device streams in Android apps.
Live WebRTC video, remote input and task approvals, with optional Compose UI.
Building Mobilerun phones into your platform? Start with the Partner guide. It walks through the API key, one phone per user, stream keys and live viewing step by step.
Configure Maven Central in settings.gradle.kts:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}Add the Compose SDK to your app module with group ai.mobilerun and version 0.1.0:
dependencies {
implementation("ai.mobilerun:mobilerun-stream-compose:0.1.0")
}For a View host, use ai.mobilerun:mobilerun-stream-android:0.1.0 instead.
See package and artifacts for module details and headless JVM use.
client.streamTokens.create. Follow the Partner guide.tokenProvider asks your server for a key before each connection.On your Node server, install @mobilerun/sdk@6.3.0 and keep MOBILERUN_API_KEY in the server environment.
Return a fresh key to the authorized app for every connection:
import { MobilerunSDK } from '@mobilerun/sdk';
// Node server only. Authenticate the user and authorize this device before minting.
const client = new MobilerunSDK({
apiKey: process.env.MOBILERUN_API_KEY,
maxRetries: 0,
});
const allowedOrigins = ['https://app.example.com']; // optional browser origin policy
const { key, keyId, expiresAt } = await client.streamTokens.create({
deviceId,
ttlSeconds: 120,
allowedOrigins,
});
res.writeHead(201, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
res.end(JSON.stringify({ key, keyId, expiresAt }));REST fallback: POST /v1/identity/stream-keys with bearer API-key authentication on the server.
In your app, backend below is your own client for that server:
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
val session = DeviceStreamSession(context, credentials = {
StreamCredentials(url = streamUrl, tokenProvider = { backend.mintStreamKey(deviceId) })
}, scope = scope)
session.start()
// Inside your composable:
StreamTheme { DeviceStream(session, Modifier.fillMaxSize()) }
// On screen disposal:
session.close(); scope.cancel()To react to failures, collect session.errors: each failed attempt reports a reason
(CredentialsUnavailable, TokenRejected, ConnectionRefused, Disconnected, …), its attempt
and final once retries stop. See Stream keys.
Every user-visible string comes from StreamLabels. The static StreamCredentials(url, token) form is legacy and deprecated: it reuses the same token on reconnect, so single-use keys need tokenProvider.
Never ship an API key in the app. Never cache keys or automatically retry mint requests. For the runnable sample, see TESTING.md.
Coding agents: use the Mobilerun device stream skill for Kotlin integration.
| Guide | Covers |
|---|---|
| Stream keys | Token provider, deadlines, secure URLs and legacy credentials |
| Package | Modules, supported API, configuration and Maven Central artifacts |
| Video and input | View and Compose hosts, touch, keyboard, IME and navigation |
| Default UI | Chrome, labels, themes and white-label slots |
| Task approvals | Backend callbacks, polling, decisions and approval cards |
| Lifecycle | Session ownership, visibility, network recovery and credentials |
| Statistics | Stream stats, benchmark and hardening checks |
See CONTRIBUTING.md for builds, tests, conformance fixtures and release guidance. Report vulnerabilities privately as described in SECURITY.md.
Apache-2.0. App distributors must also retain applicable dependency licenses and notices; see third-party notices.
Supply per-device StreamConfig(publishCapabilities = …) from your backend to enable optional local
microphone/camera injection. After host runtime permission and viewer connection,
session.startPublish(PublishOptions(audio = true, video = true)) returns when active;
session.stopPublish() releases capture without stopping viewing. Observe session.publishState
and publish errors through session.errors (operation == "publish"). Reconnect never resumes
capture. The default Compose UI includes a hideable, labelled microphone/camera pill.
See Publishing for permissions, capabilities, errors and UI options.