-
public final class WebRTCConnection extends BaseConnection
WebRTC implementation using LiveKit for real-time communication
This class manages room-based architecture for connections, data channels for event messaging, audio tracks for voice communication, and automatic reconnection handling.
-
-
Field Summary
Fields Modifier and Type Field Description private final ConnectionStateconnectionStateprivate final StateFlow<Float>audioLevel
-
Constructor Summary
Constructors Constructor Description WebRTCConnection(Context context, Room room, CoroutineScope scope)
-
Method Summary
Modifier and Type Method Description ConnectionStategetConnectionState()final StateFlow<Float>getAudioLevel()Unitconnect(String serverUrl, ConversationConfig config)Connect to LiveKit room using the WebRTC token from config and the given server URL. Unitdisconnect(DisconnectionDetails details)Disconnect from the room and clean up resources UnitsendMessage(Object message)Send a message through the data channel UnitsetOnMessageListener(Function1<String, Unit> listener)Set listener for incoming messages UnitsetOnConnectionStateListener(Function1<ConnectionState, Unit> listener)Set listener for connection state changes final Unitcleanup()Clean up resources when the connection is no longer needed -
-
Constructor Detail
-
WebRTCConnection
WebRTCConnection(Context context, Room room, CoroutineScope scope)
-
-
Method Detail
-
getConnectionState
ConnectionState getConnectionState()
-
getAudioLevel
final StateFlow<Float> getAudioLevel()
-
connect
Unit connect(String serverUrl, ConversationConfig config)
Connect to LiveKit room using the WebRTC token from config and the given server URL.
- Parameters:
serverUrl- URL of the server to connect toconfig- Conversation configuration
-
disconnect
Unit disconnect(DisconnectionDetails details)
Disconnect from the room and clean up resources
- Parameters:
details- Optional disconnection details.
-
sendMessage
Unit sendMessage(Object message)
Send a message through the data channel
- Parameters:
message- The message to send (will be serialized as needed)
-
setOnMessageListener
Unit setOnMessageListener(Function1<String, Unit> listener)
Set listener for incoming messages
- Parameters:
listener- Callback that receives incoming message strings
-
setOnConnectionStateListener
Unit setOnConnectionStateListener(Function1<ConnectionState, Unit> listener)
Set listener for connection state changes
- Parameters:
listener- Callback that receives connection state updates
-
-
-
-