Kotlin SDK API Reference
Complete API reference for the BaxCloud Kotlin SDK (Android)
Table of Contents
Installation
Gradle Setup
Add the BaxCloud SDK to your Android project
Add to build.gradle.kts
1dependencies {
2 implementation("com.baxcloud:client:1.0.0")
3}All required dependencies are bundled with the SDK.
Android Permissions
Required permissions for camera and audio
AndroidManifest.xml
1<uses-permission android:name="android.permission.CAMERA" />
2<uses-permission android:name="android.permission.RECORD_AUDIO" />
3<uses-permission android:name="android.permission.INTERNET" />Runtime Permissions (Android 6.0+)
1import android.Manifest
2import android.content.pm.PackageManager
3import androidx.core.app.ActivityCompat
4import androidx.core.content.ContextCompat
5
6fun requestPermissions(activity: Activity) {
7 val permissions = arrayOf(
8 Manifest.permission.CAMERA,
9 Manifest.permission.RECORD_AUDIO
10 )
11
12 if (permissions.any {
13 ContextCompat.checkSelfPermission(activity, it) != PackageManager.PERMISSION_GRANTED
14 }) {
15 ActivityCompat.requestPermissions(activity, permissions, REQUEST_CODE)
16 }
17}BaxCloudClient
Constructor
Initialize the BaxCloud client
BaxCloudClient(
context: Context,
config: BaxCloudConfig
)Parameters
context(Context) - Android application contextconfig.projectId(String) - Your BaxCloud project IDconfig.apiKey(String) - Your BaxCloud API key
Example
1import com.baxcloud.client.BaxCloudClient
2import com.baxcloud.client.BaxCloudConfig
3
4val client = BaxCloudClient(
5 context = applicationContext,
6 config = BaxCloudConfig(
7 projectId = "your-project-id",
8 apiKey = "your-api-key"
9 )
10)Properties
room
val room: Room?Gets the current active Room instance. The Room type is internal to the SDK.
connectionState
val connectionState: StateFlow<BaxCloudConnectionState>StateFlow of connection state changes.
Room Management
createRoom
Create a new room
suspend fun createRoom(options: BaxcloudCreateRoomOptions): BaxcloudRoomInfoParameters
options.roomName(String) - Unique room nameoptions.liveType(BaxcloudLiveType) - Type of live sessionoptions.maxParticipants(Int?, optional) - Maximum participants
Example
1lifecycleScope.launch {
2 val room = client.createRoom(
3 BaxcloudCreateRoomOptions(
4 roomName = "meeting-123",
5 liveType = BaxcloudLiveType.VIDEO_CONFERENCE,
6 maxParticipants = 50
7 )
8 )
9 println("Room created: ${room.roomName}")
10}deleteRoom
Delete a room
suspend fun deleteRoom(roomName: String)Example
lifecycleScope.launch {
client.deleteRoom("meeting-123")
}listRooms
List all rooms in the project
suspend fun listRooms(): List<BaxcloudRoomInfo>Example
lifecycleScope.launch {
val rooms = client.listRooms()
println("Total rooms: ${rooms.size}")
}getRoom
Get information about a specific room
suspend fun getRoom(roomName: String): BaxcloudRoomInfoExample
lifecycleScope.launch {
val room = client.getRoom("meeting-123")
println("Room info: $room")
}getToken
Get an access token for joining a room
suspend fun getToken(options: BaxcloudRoomOptions): BaxcloudTokenResponseParameters
options.roomName(String) - Room nameoptions.participant(BaxcloudUser) - Participant informationoptions.liveType(BaxcloudLiveType) - Type of live sessionoptions.canJoinWithNoHost(Boolean?, optional) - Allow joining without host (default: true)
Example
1lifecycleScope.launch {
2 val token = client.getToken(
3 BaxcloudRoomOptions(
4 roomName = "meeting-123",
5 participant = BaxcloudUser(
6 userId = "user-1",
7 name = "Alice",
8 avatarUrl = "https://example.com/avatar.jpg",
9 isHost = true
10 ),
11 liveType = BaxcloudLiveType.VIDEO_CONFERENCE
12 )
13 )
14 println("Access token: ${token.token}")
15}Connection Methods
connect
Connect to a room
suspend fun connect(options: BaxcloudRoomOptions): RoomExample
1lifecycleScope.launch {
2 try {
3 val room = client.connect(
4 BaxcloudRoomOptions(
5 roomName = "my-room",
6 participant = BaxcloudUser(
7 userId = "user-123",
8 name = "John Doe",
9 avatarUrl = "https://example.com/avatar.jpg",
10 isHost = true
11 ),
12 liveType = BaxcloudLiveType.VIDEO_CALL,
13 canJoinWithNoHost = true
14 )
15 )
16 println("Connected to room: ${room.name}")
17 } catch (e: Exception) {
18 println("Connection failed: ${e.message}")
19 }
20}disconnect
Disconnect from the current room
suspend fun disconnect()Example
lifecycleScope.launch {
client.disconnect()
println("Disconnected from room")
}Media Controls
enableCamera
suspend fun enableCamera()disableCamera
suspend fun disableCamera()enableMicrophone
suspend fun enableMicrophone()disableMicrophone
suspend fun disableMicrophone()enableScreenShare
suspend fun enableScreenShare()disableScreenShare
suspend fun disableScreenShare()Messaging
sendRealtimeMessage
Send a real-time message to the room
suspend fun sendRealtimeMessage(options: BaxcloudSendRealtimeMessageOptions)Example
lifecycleScope.launch {
client.sendRealtimeMessage(
BaxcloudSendRealtimeMessageOptions(
roomName = "meeting-123",
message = "Hello everyone!",
sender = BaxcloudUser(
userId = "user-1",
name = "Alice"
)
)
)
}Observing Connection State
StateFlow Collection
Monitor connection state changes
1import kotlinx.coroutines.flow.collect
2import kotlinx.coroutines.launch
3
4lifecycleScope.launch {
5 client.connectionState.collect { state ->
6 when (state) {
7 BaxCloudConnectionState.CONNECTING -> {
8 // Show loading indicator
9 }
10 BaxCloudConnectionState.CONNECTED -> {
11 // Hide loading, show room UI
12 }
13 BaxCloudConnectionState.DISCONNECTED -> {
14 // Show disconnected state
15 }
16 BaxCloudConnectionState.RECONNECTING -> {
17 // Show reconnecting indicator
18 }
19 BaxCloudConnectionState.FAILED -> {
20 // Show error message
21 }
22 }
23 }
24}Recording APIs
startRecording
Start recording a room
suspend fun startRecording(options: BaxcloudStartRecordingOptions): BaxcloudRecordingInfoParameters
options.roomName(String) - Room name to recordoptions.filepath(String?, optional) - Custom file path for the recordingoptions.fileType(String?, optional) - Recording file type ('MP4' | 'OGG' | 'WEBM', default: 'MP4')
Example
1lifecycleScope.launch {
2 val recording = client.startRecording(
3 BaxcloudStartRecordingOptions(
4 roomName = "my-room",
5 fileType = "MP4"
6 )
7 )
8 println("Recording started: ${recording.egressId}")
9}Note: Recording events (recording.started, recording.completed, recording.failed) are automatically sent to your configured webhooks in the dashboard if webhooks are enabled for your project.
stopRecording
Stop an active recording
suspend fun stopRecording(egressId: String): Map<String, Any>Parameters
egressId(String) - Recording egress ID from startRecording() response
Example
lifecycleScope.launch {
client.stopRecording(recording.egressId)
println("Recording stopped")
}listActiveRecordings
List all active recordings/egresses
suspend fun listActiveRecordings(roomName: String? = null): List<BaxcloudRecordingInfo>Parameters
roomName(String?, optional) - Filter by specific room name
Example
1lifecycleScope.launch {
2 // List all active recordings
3 val activeRecordings = client.listActiveRecordings()
4
5 // List active recordings for a specific room
6 val roomRecordings = client.listActiveRecordings("my-room")
7}listRecordings
List all recordings with pagination support
suspend fun listRecordings(options: BaxcloudListRecordingsOptions? = null): BaxcloudRecordingListResponseParameters
options.status(String?, optional) - Filter by status ('STARTED' | 'COMPLETED' | 'FAILED')options.page(Int?, optional) - Page number (default: 1)options.limit(Int?, optional) - Items per page (default: 10)
Example
1lifecycleScope.launch {
2 val recordings = client.listRecordings(
3 BaxcloudListRecordingsOptions(
4 status = "COMPLETED",
5 page = 1,
6 limit = 20
7 )
8 )
9 println("Recordings: ${recordings.items}")
10 println("Total: ${recordings.meta.total}")
11}getRecording
Get detailed information about a specific recording
suspend fun getRecording(recordingId: String): BaxcloudRecordingInfoExample
lifecycleScope.launch {
val recording = client.getRecording("recording-123")
println("Recording status: ${recording.status}")
println("File URL: ${recording.fileUrl}")
}getRecordingDownloadUrl
Get a temporary download URL for a recording file
suspend fun getRecordingDownloadUrl(recordingId: String, expiresIn: Int? = null): Map<String, Any>Parameters
recordingId(String) - Recording IDexpiresIn(Int?, optional) - URL expiration time in seconds (default: 3600)
Example
1lifecycleScope.launch {
2 val result = client.getRecordingDownloadUrl("recording-123", 7200)
3 val downloadUrl = result["downloadUrl"] as String
4 val expiresIn = result["expiresIn"] as Int
5 println("Download URL (expires in 2 hours): $downloadUrl")
6}Event Handlers
Register event handlers to listen for room events.
onUserJoined
fun onUserJoined(
handler: (Any) -> Unit
)onUserLeft
fun onUserLeft(
handler: (Any) -> Unit
)onMessageReceived
fun onMessageReceived(
handler: (BaxcloudRealtimeMessage, Any?) -> Unit
)onMediaStarted
fun onMediaStarted(
handler: (Any, Any, Any) -> Unit
)onMediaStopped
fun onMediaStopped(
handler: (Any, Any, Any) -> Unit
)onConnected
fun onConnected(
handler: () -> Unit
)onDisconnected
fun onDisconnected(
handler: (String?) -> Unit
)onReconnecting
fun onReconnecting(
handler: () -> Unit
)onReconnected
fun onReconnected(
handler: () -> Unit
)Event Handler Example
1class VideoCallActivity : AppCompatActivity() {
2 private lateinit var client: BaxCloudClient
3
4 override fun onCreate(savedInstanceState: Bundle?) {
5 super.onCreate(savedInstanceState)
6
7 client = BaxCloudClient(
8 context = this,
9 config = BaxCloudConfig(
10 projectId = "your-project-id",
11 apiKey = "your-api-key"
12 )
13 )
14
15 // Subscribe to events
16 client.onUserJoined { user ->
17 println("User joined: $user")
18 }
19
20 client.onUserLeft { user ->
21 println("User left: $user")
22 }
23
24 client.onConnected {
25 println("Connected to room")
26 }
27
28 client.onDisconnected { reason ->
29 println("Disconnected: $reason")
30 }
31 }
32}BaxCloudRoomController
Overview
Singleton controller for centralized room management
Access the controller via BaxCloudRoomController.instance
Initialization
1val controller = BaxCloudRoomController.instance
2controller.initialize(client, context)Host/Co-Host Management
isHost
fun isHost(): BooleanisCoHost
fun isCoHost(userId: String? = null): BooleantransferHost
suspend fun transferHost(
targetUserId: String
)Host only
promoteToCoHost
suspend fun promoteToCoHost(
userId: String
)Host only
demoteFromCoHost
suspend fun demoteFromCoHost(
userId: String
)Host only
getCoHosts
fun getCoHosts(): List<String>Participant Management
getParticipants
fun getParticipants(): List<Any>getParticipant
fun getParticipant(
userId: String
): Any?kickParticipant
suspend fun kickParticipant(
userId: String,
reason: String? = null
)Host/Co-host only
pinParticipant
suspend fun pinParticipant(
userId: String
)unpinParticipant
suspend fun unpinParticipant(
userId: String
)getPinnedParticipants
fun getPinnedParticipants(): List<String>spotlightParticipant
suspend fun spotlightParticipant(
userId: String
)Host/Co-host only
unspotlightParticipant
suspend fun unspotlightParticipant(
userId: String
)Host/Co-host only
getSpotlightedParticipants
fun getSpotlightedParticipants(): List<String>Audio/Video Controls
muteMicrophone
suspend fun muteMicrophone()unmuteMicrophone
suspend fun unmuteMicrophone()isMicrophoneMuted
fun isMicrophoneMuted(): BooleanenableCamera
suspend fun enableCamera()disableCamera
suspend fun disableCamera()isCameraEnabled
fun isCameraEnabled(): BooleanmuteAll
suspend fun muteAll()Host only
unmuteAll
suspend fun unmuteAll()Host only
muteParticipant
suspend fun muteParticipant(
userId: String
)Host/Co-host only
unmuteParticipant
suspend fun unmuteParticipant(
userId: String
)Host/Co-host only
Screen Sharing
enableScreenShare
suspend fun enableScreenShare()disableScreenShare
suspend fun disableScreenShare()isScreenShareEnabled
fun isScreenShareEnabled(): BooleanChat System
sendChatMessage
suspend fun sendChatMessage(
message: String
)getChatHistory
fun getChatHistory(): List<BaxcloudChatMessage>clearChatHistory
fun clearChatHistory()startTyping
suspend fun startTyping()Auto-stops after 3 seconds
stopTyping
suspend fun stopTyping()getTypingIndicators
fun getTypingIndicators(): List<BaxcloudTypingIndicator>Additional Features
Invitation System
sendCallInvitation(options: BaxcloudInvitationOptions): StringacceptCallInvitation(invitationId: String)declineCallInvitation(invitationId: String)cancelCallInvitation(invitationId: String)
Raise Hand
raiseHand()lowerHand(userId: String? = null)getRaisedHands(): List<BaxcloudRaisedHand>
Network Quality
getNetworkQuality(): BaxcloudNetworkQualitygetParticipantQuality(userId: String): BaxcloudNetworkQuality
Polling/Q&A
createPoll(question: String, options: List<String>): String(Host/Co-host only)respondToPoll(pollId: String, selectedOption: String)endPoll(pollId: String)(Host/Co-host only)getActivePolls(): List<BaxcloudPoll>getPoll(pollId: String): BaxcloudPoll?
Breakout Rooms
createBreakoutRoom(roomName: String, participantIds: List<String>): StringjoinBreakoutRoom(roomId: String)leaveBreakoutRoom(roomId: String)getBreakoutRooms(): List<BaxcloudBreakoutRoom>
Emoji Reactions & More
sendEmojiReaction(emoji: String)getRecentEmojiReactions(): List<BaxcloudEmojiReaction>approveWaitingRoomParticipant(userId: String)(Host/Co-host only)rejectWaitingRoomParticipant(userId: String)(Host/Co-host only)getWaitingRoomParticipants(): List<BaxcloudWaitingRoomParticipant>
Background Effects
applyBackgroundEffect(effect: BaxcloudBackgroundEffect)removeBackgroundEffect()getCurrentBackgroundEffect(): BaxcloudBackgroundEffect?
Accessibility
updateAccessibilitySettings(settings: BaxcloudAccessibilitySettings)getAccessibilitySettings(): BaxcloudAccessibilitySettings
Type Definitions
BaxcloudLiveType
Types of live sessions
enum class BaxcloudLiveType {
VIDEO_CALL,
VIDEO_CONFERENCE,
LIVE_STREAMING,
AUDIO_CONFERENCE
}BaxCloudConnectionState
Connection state enum
enum class BaxCloudConnectionState {
DISCONNECTED,
CONNECTING,
CONNECTED,
RECONNECTING,
FAILED
}BaxcloudUser
User/Participant information
data class BaxcloudUser(
val userId: String,
val name: String,
val avatarUrl: String? = null,
val isHost: Boolean = false
)BaxcloudRoomOptions
Options for connecting to a room
data class BaxcloudRoomOptions(
val roomName: String,
val participant: BaxcloudUser,
val liveType: BaxcloudLiveType,
val canJoinWithNoHost: Boolean? = true,
val roomMetadata: Map<String, Any>? = null
)Android-Specific Notes
Permissions
Runtime Permissions
Required for Android 6.0+ (API 23+)
- Request permissions before connecting to a room
- Handle permission denial gracefully
- Request flow: Request → Check → Connect
Manifest Permissions
Required in AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />Background Handling
- Handle app lifecycle changes properly
- Consider disabling camera/mic when app goes to background
- Re-enable when app comes to foreground
- Use
onPause()andonResume()lifecycle methods
Picture-in-Picture (PIP)
Note: PIP is not yet implemented for Android. This is a placeholder for future implementation.
Requirements (Future)
- Available on Android 8.0+ (API 26+)
- Requires
android:supportsPictureInPicture="true"in manifest - Handle PIP mode in
onPictureInPictureModeChanged()
ProGuard Rules
If using ProGuard, add the following rules:
-keep class com.baxcloud.client.** { *; }Note: ProGuard rules are handled internally by the SDK.
Best Practices
- Use Coroutines: All SDK methods are suspend functions. Always use coroutines with
lifecycleScopeorviewModelScope. - Initialize Room Controller: Initialize the controller in
onCreate()for centralized room management. - Request Permissions Early: Always request permissions before attempting to connect to a room.
- Handle Lifecycle: Properly handle activity lifecycle to manage camera/mic resources.
- Clean Up Resources: Always disconnect in
onDestroy()to free resources.