Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SDK Configuration

Configure the Portal SDK for your specific needs.

Basic Configuration

JavaScript
const client = new PortalSDK({
  serverUrl: 'ws://localhost:3000/ws',
  connectTimeout: 10000
});
Java

Create PortalSDK with health and WebSocket endpoints: new PortalSDK(healthEndpoint, wsEndpoint). Call connect(authToken) to connect and authenticate.

Configuration Options

JavaScript

serverUrl (required)

The Portal endpoint URL (where Portal is running—e.g. your hosted URL or local Docker).

// Local development (e.g. Docker)
serverUrl: 'ws://localhost:3000/ws'

// Production (hosted Portal)
serverUrl: 'wss://portal.yourdomain.com/ws'

connectTimeout (optional)

Connection timeout in milliseconds. Default: 10000 (10 seconds)

connectTimeout: 5000  // 5 seconds

debug (optional)

When true, the SDK logs requests and responses to the console (via console.debug). Useful for development. Default: false.

const client = new PortalSDK({
  serverUrl: 'ws://localhost:3000/ws',
  debug: true
});
Java

Pass health URL, WebSocket URL, and (for connect) auth token from environment or config.

Environment-Based Configuration

JavaScript
const config = {
  serverUrl: process.env.PORTAL_WS_URL || 'ws://localhost:3000/ws',
  connectTimeout: parseInt(process.env.PORTAL_TIMEOUT || '10000')
};

const client = new PortalSDK(config);
Java

Handle responses and errors in the sendCommand(request, (response, err) -> { ... }) callback.

Event Configuration

JavaScript

Set up event listeners during initialization:

const client = new PortalSDK({ serverUrl: 'ws://localhost:3000/ws' });

client.on({
  onConnected: () => console.log('Connected'),
  onDisconnected: () => console.log('Disconnected'),
  onError: (error) => console.error('Error:', error)
});

await client.connect();
Java

Handle responses and errors in sendCommand(request, (response, err) -> { ... }).


Next: Error Handling