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 Show InstanceClientOptions properties
The URL of the ADB WebSocket endpoint
The URL of the main endpoint WebSocket
The token to use for the WebSocket connections
Path to the ADB executable
Controls logging verbosity. One of: 'none', 'error', 'warn', 'info', 'debug'
Maximum number of reconnection attempts
Initial reconnection delay in milliseconds
Maximum reconnection delay in milliseconds
Returns
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,...
Returns a promise that resolves to screenshot data Show ScreenshotData properties
Data URI containing the screenshot image (e.g., data:image/png;base64,...)
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 ();
Returns a promise that resolves to a Tunnel object address
{ address: string, port: number }
The local address and port for the ADB connection
Function to close the tunnel and cleanup resources
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 of the asset to send (e.g., APK file)
Resolves on success, rejects with an Error on failure
disconnect
Disconnect from the Limrun instance.
getConnectionState
Get the current connection state.
const state = client . getConnectionState ();
console . log ( state ); // 'connecting' | 'connected' | 'disconnected' | 'reconnecting'
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
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 ();