-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
187 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
kmp-webrtc/src/androidMain/kotlin/com/piasy/kmp/webrtc/AndroidAudioDeviceManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.piasy.kmp.webrtc | ||
|
||
import android.content.Context | ||
import android.media.AudioManager | ||
import com.piasy.avconf.audio.AppRTCAudioManager | ||
import com.piasy.avconf.audio.AppRTCAudioManager.AudioDevice.BLUETOOTH | ||
import com.piasy.avconf.audio.AppRTCAudioManager.AudioDevice.EARPIECE | ||
import com.piasy.avconf.audio.AppRTCAudioManager.AudioDevice.SPEAKER_PHONE | ||
import com.piasy.avconf.audio.AppRTCAudioManager.AudioDevice.WIRED_HEADSET | ||
|
||
/** | ||
* Created by Piasy{github.com/Piasy} on 2019-11-27. | ||
*/ | ||
class AndroidAudioDeviceManager(private val context: Context, speakerPhoneMode: SpeakerphoneMode) : | ||
AudioDeviceManager { | ||
private val audioManager = AppRTCAudioManager.create(context, speakerphoneMode(speakerPhoneMode)) | ||
private var speakerOn = false | ||
|
||
private fun speakerphoneMode(mode: SpeakerphoneMode) = when (mode) { | ||
SpeakerphoneMode.AUTO -> AppRTCAudioManager.SPEAKERPHONE_AUTO | ||
SpeakerphoneMode.OPEN -> AppRTCAudioManager.SPEAKERPHONE_TRUE | ||
SpeakerphoneMode.CLOSE -> AppRTCAudioManager.SPEAKERPHONE_FALSE | ||
} | ||
|
||
override fun setSpeakerphoneOn(speakerOn: Boolean) { | ||
this.speakerOn = speakerOn | ||
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager | ||
if (!audioManager.isWiredHeadsetOn) { | ||
audioManager.isSpeakerphoneOn = speakerOn | ||
} | ||
} | ||
|
||
override fun start(callback: AudioDeviceManagerCallback) { | ||
audioManager.start { selectedAudioDevice, _ -> | ||
when (selectedAudioDevice) { | ||
SPEAKER_PHONE -> { | ||
setSpeakerphoneOn(speakerOn) | ||
callback.onAudioDeviceChanged(AudioDevice.SPEAKER_PHONE) | ||
} | ||
|
||
WIRED_HEADSET -> callback.onAudioDeviceChanged(AudioDevice.WIRED_HEADSET) | ||
EARPIECE -> callback.onAudioDeviceChanged(AudioDevice.EARPIECE) | ||
BLUETOOTH -> callback.onAudioDeviceChanged(AudioDevice.BLUETOOTH) | ||
else -> callback.onAudioDeviceChanged(AudioDevice.NONE) | ||
} | ||
} | ||
audioManager.changeAudioRoute(true) | ||
if (audioManager.selectedAudioDevice == SPEAKER_PHONE) { | ||
setSpeakerphoneOn(true) | ||
} | ||
} | ||
|
||
override fun stop() { | ||
audioManager.stop() | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
kmp-webrtc/src/androidMain/kotlin/com/piasy/kmp/webrtc/AndroidPeerConnectionClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
kmp-webrtc/src/appleMain/kotlin/com/piasy/kmp/webrtc/IOSAudioDeviceManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.piasy.kmp.webrtc | ||
|
||
import WebRTC.* | ||
import com.piasy.kmp.webrtc.AudioDevice.BLUETOOTH | ||
import com.piasy.kmp.webrtc.AudioDevice.EARPIECE | ||
import com.piasy.kmp.webrtc.AudioDevice.NONE | ||
import com.piasy.kmp.webrtc.AudioDevice.SPEAKER_PHONE | ||
import com.piasy.kmp.webrtc.AudioDevice.WIRED_HEADSET | ||
import platform.darwin.NSObject | ||
|
||
/** | ||
* Created by Piasy{github.com/Piasy} on 2019-11-30. | ||
*/ | ||
private class ObjCAudioDeviceManagerCallback(private val realCallback: AudioDeviceManagerCallback) : | ||
CFAudioDeviceManagerDelegateProtocol, NSObject() { | ||
override fun onAudioDeviceChanged(audioDevice: CFAudioDevice) { | ||
realCallback.onAudioDeviceChanged( | ||
when (audioDevice) { | ||
CFAudioDevice.CF_SPEAKER_PHONE -> SPEAKER_PHONE | ||
CFAudioDevice.CF_WIRED_HEADSET -> WIRED_HEADSET | ||
CFAudioDevice.CF_EARPIECE -> EARPIECE | ||
CFAudioDevice.CF_BLUETOOTH -> BLUETOOTH | ||
else -> NONE | ||
} | ||
) | ||
} | ||
} | ||
|
||
class IOSAudioDeviceManager : AudioDeviceManager { | ||
private val realManager = CFAudioDeviceManager() | ||
|
||
override fun setSpeakerphoneOn(speakerOn: Boolean) { | ||
realManager.setSpeakerphoneOn(speakerOn) | ||
} | ||
|
||
override fun start(callback: AudioDeviceManagerCallback) { | ||
realManager.start(ObjCAudioDeviceManagerCallback(callback)) | ||
} | ||
|
||
override fun stop() { | ||
realManager.stop() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
kmp-webrtc/src/commonMain/kotlin/com/piasy/kmp/webrtc/AudioDeviceManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.piasy.kmp.webrtc | ||
|
||
/** | ||
* Created by Piasy{github.com/Piasy} on 2019-11-27. | ||
*/ | ||
interface AudioDeviceManager { | ||
fun setSpeakerphoneOn(speakerOn: Boolean) | ||
|
||
fun start(callback: AudioDeviceManagerCallback) | ||
|
||
fun stop() | ||
} | ||
|
||
enum class AudioDevice { | ||
SPEAKER_PHONE, | ||
WIRED_HEADSET, | ||
EARPIECE, | ||
BLUETOOTH, | ||
NONE, | ||
} | ||
|
||
enum class SpeakerphoneMode { | ||
AUTO, | ||
OPEN, | ||
CLOSE, | ||
} | ||
|
||
interface AudioDeviceManagerCallback { | ||
fun onAudioDeviceChanged(device: AudioDevice) | ||
} |
5 changes: 5 additions & 0 deletions
5
kmp-webrtc/src/commonMain/kotlin/com/piasy/kmp/webrtc/PeerConnectionClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tlin/com/piasy/kmp/webrtc/IceCandidate.kt → ...com/piasy/kmp/webrtc/data/IceCandidate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../kotlin/com/piasy/kmp/webrtc/IceServer.kt → ...in/com/piasy/kmp/webrtc/data/IceServer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...in/com/piasy/kmp/webrtc/RtcStatsReport.kt → ...m/piasy/kmp/webrtc/data/RtcStatsReport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.piasy.kmp.webrtc | ||
package com.piasy.kmp.webrtc.data | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...om/piasy/kmp/webrtc/SessionDescription.kt → ...asy/kmp/webrtc/data/SessionDescription.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...kotlin/com/piasy/kmp/webrtc/FieldTrial.kt → .../com/piasy/kmp/webrtc/utils/FieldTrial.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...in/com/piasy/kmp/webrtc/FieldTrialTest.kt → .../piasy/kmp/webrtc/utils/FieldTrialTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters