WebsocketConfig
Configuration for WebSocket connections.
Production Usage (Recommended)
Just provide the complete WebSocket URL:
val config = WebsocketConfig(url = "wss://api.example.com/mpc")With Authentication
val config = WebsocketConfig(
url = "wss://api.example.com/mpc",
authenticationToken = "your_api_token"
)Development/Testing Usage
For local testing or debugging, specify hostname with port and security:
// Desktop/JVM - localhost works
val config = WebsocketConfig(
url = "localhost",
port = 8080,
isSecure = false
)
// Android/iOS - Use IP address instead of localhost
val config = WebsocketConfig(
url = "10.0.2.2", // Android emulator host machine
port = 8080,
isSecure = false
)
// or
val config = WebsocketConfig(
url = "192.168.1.100", // Your machine's local IP
port = 8080,
isSecure = false
)Platform-Specific Notes
Android:
localhostdoes NOT work - it refers to the device/emulator itselfUse
10.0.2.2for Android Emulator (maps to host machine's 127.0.0.1)Use
10.0.3.2for Genymotion EmulatorUse your machine's local IP (e.g.,
192.168.1.100) for physical devices
iOS:
localhostdoes NOT work - it refers to the simulator/device itselfUse your machine's local IP (e.g.,
192.168.1.100) for both simulator and physical devicesRun
ipconfig getifaddr en0(macOS) to get your local IP
Desktop/JVM:
localhostworks as expected
Examples
// Production - Full URL (all platforms)
WebsocketConfig(url = "wss://mpc.example.com")
WebsocketConfig(url = "wss://mpc.example.com/v1/duo")
// Production - With authentication
WebsocketConfig(
url = "wss://mpc.example.com",
authenticationToken = "your_jwt_token"
)
// Development - Desktop/JVM
WebsocketConfig(url = "localhost", port = 8080, isSecure = false)
// Development - Android Emulator
WebsocketConfig(url = "10.0.2.2", port = 8080, isSecure = false)
// Development - Android Physical Device or iOS (any)
WebsocketConfig(url = "192.168.1.100", port = 8080, isSecure = false)Properties
Optional authentication token sent after WebSocket connection. Commonly used for JWT tokens, API keys, or session tokens. The token is sent as the first message after connection establishment.
Builds the HTTP URL for POST requests. Handles both production URLs (with protocol) and development hostnames.
Builds the websocket connection URL. Handles both production URLs (with protocol) and development hostnames.