client.state.callConfigRegistry.register(
DefaultCallConfigurations.getLivestreamGuestCallServiceConfig()
)
Call Configurations
Table of Contents
Overview
This document outlines how to configure specific behavior for different types of calls (e.g., default call, livestream call, audio call) using the Stream SDK. Users can customise the following behavior for each call type:
- Show or hide foreground notifications.
- Set the type of audio usage for the call from:
AudioAttributes.USAGE_VOICE_COMMUNICATION
(default)AudioAttributes.USAGE_MEDIA
- Set a custom foreground service class.
Default Behavior
If no CallServiceConfigRegistry
is explicitly provided, the SDK uses default behavior to ensure compatibility and smooth functioning. Users can override these defaults as needed.
Implementation Details
We introduced a new class, CallServiceConfigRegistry
, to manage call type configurations and provide an easy way to register, retrieve, and update them.
Default Configurations
To simplify the process, we provide default configurations through the DefaultCallConfigurations
class. These can be used directly for common scenarios.
The following table outlines the default properties and their specific usage:
Property |
---|
default |
livestream |
livestreamAudioCall |
livestreamGuestCall |
audioCall |
Example: Guest Livestream Call Configuration
Managing CallServiceConfigRegistry
Setting CallServiceConfigRegistry
Users can pass their own CallServiceConfigRegistry
instance into the StreamVideoBuilder
constructor as an argument. For example:
val customRegistry = CallServiceConfigRegistry()
val streamVideoBuilder = StreamVideoBuilder(callServiceConfigRegistry = customRegistry)
Accessing CallServiceConfigRegistry
Users can access the CallServiceConfigRegistry
through ClientState.callConfigRegistry
. This provides a global point to manage and retrieve configurations:
val registry = client.state.callConfigRegistry
Practical Tip
Ensure the CallServiceConfigRegistry
is initialized and passed into the StreamVideoBuilder
before any call configurations are required. This ensures seamless integration and functionality.
Configuring Call Behavior
Registering Configurations
You can register configurations for different call types using the CallServiceConfigRegistry
class:
Explicit Registration
val registry = CallServiceConfigRegistry()
// Register a configuration explicitly
registry.register(CallType.Default.name, CallServiceConfig())
Using a Builder
registry.register("livestream") {
setServiceClass(MyCallService::class.java)
setRunCallServiceInForeground(true)
}
Registering Multiple Configurations
registry.register(
mapOf(
CallType.AudioCall.name to CallServiceConfig(),
CallType.Default.name to CallServiceConfig()
)
)
Retrieving Configurations
You can retrieve a configuration for a specific call type using:
val config = registry.get(CallType.Default.name)
Updating Configurations
To update an existing configuration:
registry.update(CallType.Default.name) {
setRunCallServiceInForeground(false)
}
Examples for Different Call Types
With the provided APIs, users can set specific configurations for various call types. Below are examples:
Example: Default Call Configuration
val registry = CallServiceConfigRegistry()
/**
* Either you can directly use the default configurations
*/
registry.register(CallType.Default.name, DefaultCallConfigurations.default)
/**
* Or you can customise the default configurations via .copy() like this
*/
registry.register(CallType.Default.name, DefaultCallConfigurations.default.copy(audioUsage = ... // Customise the audio usage and other properties here
))
/**
* Or you can just use customise all from ground up
*/
registry.register(CallType.Default.name) {
setServiceClass(YourCustomService::class.java)
setRunCallServiceInForeground(true)
setAudioUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
}
/**
* Finally Setting call configurations to the stream sdk
*/
StreamVideoBuilder.build(
// other arguments...
callServiceConfigRegistry = registry)
Example: Livestream Call Configuration
val registry = CallServiceConfigRegistry()
/**
* Either you can directly use the default configurations
*/
registry.register(CallType.Livestream.name, DefaultCallConfigurations.livestream)
/**
* Or you can customise the default configurations via .copy() like this
*/
registry.register(CallType.Livestream.name, DefaultCallConfigurations.livestream.copy(audioUsage = ... // Customise the audio usage and other properties here
))
/**
* Or you can just use customise all from ground up
*/
registry.register(CallType.Livestream.name) {
setServiceClass(YourCustomService::class.java)
setRunCallServiceInForeground(false)
setAudioUsage(AudioAttributes.USAGE_MEDIA)
}
Example: Audio Call Configuration
val registry = CallServiceConfigRegistry()
/**
* Either you can directly use the default configurations
*/
registry.register(CallType.AudioCall.name, DefaultCallConfigurations.audioCall)
/**
* Or you can customise the default configurations via .copy() like this
*/
registry.register(CallType.AudioCall.name, DefaultCallConfigurations.audioCall.copy(audioUsage = ... // Customise the audio usage and other properties here
))
/**
* Or you can just use customise all from ground up
*/
registry.register(CallType.Audio.name) {
setRunCallServiceInForeground(false)
setAudioUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
}
Summary
The CallServiceConfigRegistry
class provides a flexible and efficient way to customise call behavior for various scenarios. By leveraging this feature, users can:
- Define custom behavior for specific call types.
- Update configurations dynamically.
- Use predefined default configurations for common use cases.
This functionality ensures that the Stream SDK remains adaptable to diverse application requirements.