WebsocketConfig

data class WebsocketConfig(val url: String, val port: Int? = null, val isSecure: Boolean = true, val authenticationToken: String? = null)

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:

  • localhost does NOT work - it refers to the device/emulator itself

  • Use 10.0.2.2 for Android Emulator (maps to host machine's 127.0.0.1)

  • Use 10.0.3.2 for Genymotion Emulator

  • Use your machine's local IP (e.g., 192.168.1.100) for physical devices

iOS:

  • localhost does NOT work - it refers to the simulator/device itself

  • Use your machine's local IP (e.g., 192.168.1.100) for both simulator and physical devices

  • Run ipconfig getifaddr en0 (macOS) to get your local IP

Desktop/JVM:

  • localhost works 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)

Constructors

Link copied to clipboard
constructor(url: String, port: Int? = null, isSecure: Boolean = true, authenticationToken: String? = null)

Properties

Link copied to clipboard

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.

Link copied to clipboard

Whether to use secure protocol (wss/https) or not (ws/http). Defaults to true. Only used if URL doesn't specify protocol.

Link copied to clipboard
val port: Int?

Optional port number for development. Ignored if URL contains port or path.

Link copied to clipboard

Builds the HTTP URL for POST requests. Handles both production URLs (with protocol) and development hostnames.

Link copied to clipboard
val url: String

WebSocket URL (production: full URL like "wss://api.example.com", development: hostname like "localhost" (Desktop only) or IP address)

Link copied to clipboard

Builds the websocket connection URL. Handles both production URLs (with protocol) and development hostnames.