-
public abstract class BaseConnectionAbstract base class for network connections
This provides a common interface for different transport types (WebRTC, WebSocket) while supporting event-driven architecture with observable state.
-
-
Field Summary
Fields Modifier and Type Field Description private final ConnectionStateconnectionState
-
Constructor Summary
Constructors Constructor Description BaseConnection()
-
Method Summary
Modifier and Type Method Description abstract ConnectionStategetConnectionState()Get the current connection state abstract Unitconnect(String serverUrl, ConversationConfig config)Establish a connection. abstract Unitdisconnect(DisconnectionDetails details)Disconnect from the server and clean up resources abstract UnitsendMessage(Object message)Send a message through the connection abstract UnitsetOnMessageListener(Function1<String, Unit> listener)Set a listener for incoming messages abstract UnitsetOnConnectionStateListener(Function1<ConnectionState, Unit> listener)Set a listener for connection state changes -
-
Method Detail
-
getConnectionState
abstract ConnectionState getConnectionState()
Get the current connection state
-
connect
abstract Unit connect(String serverUrl, ConversationConfig config)
Establish a connection. Each transport reads its own credential from config: WebRTC uses ConversationConfig.conversationToken, WebSocket uses ConversationConfig.signedUrl (or builds a public-agent URL from ConversationConfig.agentId).
- Parameters:
serverUrl- URL of the server to connect toconfig- Conversation configuration
-
disconnect
abstract Unit disconnect(DisconnectionDetails details)
Disconnect from the server and clean up resources
- Parameters:
details- Optional details about why the disconnection occurred.
-
sendMessage
abstract Unit sendMessage(Object message)
Send a message through the connection
- Parameters:
message- The message to send (will be serialized as needed)
-
setOnMessageListener
abstract Unit setOnMessageListener(Function1<String, Unit> listener)
Set a listener for incoming messages
- Parameters:
listener- Callback that receives incoming message strings
-
setOnConnectionStateListener
abstract Unit setOnConnectionStateListener(Function1<ConnectionState, Unit> listener)
Set a listener for connection state changes
- Parameters:
listener- Callback that receives connection state updates
-
-
-
-