Skip to main content

mobilerun_flutter 0.1.0 copy "mobilerun_flutter: ^0.1.0" to clipboard
mobilerun_flutter: ^0.1.0 copied to clipboard

Flutter package for embedding Mobilerun device streaming, remote input and task approvals.

Mobilerun

mobilerun-flutter

Embed Mobilerun device streaming and remote input in your Flutter app.
Live WebRTC video, touch and keyboard control, task approvals and optional UI for Android and iOS.

Building Mobilerun phones into your platform? Start with the Partner guide. It walks through the API key, one phone per user, stream tokens and live viewing step by step.

Flutter sample with live device video and remote controls In this package
  • DeviceStreamSession โ€” connection, recovery and screenshots.
  • DeviceStream โ€” video with status overlays and navigation.
  • DeviceStreamView โ€” video and input for your own UI.
  • DeviceStreamController โ€” keyboard and system-key controls.
  • StreamCredentials โ€” stream target and token provider.
  • StreamLifecycle โ€” app visibility and network recovery.
  • TaskApprovalController โ€” approval fetching and decisions.
  • TaskApprovalCard โ€” approval details and action buttons.
  • StreamTheme and labels โ€” styling and localization.
  • StreamStats โ€” connection and video statistics.
Requirements
  • Android API 24+ or iOS 13+; the example targets iOS 15+.
  • Flutter 3.47.9+ with Dart 3.13.7+.
  • A Mobilerun API key on your server.

Install #

Add the pub.dev package to your Flutter app's pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  mobilerun_flutter: ^0.1.0

Run flutter pub get, then import package:mobilerun_flutter/mobilerun_flutter.dart.

The host Android app needs <uses-permission android:name="android.permission.INTERNET" /> in android/app/src/main/AndroidManifest.xml, including release builds. Set uses-material-design: true under flutter: in the host's pubspec.yaml for the default UI icons.

Quick start #

  1. Your server mints a short-lived stream token for one device with your API key with client.streamTokens.create(...). Follow the Partner guide.
  2. Your app's tokenProvider asks your server for a stream token before each connection.
  3. The SDK opens the stream with that stream token, one token per connection, and reconnects with a fresh one.

On your Node server, install @mobilerun/[email protected] and mint with MOBILERUN_API_KEY from the server environment (never ship it in the app). Authenticate your user and check they own the device first:

import { MobilerunSDK } from '@mobilerun/sdk';

const client = new MobilerunSDK({
  apiKey: process.env.MOBILERUN_API_KEY,
});

// Authenticate your user and authorize this device before calling.
async function mintStreamToken(authorizedDeviceId, allowedOrigins) {
  const { key, keyId, expiresAt } = await client.streamTokens.create({
    deviceId: authorizedDeviceId,
    ttlSeconds: 120,
    allowedOrigins, // Optional server-owned policy for browser embeds.
  }, { maxRetries: 0 });
  // Keep keyId/expiry on the server if needed; return only the fresh key.
  return key;
}

The SDK returns {key, keyId, expiresAt}. Omit allowedOrigins for native-only apps; set it to your permitted site origins for browser embeds. REST fallback: POST https://api.mobilerun.ai/v1/identity/stream-keys with the same request fields.

In your app, using your backend client and the device's stream URL: The default connectivity seed is asynchronous. Attach the lifecycle before start(); to guarantee no provider call on a launch known to be offline, seed availability from your own snapshot before starting. This example uses connectivity_plus for that snapshot: declare it in the host app and import package:connectivity_plus/connectivity_plus.dart.

final session = DeviceStreamSession(
  credentials: () async => StreamCredentials(
    url: streamUrl,
    // Called before every connection, including each reconnect.
    tokenProvider: () => backend.mintStreamToken(deviceId),
  ),
  onError: (error) =>
      debugPrint('stream ${error.reason.code} attempt ${error.attempt}'),
);
final routes = await Connectivity().checkConnectivity();
session.setNetworkAvailable(routes.any((route) => route != ConnectivityResult.none));
final lifecycle = StreamLifecycle(session: session);
session.start();
// Inside a bounded area, such as Expanded:
DeviceStream(
  session: session,
  observeLifecycle: false, // The adapter above owns observation.
  labels: const StreamLabels(unavailable: 'Phone offline', retry: 'Try again'),
);
// When finished: lifecycle.dispose(); await session.close();

onError reasons are credentials_unavailable, connection_refused, token_rejected (HTTP 401 on connect), disconnected and unknown; isFinal is true when the SDK stopped retrying, including a failed attempt waiting offline.

Credential modes. tokenProvider is the recommended path: one fresh stream token per connection. The static StreamCredentials.token is a device token (legacy), deprecated until its hard cut. It is an explicit exception: a reconnect reuses the same static token (the SDK logs one deprecation warning per session). That works for a long-lived token, but a single-use stream token is rejected on the second connect, so single-use stream tokens need tokenProvider.

Microphone and camera publish #

Supply StreamConfig(publishCapabilities: ...) from your backend's per-device capabilities response before connecting. DeviceStream then shows a floating microphone/camera pill over the video; hide it with showPublishControls: false. The snapshot describes device support; the server still decides each request.

// After the viewer connects, from an explicit user action:
try {
  await session.startPublish(const PublishOptions(audio: true, video: true));
} on PublishException catch (error) {
  debugPrint(error.failure.reason.code);
}
// Observe session.publishState (ValueListenable<PublishState>).
await session.stopPublish(); // Viewing and output mute are independent.

Inputs open only after server acceptance; refused or silent requests never prompt. Audio is required. Stop before changing input kinds; reconnect never resumes capture. Publish errors use the existing onError with operation == 'publish'. See publish setup and lifecycle for permissions, labels, capability delivery, supported codecs and failure details.

Guides #

Coding agents: use the device stream integration skill.

Guide Covers
Stream tokens Single-use stream tokens, deadlines, retries, onError reasons and legacy credentials.
Video and input Touch, keyboard, host back, URLs and screenshots.
Default UI Navigation, overlays, custom builders, themes and labels.
Task approvals Backend callbacks, polling, decisions and card customization.
Session and lifecycle Status, codecs, credentials, visibility and network recovery.
Statistics Stats fields, sampling and the benchmark procedure.

Contributing #

See CONTRIBUTING.md for building, tests, conformance fixtures, the example app and releases. Report vulnerabilities privately through SECURITY.md.

License #

Apache-2.0. See third-party notices for flutter_webrtc and its native WebRTC dependencies, including app redistribution requirements.

0
likes
150
points
69
downloads

Documentation

API reference

Publisher

verified publishermobilerun.ai

Weekly Downloads

Flutter package for embedding Mobilerun device streaming, remote input and task approvals.

Repository (GitHub)
View/report issues
Contributing

Topics

#streaming #webrtc #android #remote-control

License

Apache-2.0 (license)

Dependencies

connectivity_plus, flutter, flutter_webrtc, web_socket_channel

More

Packages that depend on mobilerun_flutter