Skip to main content
The Instance Client provides methods to connect to and interact with Limrun Android instances.

createInstanceClient

Creates a client for interacting with a Limrun Android instance.
import { createInstanceClient } from '@limrun/client';

const client = await createInstanceClient({
  adbUrl: 'wss://instance.limrun.com/adb',
  endpointUrl: 'wss://instance.limrun.com/endpoint',
  token: 'your-token',
  logLevel: 'info'
});

Parameters

options
InstanceClientOptions
required
Configuration options for the instance client

Returns

client
Promise<InstanceClient>
A promise that resolves to an InstanceClient instance

InstanceClient

The client interface for interacting with a Limrun instance.

Methods

screenshot

Take a screenshot of the current screen.
const screenshot = await client.screenshot();
console.log(screenshot.dataUri); // data:image/png;base64,...
screenshot
Promise<ScreenshotData>
Returns a promise that resolves to screenshot data

startAdbTunnel

Establish an ADB tunnel to the instance. Returns the local TCP port and a cleanup function.
const tunnel = await client.startAdbTunnel();
console.log(`ADB connected on ${tunnel.address.address}:${tunnel.address.port}`);

// When done, close the tunnel
tunnel.close();
tunnel
Promise<Tunnel>
Returns a promise that resolves to a Tunnel object

sendAsset

Send an asset URL to the instance. The instance will download the asset and process it (currently APK install is supported).
await client.sendAsset('https://example.com/app.apk');
console.log('APK installation started');
url
string
required
URL of the asset to send (e.g., APK file)
result
Promise<void>
Resolves on success, rejects with an Error on failure

disconnect

Disconnect from the Limrun instance.
client.disconnect();

getConnectionState

Get the current connection state.
const state = client.getConnectionState();
console.log(state); // 'connecting' | 'connected' | 'disconnected' | 'reconnecting'
state
ConnectionState
One of: 'connecting', 'connected', 'disconnected', 'reconnecting'

onConnectionStateChange

Register a callback for connection state changes.
const unsubscribe = client.onConnectionStateChange((state) => {
  console.log('Connection state changed:', state);
});

// Later, to unregister:
unsubscribe();
callback
ConnectionStateCallback
required
Callback function that receives the new connection state
unsubscribe
() => void
Function to unregister the callback

Types

ConnectionState

type ConnectionState = 'connecting' | 'connected' | 'disconnected' | 'reconnecting';
Represents the current connection state of the instance client.

ConnectionStateCallback

type ConnectionStateCallback = (state: ConnectionState) => void;
Callback function for connection state changes.

LogLevel

type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'debug';
Controls the verbosity of logging in the client.

Example Usage

import { createInstanceClient } from '@limrun/client';

// Create the client
const client = await createInstanceClient({
  adbUrl: 'wss://instance.limrun.com/adb',
  endpointUrl: 'wss://instance.limrun.com/endpoint',
  token: 'your-token',
  logLevel: 'info'
});

// Monitor connection state
client.onConnectionStateChange((state) => {
  console.log('Connection state:', state);
});

// Take a screenshot
const screenshot = await client.screenshot();
console.log('Screenshot captured:', screenshot.dataUri);

// Start ADB tunnel
const tunnel = await client.startAdbTunnel();
console.log(`ADB available at ${tunnel.address.address}:${tunnel.address.port}`);

// Install an APK
await client.sendAsset('https://example.com/app.apk');
console.log('APK installed');

// Cleanup
tunnel.close();
client.disconnect();

Build docs developers (and LLMs) love