SDK Configuration
Configure the Portal SDK for your specific needs.
Basic Configuration
const client = new PortalSDK({
serverUrl: 'ws://localhost:3000/ws',
connectTimeout: 10000
});
Create PortalSDK with health and WebSocket endpoints: new PortalSDK(healthEndpoint, wsEndpoint). Call connect(authToken) to connect and authenticate.
Configuration Options
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
});
Pass health URL, WebSocket URL, and (for connect) auth token from environment or config.
Environment-Based Configuration
const config = {
serverUrl: process.env.PORTAL_WS_URL || 'ws://localhost:3000/ws',
connectTimeout: parseInt(process.env.PORTAL_TIMEOUT || '10000')
};
const client = new PortalSDK(config);
Handle responses and errors in the sendCommand(request, (response, err) -> { ... }) callback.
Event Configuration
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();
Handle responses and errors in sendCommand(request, (response, err) -> { ... }).
Next: Error Handling