Skip to content

Commit

Permalink
Add audio only livestream call service.
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandar-apostolov committed Aug 29, 2024
1 parent 9b4ffee commit e987a3a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions stream-video-android-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
android:foregroundServiceType="camera|microphone"
android:exported="false" />

<service
android:name=".notifications.internal.service.LivestreamAudioCallService"
android:foregroundServiceType="microphone"
android:exported="false" />

<service
android:name=".notifications.internal.service.LivestreamViewerService"
android:foregroundServiceType="mediaPlayback"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ public fun livestreamCallServiceConfig(): CallServiceConfig {
)
}

/**
* Return a default configuration for the call service configuration for livestream which has no camera
*/
public fun livestreamAudioCallServiceConfig(): CallServiceConfig {
return CallServiceConfig(
runCallServiceInForeground = true,
callServicePerType = mapOf(
Pair(ANY_MARKER, CallService::class.java),
Pair("livestream", LivestreamAudioCallService::class.java),
),
)
}

/**
* Return a default configuration for the call service configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ internal open class LivestreamCallService : CallService() {
override val serviceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
}

/**
* Due to the nature of the livestream calls, the service that is used is of different type.
*/
internal open class LivestreamAudioCallService : CallService() {
override val logger: TaggedLogger by taggedLogger("LivestreamHostCallService")
override val serviceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
}

/**
* Due to the nature of the livestream calls, the service that is used is of different type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,24 @@ class CallServiceConfigTest {
assertEquals(LivestreamViewerService::class.java, livestreamServiceClass)
assertEquals(AudioAttributes.USAGE_MEDIA, audioUsage)
}

@Test
fun `livestreamAudioCallServiceConfig should return correct default configuration`() {
// Given
val config = livestreamAudioCallServiceConfig()

// When
val runInForeground = config.runCallServiceInForeground
val servicePerTypeSize = config.callServicePerType.size
val hostServiceClass = config.callServicePerType[ANY_MARKER]
val livestreamServiceClass = config.callServicePerType["livestream"]
val audioUsage = config.audioUsage

// Then
assertEquals(true, runInForeground)
assertEquals(2, servicePerTypeSize)
assertEquals(CallService::class.java, hostServiceClass)
assertEquals(LivestreamAudioCallService::class.java, livestreamServiceClass)
assertEquals(AudioAttributes.USAGE_VOICE_COMMUNICATION, audioUsage)
}
}

0 comments on commit e987a3a

Please sign in to comment.