Connection Management

Note: In the SDK Playground, connection is automatic - you don't need these methods. They are only required when using a standalone client or when connecting to additional appliances from your code.

connect(robotId, token, options)

JavaScript:

JS
await oloClient.connect(robotId, token, options)

Python:

Connect to an appliance via WebSocket using an authenticated token.

JavaScript Parameters:

  • robotId (string) - Appliance identifier from getUserRobots()
  • token (string) - Authentication token from authenticate() or getAuthToken()
  • options (object, optional) - Connection options
    • serverUrl (string) - Custom WebSocket server URL
    • onConnect (function) - Callback when connected
    • onDisconnect (function) - Callback when disconnected
    • onError (function) - Callback for errors

Python Parameters:

  • robot_id (string) - Appliance identifier from get_user_robots()
  • token (string) - Authentication token from authenticate() or get_auth_token()
  • server_host (string) - Server hostname (default: 'localhost')
  • server_port (int) - Server port (default: 3000)
  • use_ssl (bool) - Use WSS instead of WS (default: False)

Returns: Promise<boolean> - True if connection successful

Example:

JS
// After authentication const appliances = await oloClient.getUserRobots(); const appliance = appliances[0]; // Connect to appliance await oloClient.connect(appliance.id, oloClient.getAuthToken()); console.log('Connected to appliance!');

disconnect()

Disconnect from appliance and clean up resources.

JS
oloClient.disconnect(); console.log('Disconnected from appliance');

getConnectionStatus()

Get current connection status.

Returns: boolean - True if connected

JS
const isConnected = oloClient.getConnectionStatus(); console.log('Connection status:', isConnected);