Skip to content

Commit

Permalink
Merge pull request #37 from wuleihenbang/master
Browse files Browse the repository at this point in the history
升级 Gradle 和依赖版本,优化音频通话逻辑
  • Loading branch information
chandarlee authored Aug 6, 2024
2 parents f3a6cd2 + 236c70f commit 46945f5
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
with:
java-version: 1.8

- name: Setup Python 2.7
- name: Setup Python 3.12.4
uses: actions/setup-python@v2
with:
python-version: '2.7'
python-version: '3.12.4'

- name: Config Stub
run:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Setup Python 2.7
- name: Setup Python 3.12.4
uses: actions/setup-python@v2
with:
python-version: '2.7'
python-version: '3.12.4'

- name: Config Stub
run:
Expand Down
13 changes: 5 additions & 8 deletions NLiteAVDemo-Android-Java/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
google()
jcenter()
mavenCentral()
maven { url 'https://maven.faceunity.com/repository/maven-public/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -16,12 +16,9 @@ buildscript {

allprojects {
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
google()
mavenCentral()
maven { url 'http://developer.huawei.com/repo/' }
maven { url "https://jitpack.io" }
jcenter()
maven { url 'https://maven.faceunity.com/repository/maven-public/' }
}
}

Expand Down Expand Up @@ -61,7 +58,7 @@ class Libs{
static def alog = "com.netease.yunxin.kit:alog:1.1.0"
static def kotlinxCoroutinesCore = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
static def kotlinxCoroutinesAndroid = "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
static def call = "com.netease.yunxin.kit.call:call:2.2.2"
static def call = "com.netease.yunxin.kit.call:call:2.5.1"
static def okhttp = "com.squareup.okhttp3:okhttp:4.9.3"
static def okhttpLoggingInterceptor = "com.squareup.okhttp3:logging-interceptor:4.9.3"
static def retrofitCore = "com.squareup.retrofit2:retrofit:2.9.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import com.netease.yunxin.kit.call.p2p.model.NECallType
import com.netease.yunxin.kit.call.p2p.model.NEInviteInfo
import com.netease.yunxin.kit.call.p2p.model.NESetupConfig
import com.netease.yunxin.nertc.nertcvideocall.utils.CallOrderHelper
import com.netease.yunxin.nertc.nertcvideocall.utils.EventReporter
import com.netease.yunxin.nertc.ui.base.AVChatSoundPlayer
import com.netease.yunxin.nertc.ui.base.CallParam
import com.netease.yunxin.nertc.ui.base.Constants
import com.netease.yunxin.nertc.ui.base.MultiLanguageHelper
import com.netease.yunxin.nertc.ui.base.UserInfoExtensionHelper
import com.netease.yunxin.nertc.ui.p2p.CallUIOperationsMgr
import com.netease.yunxin.nertc.ui.service.CallKitUIBridgeService
Expand Down Expand Up @@ -123,7 +123,6 @@ object CallKitUI {
wrapperUncaughtExceptionHandler()
this@CallKitUI.currentUserAccId = currentUserAccId
this@CallKitUI.currentUserRtcUid = currentUserRtcUId
EventReporter.canReport = enableReport
UserInfoExtensionHelper.userInfoHelper = userInfoHelper
val uiService = object : UIService {
override fun getOneToOneAudioChat(): Class<out Activity>? =
Expand Down Expand Up @@ -191,13 +190,15 @@ object CallKitUI {
// rtc 扩展
val extension = callExtension ?: NECallExtensionMgr.getInstance().callExtension
// 组件初始化配置
val setupConfig = NESetupConfig.Builder(rtcConfig.appKey, currentUserAccId)
val setupConfig = NESetupConfig.Builder(rtcConfig.appKey)
.currentUserRtcUid(currentUserRtcUId)
.initRtcMode(initRtcMode)
.rtcCallExtension(extension)
.enableAutoJoinSignalChannel(enableAutoJoinWhenCalled)
.enableJoinRtcWhenCall(joinRtcWhenCall)
.rtcOption(rtcConfig.rtcSdkOption)
.framework(framework)
.channel(channel)
.build()
// 初始化
NECallEngine.sharedInstance().setup(context.applicationContext, setupConfig)
Expand All @@ -217,6 +218,7 @@ object CallKitUI {
)
}
CallUIOperationsMgr.load(context)
MultiLanguageHelper.changeLanguage(context, language.language)
init = true
ALog.d(TAG, "CallKitUI init completed. Init with options $this.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.netease.yunxin.kit.call.p2p.model.NECallInitRtcMode
import com.netease.yunxin.kit.call.p2p.model.NEInviteInfo
import com.netease.yunxin.nertc.nertcvideocall.model.CallExtension
import com.netease.yunxin.nertc.nertcvideocall.utils.InfoFilterUtils.subInfo
import com.netease.yunxin.nertc.ui.base.LanguageType
import com.netease.yunxin.nertc.ui.base.SoundHelper
import com.netease.yunxin.nertc.ui.base.UserInfoHelper
import com.netease.yunxin.nertc.ui.group.GroupCallActivity
Expand All @@ -38,7 +39,6 @@ class CallKitUIOptions constructor(
val userInfoHelper: UserInfoHelper? = null,
val incomingCallEx: IncomingCallEx? = null,
val callKitUIBridgeService: CallKitUIBridgeService? = null,
val enableReport: Boolean = true,
val pushConfigProviderForGroup: PushConfigProviderForGroup? = null,
val callExtension: CallExtension? = null,
val soundHelper: SoundHelper? = SoundHelper(),
Expand All @@ -48,7 +48,10 @@ class CallKitUIOptions constructor(
val joinRtcWhenCall: Boolean = false,
val audio2Video: Boolean = false,
val video2Audio: Boolean = false,
val enableGroup: Boolean = false
val enableGroup: Boolean = false,
val language: NECallUILanguage = NECallUILanguage.AUTO,
var framework: String? = null,
var channel: String? = null
) {

class Builder {
Expand All @@ -70,8 +73,6 @@ class CallKitUIOptions constructor(

private var callKitUIBridgeService: CallKitUIBridgeService? = null

private var enableReport: Boolean = true

private var pushConfigProviderForGroup: PushConfigProviderForGroup? = null

private var contactSelector: (
Expand Down Expand Up @@ -101,10 +102,17 @@ class CallKitUIOptions constructor(
private var enableGroup: Boolean = false

private var audio2Video: Boolean = false

private var video2Audio: Boolean = false

private var joinRtcWhenCall: Boolean = false

private var language: NECallUILanguage = NECallUILanguage.AUTO

private var framework: String? = null

private var channel: String? = null

fun rtcSdkOption(option: NERtcOption) = apply {
this.rtcSdkOption = option
}
Expand Down Expand Up @@ -161,10 +169,6 @@ class CallKitUIOptions constructor(
this.callKitUIBridgeService = callKitUIBridgeService
}

fun enableReport(enable: Boolean) = apply {
this.enableReport = enable
}

fun pushConfigProviderForGroup(providerForGroup: PushConfigProviderForGroup) = apply {
this.pushConfigProviderForGroup = providerForGroup
}
Expand Down Expand Up @@ -224,6 +228,18 @@ class CallKitUIOptions constructor(
this.joinRtcWhenCall = joinRtcWhenCall
}

fun language(language: NECallUILanguage) = apply {
this.language = language
}

fun framework(framework: String) = apply {
this.framework = framework
}

fun channel(channel: String) = apply {
this.channel = channel
}

fun build(): CallKitUIOptions {
val rtcConfig =
CallKitUIRtcConfig(rtcAppKey, rtcSdkOption)
Expand All @@ -244,7 +260,6 @@ class CallKitUIOptions constructor(
userInfoHelper = userInfoHelper,
incomingCallEx = incomingCallEx,
callKitUIBridgeService = callKitUIBridgeService,
enableReport = enableReport,
pushConfigProviderForGroup = pushConfigProviderForGroup,
callExtension = callExtension,
soundHelper = soundHelper,
Expand All @@ -254,13 +269,16 @@ class CallKitUIOptions constructor(
joinRtcWhenCall = joinRtcWhenCall,
audio2Video = audio2Video,
video2Audio = video2Audio,
enableGroup = enableGroup
enableGroup = enableGroup,
language = language,
framework = framework,
channel = channel
)
}
}

override fun toString(): String {
return "CallKitUIOptions(currentUserAccId='$currentUserAccId', currentUserRtcUId=$currentUserRtcUId, timeOutMillisecond=$timeOutMillisecond, resumeBGInvitation=$resumeBGInvitation, rtcConfig=$rtcConfig, activityConfig=$activityConfig, uiHelper=$uiHelper, notificationConfigFetcher=$notificationConfigFetcher, notificationConfigFetcherForGroup=$notificationConfigFetcherForGroup, userInfoHelper=$userInfoHelper, incomingCallEx=$incomingCallEx, callKitUIBridgeService=$callKitUIBridgeService, enableReport=$enableReport, pushConfigProviderForGroup=$pushConfigProviderForGroup, callExtension=$callExtension, soundHelper=$soundHelper, enableOrder=$enableOrder, enableAutoJoinWhenCalled=$enableAutoJoinWhenCalled, initRtcMode=$initRtcMode, joinRtcWhenCall=$joinRtcWhenCall, audio2Video=$audio2Video, video2Audio=$video2Audio, enableGroup=$enableGroup)"
return "CallKitUIOptions(currentUserAccId='$currentUserAccId', currentUserRtcUId=$currentUserRtcUId, timeOutMillisecond=$timeOutMillisecond, resumeBGInvitation=$resumeBGInvitation, rtcConfig=$rtcConfig, activityConfig=$activityConfig, uiHelper=$uiHelper, notificationConfigFetcher=$notificationConfigFetcher, notificationConfigFetcherForGroup=$notificationConfigFetcherForGroup, userInfoHelper=$userInfoHelper, incomingCallEx=$incomingCallEx, callKitUIBridgeService=$callKitUIBridgeService, pushConfigProviderForGroup=$pushConfigProviderForGroup, callExtension=$callExtension, soundHelper=$soundHelper, enableOrder=$enableOrder, enableAutoJoinWhenCalled=$enableAutoJoinWhenCalled, initRtcMode=$initRtcMode, joinRtcWhenCall=$joinRtcWhenCall, audio2Video=$audio2Video, video2Audio=$video2Audio, enableGroup=$enableGroup, language=$language, framework=$framework, channel=$channel)"
}
}

Expand Down Expand Up @@ -310,3 +328,9 @@ class CallKitNotificationConfig @JvmOverloads constructor(
return "CallKitNotificationConfig(notificationIconRes=$notificationIconRes, channelId=$channelId, title=$title, content=$content)"
}
}

enum class NECallUILanguage(val language: String) {
AUTO(LanguageType.LANGUAGE_SYSTEM),
ZH_HANS(LanguageType.LANGUAGE_ZH_CN),
EN(LanguageType.LANGUAGE_EN)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ import android.content.Context

interface UserInfoHelper {

/**
* 用户根据 accId 内容,利用 notify 接口将用户昵称通知组件
*/
fun fetchNickname(accId: String, notify: ((String) -> Unit)): Boolean

/**
* 用户根据 accId 内容,利用 notify 接口个将用户的头像链接通知组件,
* notify 中的两个字段其中一个为头像的url,另一个为加载头像失败后展示占位的本地资源 id
*/
fun fetchAvatar(context: Context, accId: String, notify: (String?, Int?) -> Unit): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class DefaultFloatingTouchEventStrategy(
* 属性动画更新监听
*/
private val updateListener = object : ValueAnimator.AnimatorUpdateListener {
override fun onAnimationUpdate(animation: ValueAnimator?) {
override fun onAnimationUpdate(animation: ValueAnimator) {
animation ?: return
(animation.animatedValue as? Int)?.run {
windowWrapper?.updateWindowParamsPos(xPos = this)
Expand All @@ -191,20 +191,20 @@ class DefaultFloatingTouchEventStrategy(
* 动画状态监听
*/
private val animatorListener = object : Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator?) {
override fun onAnimationStart(animation: Animator) {
}

override fun onAnimationEnd(animation: Animator?) {
override fun onAnimationEnd(animation: Animator) {
ALog.d(logTag, "onAnimationEnd")
finish()
}

override fun onAnimationCancel(animation: Animator?) {
override fun onAnimationCancel(animation: Animator) {
ALog.d(logTag, "onAnimationCancel")
finish()
}

override fun onAnimationRepeat(animation: Animator?) {
override fun onAnimationRepeat(animation: Animator) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class GroupVideoViewPool {
videoView1 = queue.poll()
}
if (videoView1 == null) {
videoView1 = NERtcVideoView(context).apply {
videoView1 = NERtcVideoView(context!!).apply {
setZOrderMediaOverlay(true)
layoutParams = ViewGroup.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,32 +407,45 @@ object CallUIOperationsMgr {
action.invoke()
return
}
ALog.dApi(TAG, ParameterMap("doConfigSpeaker").append("enableSpeaker", enableSpeaker))
ALog.d(
TAG,
ParameterMap("doConfigSpeaker").append("enableSpeaker", enableSpeaker).toString()
)
(context.getSystemService(Context.AUDIO_SERVICE) as AudioManager).run {
@Suppress("DEPRECATION")
if (isBluetoothA2dpOn) {
startBluetoothSco()
return
}
}
if (!callInfoWithUIState.callParam.isCalled && CallKitUI.options?.joinRtcWhenCall != true && currentCallState() != CallState.STATE_DIALOG) {
(context.getSystemService(Context.AUDIO_SERVICE) as AudioManager).run {
if (enableSpeaker) {
mode = AudioManager.MODE_NORMAL
isSpeakerphoneOn = true

if (CallKitUI.options?.joinRtcWhenCall != true) {
enableSystemSpeaker(enableSpeaker)
}
action.invoke()
}

private fun enableSystemSpeaker(enableSpeaker: Boolean) {
ALog.d(
TAG,
ParameterMap("enableSystemSpeaker").append("enableSpeaker", enableSpeaker).toString()
)
(context.getSystemService(Context.AUDIO_SERVICE) as AudioManager).run {
if (enableSpeaker) {
mode = AudioManager.MODE_NORMAL
isSpeakerphoneOn = true
} else {
// 兼容高版本 sdk
@SuppressLint("ObsoleteSdkInt")
mode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
AudioManager.MODE_IN_COMMUNICATION
} else {
// 兼容高版本 sdk
@SuppressLint("ObsoleteSdkInt")
mode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
AudioManager.MODE_IN_COMMUNICATION
} else {
AudioManager.MODE_IN_CALL
}
isSpeakerphoneOn = false
AudioManager.MODE_IN_CALL
}
isSpeakerphoneOn = false
}
callInfoWithUIState.isLocalMuteSpeaker = !enableSpeaker
}
action.invoke()
}

/**
Expand Down Expand Up @@ -608,15 +621,18 @@ object CallUIOperationsMgr {
var isRemoteMuteVideo: Boolean = false,
var isLocalMuteVideo: Boolean = false,
var isLocalMuteAudio: Boolean = false,
var isLocalMuteSpeaker: Boolean = (
CallKitUI.baseContext()
?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
)?.isSpeakerphoneOn
?: !NERtcEx.getInstance().isSpeakerphoneOn,
var isLocalMuteSpeaker: Boolean = initializeSpeakerphoneStatus(),
var cameraDeviceStatus: Int = NERtcConstants.VideoDeviceState.OPENED,
var isLocalSmallVideo: Boolean = true,
var isVirtualBlur: Boolean = false
) {
companion object {
private fun initializeSpeakerphoneStatus(): Boolean {
val audioManager = CallKitUI.baseContext()?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
return audioManager?.isSpeakerphoneOn?.not() ?: !NERtcEx.getInstance().isSpeakerphoneOn
}
}

val callState: Int
get() = callEngine.callInfo.callStatus

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ open class AudioCalleeFragment : BaseP2pCallFragment() {
}

override fun toUpdateUIState(type: Int) {
bridge.doConfigSpeaker(false)
bridge.doConfigSpeaker(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ open class AudioOnTheCallFragment : BaseP2pCallFragment() {
override fun toUpdateUIState(type: Int) {
when (type) {
INIT -> {
bridge.doConfigSpeaker(!bridge.isLocalMuteSpeaker)
bridge.doConfigSpeaker(false)
getView<ImageView>(viewKeyImageSpeaker)?.run {
setImageResource(
if (bridge.isSpeakerOn()) R.drawable.speaker_on else R.drawable.speaker_off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsTranslucent">false</item>
</style>

<style name="Base_Theme_AppCompat_Empty" />
</resources>
Loading

0 comments on commit 46945f5

Please sign in to comment.