Skip to content

Commit

Permalink
Merge branch 'develop' into release/1.0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandar-apostolov authored Sep 27, 2024
2 parents 8c5e473 + ba29ce4 commit 050c43d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 35 deletions.
8 changes: 2 additions & 6 deletions stream-video-android-core/api/stream-video-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,14 @@ public final class io/getstream/video/android/core/MemberState {
}

public final class io/getstream/video/android/core/MicrophoneManager {
public fun <init> (Lio/getstream/video/android/core/MediaManagerImpl;ZI)V
public fun <init> (Lio/getstream/video/android/core/MediaManagerImpl;I)V
public final fun canHandleDeviceSwitch ()Z
public final fun cleanup ()V
public final fun disable (Z)V
public static synthetic fun disable$default (Lio/getstream/video/android/core/MicrophoneManager;ZILjava/lang/Object;)V
public final fun getAudioUsage ()I
public final fun getDevices ()Lkotlinx/coroutines/flow/StateFlow;
public final fun getMediaManager ()Lio/getstream/video/android/core/MediaManagerImpl;
public final fun getPreferSpeakerphone ()Z
public final fun getSelectedDevice ()Lkotlinx/coroutines/flow/StateFlow;
public final fun getStatus ()Lkotlinx/coroutines/flow/StateFlow;
public final fun isEnabled ()Lkotlinx/coroutines/flow/StateFlow;
Expand Down Expand Up @@ -868,11 +867,8 @@ public abstract interface class io/getstream/video/android/core/audio/AudioHandl

public final class io/getstream/video/android/core/audio/AudioSwitchHandler : io/getstream/video/android/core/audio/AudioHandler {
public static final field Companion Lio/getstream/video/android/core/audio/AudioSwitchHandler$Companion;
public fun <init> (Landroid/content/Context;ZLkotlin/jvm/functions/Function2;)V
public final fun getAudioDeviceChangeListener ()Lkotlin/jvm/functions/Function2;
public final fun getPreferSpeakerphone ()Z
public fun <init> (Landroid/content/Context;Lkotlin/jvm/functions/Function2;)V
public final fun selectDevice (Lcom/twilio/audioswitch/AudioDevice;)V
public final fun setAudioDeviceChangeListener (Lkotlin/jvm/functions/Function2;)V
public fun start ()V
public fun stop ()V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,17 +900,10 @@ public class Call(

private fun updateMediaManagerFromSettings(callSettings: CallSettingsResponse) {
// Speaker
if (speaker.status.value is DeviceStatus.NotSelected) {
val enableSpeaker =
if (callSettings.video.cameraDefaultOn || camera.status.value is DeviceStatus.Enabled) {
// if camera is enabled then enable speaker. Eventually this should
// be a new audio.defaultDevice setting returned from backend
true
} else {
callSettings.audio.defaultDevice == AudioSettingsResponse.DefaultDevice.Speaker
}
speaker.setEnabled(enableSpeaker)
}
speaker.setEnabled(
enabled = callSettings.audio.defaultDevice == AudioSettingsResponse.DefaultDevice.Speaker ||
callSettings.audio.speakerDefaultOn,
)

// Camera
if (camera.status.value is DeviceStatus.NotSelected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ class SpeakerManager(
fun setSpeakerPhone(enable: Boolean, defaultFallback: StreamAudioDevice? = null) {
microphoneManager.setup()
val devices = devices.value
val selectedBeforeSpeaker = selectedDevice.value
if (enable) {
val speaker = devices.filterIsInstance<StreamAudioDevice.Speakerphone>().firstOrNull()
selectedBeforeSpeaker = selectedDevice.value
_speakerPhoneEnabled.value = true
microphoneManager.select(speaker)
} else {
Expand Down Expand Up @@ -328,7 +328,6 @@ class ScreenShareManager(
*/
class MicrophoneManager(
val mediaManager: MediaManagerImpl,
val preferSpeakerphone: Boolean,
val audioUsage: Int,
) {
// Internal data
Expand Down Expand Up @@ -451,7 +450,7 @@ class MicrophoneManager(

if (canHandleDeviceSwitch()) {
audioHandler =
AudioSwitchHandler(mediaManager.context, preferSpeakerphone) { devices, selected ->
AudioSwitchHandler(mediaManager.context) { devices, selected ->
logger.i { "audio devices. selected $selected, available devices are $devices" }
_devices.value = devices.map { it.fromAudio() }
_selectedDevice.value = selected?.fromAudio()
Expand Down Expand Up @@ -858,7 +857,7 @@ class MediaManagerImpl(
)

internal val camera = CameraManager(this, eglBaseContext)
internal val microphone = MicrophoneManager(this, preferSpeakerphone = true, audioUsage)
internal val microphone = MicrophoneManager(this, audioUsage)
internal val speaker = SpeakerManager(this, microphone)
internal val screenShare = ScreenShareManager(this, eglBaseContext)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ public interface AudioHandler {
/**
* TODO: this class should be merged into the Microphone Manager
*/
public class AudioSwitchHandler constructor(
public class AudioSwitchHandler(
private val context: Context,
val preferSpeakerphone: Boolean,
var audioDeviceChangeListener: AudioDeviceChangeListener,
private var audioDeviceChangeListener: AudioDeviceChangeListener,
) :
AudioHandler {

Expand All @@ -65,13 +64,8 @@ public class AudioSwitchHandler constructor(
AudioDevice.BluetoothHeadset::class.java,
)

if (preferSpeakerphone) {
devices.add(AudioDevice.Speakerphone::class.java)
devices.add(AudioDevice.Earpiece::class.java)
} else {
devices.add(AudioDevice.Earpiece::class.java)
devices.add(AudioDevice.Speakerphone::class.java)
}
devices.add(AudioDevice.Earpiece::class.java)
devices.add(AudioDevice.Speakerphone::class.java)

handler.post {
val switch = AudioSwitch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MicrophoneManagerTest {
fun `Ensure setup is called prior to any action onto the microphone manager`() = runTest {
// Given
val mediaManager = mockk<MediaManagerImpl>(relaxed = true)
val actual = MicrophoneManager(mediaManager, false, audioUsage)
val actual = MicrophoneManager(mediaManager, audioUsage)
val context = mockk<Context>(relaxed = true)
val microphoneManager = spyk(actual)
every { mediaManager.context } returns context
Expand Down Expand Up @@ -69,7 +69,6 @@ class MicrophoneManagerTest {
val actual =
MicrophoneManager(
mediaManager,
false,
audioUsage = AudioAttributes.USAGE_VOICE_COMMUNICATION,
)
val context = mockk<Context>(relaxed = true)
Expand All @@ -91,7 +90,7 @@ class MicrophoneManagerTest {
fun `Ensure setup if ever the manager was cleaned`() {
// Given
val mediaManager = mockk<MediaManagerImpl>(relaxed = true)
val actual = MicrophoneManager(mediaManager, false, audioUsage)
val actual = MicrophoneManager(mediaManager, audioUsage)
val context = mockk<Context>(relaxed = true)
val microphoneManager = spyk(actual)
every { mediaManager.context } returns context
Expand Down Expand Up @@ -119,7 +118,7 @@ class MicrophoneManagerTest {
fun `Resume will call enable only if prior status was DeviceStatus#enabled`() {
// Given
val mediaManager = mockk<MediaManagerImpl>(relaxed = true)
val actual = MicrophoneManager(mediaManager, false, audioUsage)
val actual = MicrophoneManager(mediaManager, audioUsage)
val context = mockk<Context>(relaxed = true)
val microphoneManager = spyk(actual)
every { mediaManager.context } returns context
Expand Down

0 comments on commit 050c43d

Please sign in to comment.