@mobilerun/react to add a
live, interactive Mobilerun cloud device to your React application.
The package provides:
DeviceStreamfor video, touch, keyboard input, and reconnectionNavigationBarfor Android Back, Home, and Recents controlsRemoteControlHandlefor actions such as opening a URL or taking a screenshot- A prebuilt stylesheet that you can customize with CSS variables
Keep the API key in your backend
The browser does not need the account API key. It only needs thestreamUrl 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
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
Render DeviceStream
Fetch the device credentials from your authenticated backend, then pass them
directly to the package component:
components/device-stream-panel.tsx
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. UseonConnectionStateChange for user-visible connection analytics:
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.
@mobilerun/react package repository.