WebSocketClient

class WebSocketClient(apiKey: String, connect: PortalConnect, webSocketServer: String = "connect.portalhq.io")

WebSocketClient is responsible for managing a WebSocket connection to a remote server, handling events, and sending/receiving messages.

Constructors

Link copied to clipboard
constructor(apiKey: String, connect: PortalConnect, webSocketServer: String = "connect.portalhq.io")

Properties

Link copied to clipboard

Checks if the WebSocket client is currently connected or in the process of connecting.

Link copied to clipboard

The current topic associated with the WebSocket session.

Functions

Link copied to clipboard
fun close()

Closes the WebSocket connection and updates the connection state.

Link copied to clipboard
fun connect(uri: String)

Establishes a WebSocket connection to the specified URI.

Link copied to clipboard
fun disconnect(topic: String?, userInitiated: Boolean = false)

Disconnects the WebSocket client, optionally specifying whether the disconnection was user-initiated.

Link copied to clipboard
suspend fun emit(event: String, data: WebSocketMessageData?)

Emits an event with the given name and associated data to registered handlers.

Link copied to clipboard
fun off(event: String)

Unregisters all event handlers for a specified event.

Link copied to clipboard
fun on(event: String, handler: RegisteredEventHandler)

Registers an event handler for a specified event.

Link copied to clipboard
fun send(message: String)

Sends a message over the WebSocket connection.

Link copied to clipboard

Sends a final message before disconnecting the WebSocket client.