Skip to main content
Use @mobilerun/react to add a live, interactive Mobilerun cloud device to your React application. The package provides:
  • DeviceStream for video, touch, keyboard input, and reconnection
  • NavigationBar for Android Back, Home, and Recents controls
  • RemoteControlHandle for actions such as opening a URL or taking a screenshot
  • A prebuilt stylesheet that you can customize with CSS variables
Your application provides the surrounding layout, branding, loading states, and access control.

Keep the API key in your backend

MOBILERUN_CLOUD_API_KEY is an account-level secret. Never include it in browser code, public environment variables, or a client-side SDK instance.In a multi-user application, your backend must authenticate the current user and verify that the user may access the requested device before returning stream credentials.
The browser does not need the account API key. It only needs the streamUrl and streamToken for the selected device: The stream token is device-scoped, but it is still sensitive. Do not store it in local storage or send it to logs, analytics, traces, or error-reporting tools.

Install

Import the package stylesheet once in your application:
app/layout.tsx

Create a backend credentials endpoint

The following Next.js route uses @mobilerun/sdk only on the server. Replace the example authentication imports with your application’s own authorization layer.
app/api/device-stream/[deviceId]/route.ts
This endpoint returns only the fields required by the stream. It does not expose the account API key or the full device response.

Render DeviceStream

Fetch the device credentials from your authenticated backend, then pass them directly to the package component:
components/device-stream-panel.tsx
If a device is still starting, streamUrl may be empty. The second effect polls the backend every three seconds until it becomes available. onStreamHealed also retrieves the current credentials after a stable disconnect. NavigationBar stays below the stream and provides Android Back, Home, and Recents. The hasControl prop controls direct interaction with the device screen; it does not disable NavigationBar or provide an authorization boundary. Anyone who receives stream credentials must be authorized to control that device. If your UI includes a view-only mode, also guard the onAction callback and treat that as a UI affordance, not a security control. The stream starts muted so browser autoplay policies do not block it; only unmute after a user action.

Customize the appearance

DeviceStream does not add Mobilerun logos or application chrome. Style its parent and override the package CSS variables to match your product:
app/globals.css

Observe the integration safely

Instrument the backend credentials request with your existing OpenTelemetry setup. Record the device ID, device state, and upstream status, but never credentials. Use onConnectionStateChange for user-visible connection analytics:
Do not include streamUrl, streamToken, or MOBILERUN_CLOUD_API_KEY in PostHog events.

Production checklist

  • The account API key is used only by backend code.
  • Every credentials request requires an authenticated application session.
  • Your backend verifies that the current user may access the requested device.
  • Credential responses use Cache-Control: no-store.
  • Stream credentials are excluded from logs, traces, analytics, and error reports.
  • Interactive control is enabled only for authorized users.
For all exported components and the local playground, see the @mobilerun/react package repository.