Skip to content

Commit

Permalink
Update docs & clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
liviu-timar committed Sep 18, 2024
1 parent c4ca820 commit 9e0ed94
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ object StreamVideoInitHelper {
apiKey = apiKey,
user = user,
token = token,
loggingLevel = loggingLevel,
ensureSingleInstance = false,
notificationConfig = NotificationConfig(
pushDeviceGenerators = listOf(
FirebasePushDeviceGenerator(providerName = "firebase"),
),
),
tokenProvider = {
val email = user.custom?.get("email")
val authData = StreamService.instance.getAuthData(
Expand All @@ -199,13 +206,6 @@ object StreamVideoInitHelper {
)
authData.token
},
loggingLevel = loggingLevel,
notificationConfig = NotificationConfig(
pushDeviceGenerators = listOf(
FirebasePushDeviceGenerator(providerName = "firebase"),
),
),
ensureSingleInstance = false,
appName = "Stream Video Demo App",
).build()
}
Expand Down
70 changes: 64 additions & 6 deletions docusaurus/docs/Android/06-advanced/01-ringing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,67 @@ call.leave()

The SDK plays sounds for incoming and outgoing calls. You can customize these sounds by passing your own instance of the `Sounds` class to the `StreamVideoBuilder` `sounds` constructor parameter.

`Sounds` has two resource properties, `incomingCallSoundResId` and `outgoingCallSoundResId`. These properties can have the following values:
- By default, their values are the device ringtone for incoming and a default ringing tone provided by the SDK for outgoing.
- You can pass raw resource identifiers that correspond to audio files in your project's `res/raw` directory.
- To disable (mute) one of the sounds, pass `null` to the corresponding property.
- You can pass the `Sounds.DEVICE_INCOMING_RINGTONE` special value to `incomingCallSoundResId` to use the device ringtone.
- Special cases: if the device ringtone is evaluated to `null` or the outgoing sound is set to `DEVICE_INCOMING_RINGTONE`, a corresponding default sound will be used.
#### Deprecated method for customizing sounds

`Sounds` has two properties, `incomingCallSound` and `outgoingCallSound`. You need to assign raw resource identifiers to these properties. These identifiers correspond to audio files in your project's `res/raw` directory.

To disable sounds, pass `null` to `incomingCallSound` or `outgoingCallSound`.

:::caution
This constructor of the `Sounds` class is deprecated. It should be replaced with the `Sounds(SoundConfig)` constructor. See the recommended method below.
:::

#### Recommended method for customizing sounds

`Sounds` has one property, `soundConfig` of type `SoundConfig`.

The `SoundConfig` interface defines two properties:
- `incomingCallSoundUri`: The URI for the incoming call sound.
- `outgoingCallSoundUri`: The URI for the outgoing call sound.

Also, `SoundConfig` provides several static factory methods to create sound configurations:
- `createDeviceRingtoneSoundConfig` - This method returns a `SoundConfig` that uses the device ringtone for incoming calls and the SDK default ringing tone for outgoing calls.
- `createStreamResourcesSoundConfig` - This method returns a `SoundConfig` that uses the SDK's default sounds for both incoming and outgoing calls.
- `createEmptySoundConfig` - Returns a `SoundConfig` that mutes (disables) all sounds.
- `createCustomSoundConfig` - This method allows you to specify custom sounds for incoming and outgoing calls. The sounds can be either `URI`s or resource ID `Int`s. If you use resource IDs, you **must** provide a context.

:::note
By default, if you don't pass anything to the `sounds` builder parameter, the `createDeviceRingtoneSoundConfig` configuration is used.
:::

##### Usage examples

```kotlin
val soundConfig = SoundConfig.createCustomSoundConfig(
incomingCallSound = R.raw.custom_sound,
outgoingCallSound = customSoundUri,
context = context
)

StreamVideoBuilder(
// ...
sounds = Sounds(soundConfig),
// ...
)
```

```kotlin
val baseSoundConfig = SoundConfig.createDeviceRingtoneSoundConfig(context)

val mixedSoundConfig1 = SoundConfig.createCustomSoundConfig(
// Use device ringtone for incoming calls
incomingCallSound = baseSoundConfig.incomingCallSoundUri,
// Use custom sound for outgoing calls
outgoingCallSound = R.raw.call_busy_sound,
// Context needed as we're using a res ID
context = context
)

val mixedSoundConfig2 = SoundConfig.createCustomSoundConfig(
// Use device ringtone for incoming calls
incomingCallSound = baseSoundConfig.incomingCallSoundUri,
// Mute the outgoing call sound
outgoingCallSound = null,
// Context not needed as we're not using any res ID
)
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import io.getstream.video.android.core.R
import io.getstream.video.android.core.utils.safeCall

/**
* Base sound configuration.
* Interface representing a sound configuration.
*
* @see createDeviceRingtoneSoundConfig
* @see createStreamResourcesSoundConfig
Expand Down Expand Up @@ -70,6 +70,11 @@ interface SoundConfig {
getSoundUriFromRes(context, R.raw.call_outgoing_sound)
}

/**
* Utility method that returns a sound URI from a resource ID.
*
* @return The sound URI or null if the resource ID is null or an exception occurred.
*/
fun getSoundUriFromRes(context: Context, soundResId: Int?): Uri? = soundResId?.let {
safeCall(default = null) {
Uri.parse("android.resource://${context.packageName}/$soundResId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ constructor(
) {

private var soundConfig: SoundConfig? = null
private set

/**
* Configure sounds by passing a [SoundConfig].
Expand All @@ -60,19 +59,15 @@ constructor(
if (soundConfig != null) {
soundConfig.incomingCallSoundUri
} else {
incomingCallSound?.let {
Uri.parse("android.resource://${context.packageName}/$it")
}
incomingCallSound?.let { SoundConfig.getSoundUriFromRes(context, it) }
}
}

internal fun getOutgoingCallSoundUri(context: Context): Uri? = soundConfig.let { soundConfig ->
if (soundConfig != null) {
soundConfig.outgoingCallSoundUri
} else {
outgoingCallSound?.let {
Uri.parse("android.resource://${context.packageName}/$it")
}
outgoingCallSound?.let { SoundConfig.getSoundUriFromRes(context, it) }
}
}
}

0 comments on commit 9e0ed94

Please sign in to comment.