Commit 82809e56 by 严久程

声网流程优化

parent 3072a1cf
...@@ -611,17 +611,9 @@ class AudioHomeActivity : ...@@ -611,17 +611,9 @@ class AudioHomeActivity :
writeAgoraLog("未接通挂断:60s等待倒计时结束挂断") writeAgoraLog("未接通挂断:60s等待倒计时结束挂断")
//提示切换传统线路 //提示切换传统线路
//发送消息通知专家用户已挂断 //发送消息通知专家用户已挂断
YDLRTMClient.instances.cancelCall( YDLavManager.instances.cancelCall( listenerUid!!, channelId!!){msg,code->
listenerUid, writeAgoraLog("未接听时:主叫主动挂断失败,msg=$msg($code),再次挂断")
channelId,
object : CancelCallStatusListener {
override fun onFailure(errorMsg: String?, errorCode: Int) {
YDLRTMClient.instances.cancelCall(listenerUid, channelId, null)
}
override fun onSuccess() {
} }
})
//通话结束或挂断时,上传日志文件 //通话结束或挂断时,上传日志文件
uploadLog() uploadLog()
...@@ -673,18 +665,9 @@ class AudioHomeActivity : ...@@ -673,18 +665,9 @@ class AudioHomeActivity :
writeAgoraLog("未接听时:主叫主动挂断,取消呼叫") writeAgoraLog("未接听时:主叫主动挂断,取消呼叫")
LogUtil.e("未接听挂断") LogUtil.e("未接听挂断")
//发送消息通知专家用户已挂断 //发送消息通知专家用户已挂断
YDLRTMClient.instances.cancelCall( YDLavManager.instances.cancelCall( listenerUid!!, channelId!!){msg,code->
listenerUid, writeAgoraLog("未接听时:主叫主动挂断失败,msg=$msg($code),再次挂断")
channelId,
object : CancelCallStatusListener {
override fun onFailure(errorMsg: String?, errorCode: Int) {
writeAgoraLog("未接听时:主叫主动挂断失败,msg=$errorMsg($errorCode),再次挂断")
YDLRTMClient.instances.cancelCall(listenerUid, channelId, null)
}
override fun onSuccess() {
} }
})
//通话结束或挂断时,上传日志文件 //通话结束或挂断时,上传日志文件
uploadLog() uploadLog()
handler!!.postDelayed({ handler!!.postDelayed({
...@@ -776,17 +759,9 @@ class AudioHomeActivity : ...@@ -776,17 +759,9 @@ class AudioHomeActivity :
//未连接成功,切换axb时:需发送消息通知专家端用户已挂断 //未连接成功,切换axb时:需发送消息通知专家端用户已挂断
//发送消息通知专家用户已挂断 //发送消息通知专家用户已挂断
//发送消息通知专家用户已挂断 //发送消息通知专家用户已挂断
YDLRTMClient.instances.cancelCall( YDLavManager.instances.cancelCall( listenerUid!!, channelId!!){msg,code->
listenerUid, writeAgoraLog("未接听时:主叫主动挂断失败,msg=$msg($code),再次挂断")
channelId,
object : CancelCallStatusListener {
override fun onFailure(errorMsg: String?, errorCode: Int) {
YDLRTMClient.instances.cancelCall(listenerUid, channelId, null)
} }
override fun onSuccess() {
}
})
leaveChannel() leaveChannel()
} }
} }
......
...@@ -13,6 +13,7 @@ import com.ydl.consultantim.ConsultantAudioHomeActivity ...@@ -13,6 +13,7 @@ import com.ydl.consultantim.ConsultantAudioHomeActivity
import com.ydl.ydl_av.messge_service.YDLRTMClient import com.ydl.ydl_av.messge_service.YDLRTMClient
import com.ydl.ydl_av.messge_service.bean.RTMMesssage import com.ydl.ydl_av.messge_service.bean.RTMMesssage
import com.ydl.ydl_av.messge_service.callback.CallListener import com.ydl.ydl_av.messge_service.callback.CallListener
import com.ydl.ydl_av.messge_service.callback.CancelCallStatusListener
import com.ydl.ydl_av.messge_service.callback.InitListener import com.ydl.ydl_av.messge_service.callback.InitListener
import com.ydl.ydl_av.messge_service.callback.LoginCallback import com.ydl.ydl_av.messge_service.callback.LoginCallback
import com.ydl.ydl_av.messge_service.request.LoginParam import com.ydl.ydl_av.messge_service.request.LoginParam
...@@ -23,9 +24,9 @@ import com.ydl.ydlcommon.utils.ActivityManager ...@@ -23,9 +24,9 @@ import com.ydl.ydlcommon.utils.ActivityManager
import com.ydl.ydlcommon.utils.LogUtil import com.ydl.ydlcommon.utils.LogUtil
import com.ydl.ydlcommon.utils.log.LogHelper import com.ydl.ydlcommon.utils.log.LogHelper
import com.yidianling.common.tools.ToastUtil import com.yidianling.common.tools.ToastUtil
import com.yidianling.im.api.bean.IMRegisterObserverCustomNotificationCallBack
import com.yidianling.user.api.event.UserLoginEvent import com.yidianling.user.api.event.UserLoginEvent
import com.yidianling.user.api.event.UserLogoutEvent import com.yidianling.user.api.event.UserLogoutEvent
import com.yidianling.im.api.bean.IMRegisterObserverCustomNotificationCallBack
import com.yidianling.user.api.service.IUserService import com.yidianling.user.api.service.IUserService
import de.greenrobot.event.EventBus import de.greenrobot.event.EventBus
import io.agora.rtm.RtmStatusCode import io.agora.rtm.RtmStatusCode
...@@ -41,7 +42,6 @@ import java.util.concurrent.TimeUnit ...@@ -41,7 +42,6 @@ import java.util.concurrent.TimeUnit
*/ */
class YDLavManager { class YDLavManager {
companion object { companion object {
const val FILE_NAME = "consult" const val FILE_NAME = "consult"
//当前sdk的登录状态 //当前sdk的登录状态
...@@ -54,8 +54,8 @@ class YDLavManager { ...@@ -54,8 +54,8 @@ class YDLavManager {
private constructor() private constructor()
fun init(context: Context,appId:String){ fun init(context: Context, appId: String) {
YDLRTMClient.instances.init(context,appId,listener) YDLRTMClient.instances.init(context, appId, listener)
EventBus.getDefault().register(this) EventBus.getDefault().register(this)
//设置回调 //设置回调
setCallback() setCallback()
...@@ -76,6 +76,7 @@ class YDLavManager { ...@@ -76,6 +76,7 @@ class YDLavManager {
public fun onEvent(event: UserLogoutEvent) { public fun onEvent(event: UserLogoutEvent) {
instances.logout() instances.logout()
} }
private fun setCallback() { private fun setCallback() {
YDLRTMClient.instances.setCallListener(object : CallListener { YDLRTMClient.instances.setCallListener(object : CallListener {
override fun onCallRecivedByPeer(response: CallLocalResponse?) { override fun onCallRecivedByPeer(response: CallLocalResponse?) {
...@@ -88,7 +89,6 @@ class YDLavManager { ...@@ -88,7 +89,6 @@ class YDLavManager {
act.playWaitingMusic() act.playWaitingMusic()
} }
} }
} }
override fun onCallAccepted(response: CallLocalResponse?, msg: String?) { override fun onCallAccepted(response: CallLocalResponse?, msg: String?) {
...@@ -118,8 +118,6 @@ class YDLavManager { ...@@ -118,8 +118,6 @@ class YDLavManager {
act.leaveChannel() act.leaveChannel()
} }
} }
} }
override fun onCallCanceled(response: CallLocalResponse?) { override fun onCallCanceled(response: CallLocalResponse?) {
...@@ -151,9 +149,6 @@ class YDLavManager { ...@@ -151,9 +149,6 @@ class YDLavManager {
if (act is AudioHomeActivity) { if (act is AudioHomeActivity) {
act.runOnUiThread { act.runOnUiThread {
act.writeAgoraLog("呼叫失败:${errorCode}") act.writeAgoraLog("呼叫失败:${errorCode}")
// //通话结束或挂断时,上传日志文件
// act.uploadLog()
// act.leaveChannel()
} }
} }
} }
...@@ -200,9 +195,9 @@ class YDLavManager { ...@@ -200,9 +195,9 @@ class YDLavManager {
} }
}) })
AudioImIn.registerObserveCustomNotification(object : IMRegisterObserverCustomNotificationCallBack { AudioImIn.registerObserveCustomNotification(object :
IMRegisterObserverCustomNotificationCallBack {
override fun onObserverCustomNotification(content: String) { override fun onObserverCustomNotification(content: String) {
} }
}) })
} }
...@@ -211,15 +206,24 @@ class YDLavManager { ...@@ -211,15 +206,24 @@ class YDLavManager {
YDLRTMClient.instances.call(listenerUid, channelId, sendDoctocrMsg) YDLRTMClient.instances.call(listenerUid, channelId, sendDoctocrMsg)
} }
fun cancelCall() fun cancelCall(listenerUid: String, channelId: String, event: (msg: String?, code: Int) -> Unit) {
YDLRTMClient.instances.cancelCall(listenerUid, channelId,
object : CancelCallStatusListener {
override fun onFailure(errorMsg: String?, errorCode: Int) {
event(errorMsg, errorCode)
YDLRTMClient.instances.cancelCall(listenerUid, channelId, null)
}
override fun onSuccess() {
}
})
}
fun login(userId: String?) { fun login(userId: String?) {
login(userId) { _, _ -> login(userId) { _, _ ->
} }
} }
@SuppressLint("CheckResult") @SuppressLint("CheckResult")
fun login(userId: String?, event: (isSuccess: Boolean, msg: String?) -> Unit) { fun login(userId: String?, event: (isSuccess: Boolean, msg: String?) -> Unit) {
if (TextUtils.isEmpty(userId) || userId ?: "0" <= "0") { if (TextUtils.isEmpty(userId) || userId ?: "0" <= "0") {
...@@ -229,10 +233,13 @@ class YDLavManager { ...@@ -229,10 +233,13 @@ class YDLavManager {
} }
//登录实时消息 //登录实时消息
//获取token //获取token
AudioApiRequestUtil.getAgoraToken().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe({ AudioApiRequestUtil.getAgoraToken().subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).subscribe({
if ("200".equals(it.code)) { if ("200".equals(it.code)) {
LogUtil.e("[agora]登录av的login-uid:$userId") LogUtil.e("[agora]登录av的login-uid:$userId")
YDLRTMClient.instances.login(LoginParam(userId, it.data.token), object : LoginCallback { YDLRTMClient.instances.login(
LoginParam(userId, it.data.token),
object : LoginCallback {
override fun onSuccess() { override fun onSuccess() {
//登陆成功,发起呼叫 //登陆成功,发起呼叫
LogUtil.e("[agora]实时消息登录成功") LogUtil.e("[agora]实时消息登录成功")
...@@ -243,18 +250,17 @@ class YDLavManager { ...@@ -243,18 +250,17 @@ class YDLavManager {
LogUtil.e("[agora]实时消息登录失败:$msg") LogUtil.e("[agora]实时消息登录失败:$msg")
event(false, msg) event(false, msg)
} }
}) })
} else { } else {
LogUtil.e("声网token获取失败uid:" + userId + " error:" + it.msg) LogUtil.e("声网token获取失败uid:" + userId + " error:" + it.msg)
LogHelper.getInstance().writeLogSync("声网token获取失败uid:" + userId + " error:" + it.msg) LogHelper.getInstance()
.writeLogSync("声网token获取失败uid:" + userId + " error:" + it.msg)
} }
}, { }, {
LogUtil.e("声网token获取异常uid:" + userId + " error:" + it.message) LogUtil.e("声网token获取异常uid:" + userId + " error:" + it.message)
}) })
} }
/** /**
* 收到邀请 * 收到邀请
*/ */
...@@ -262,12 +268,17 @@ class YDLavManager { ...@@ -262,12 +268,17 @@ class YDLavManager {
fun receivedCall(content: String?, from: String = "") { fun receivedCall(content: String?, from: String = "") {
if (!TextUtils.isEmpty(content)) { if (!TextUtils.isEmpty(content)) {
//如果已经接听了用户电话 再有电话进来 是不能接听的 //如果已经接听了用户电话 再有电话进来 是不能接听的
if (!activityIsExists(ConsultantAudioHomeActivity::class.java) && !activityIsExists(AudioHomeActivity::class.java)) { if (!activityIsExists(ConsultantAudioHomeActivity::class.java) && !activityIsExists(
AudioHomeActivity::class.java
)
) {
//延时启动通话界面,防止刚打开就被main遮挡 //延时启动通话界面,防止刚打开就被main遮挡
Observable.timer(1000, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe { Observable.timer(1000, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).subscribe {
LogUtil.e("[agora]启动通话界面") LogUtil.e("[agora]启动通话界面")
//邀请加入频道消息,跳转通话界面 //邀请加入频道消息,跳转通话界面
ARouter.getInstance().build("/av/ConsultantAudioHomeActivity").withString("param", content).navigation() ARouter.getInstance().build("/av/ConsultantAudioHomeActivity")
.withString("param", content).navigation()
AudioLogUtils.writeAgoraLog("收到主叫方通话邀请($from)", FILE_NAME, false) AudioLogUtils.writeAgoraLog("收到主叫方通话邀请($from)", FILE_NAME, false)
} }
...@@ -279,7 +290,6 @@ class YDLavManager { ...@@ -279,7 +290,6 @@ class YDLavManager {
} }
} }
private fun activityIsExists(cls: Class<*>): Boolean { private fun activityIsExists(cls: Class<*>): Boolean {
for (activity in ActivityManager.getInstance().getActivitys()) { for (activity in ActivityManager.getInstance().getActivitys()) {
if (activity.javaClass == cls) { if (activity.javaClass == cls) {
...@@ -289,7 +299,6 @@ class YDLavManager { ...@@ -289,7 +299,6 @@ class YDLavManager {
return false return false
} }
/** /**
* 关闭通话界面 * 关闭通话界面
*/ */
...@@ -303,11 +312,10 @@ class YDLavManager { ...@@ -303,11 +312,10 @@ class YDLavManager {
} }
} }
/** /**
* 退出登录 * 退出登录
*/ */
fun logout(){ fun logout() {
EventBus.getDefault().unregister(this) EventBus.getDefault().unregister(this)
YDLRTMClient.instances.logout(object : LoginCallback { YDLRTMClient.instances.logout(object : LoginCallback {
override fun onSuccess() { override fun onSuccess() {
...@@ -318,7 +326,6 @@ class YDLavManager { ...@@ -318,7 +326,6 @@ class YDLavManager {
override fun onFailure(msg: String?) { override fun onFailure(msg: String?) {
LogUtil.d("[agora]实时消息退出失败:$msg") LogUtil.d("[agora]实时消息退出失败:$msg")
} }
}) })
} }
...@@ -327,9 +334,10 @@ class YDLavManager { ...@@ -327,9 +334,10 @@ class YDLavManager {
* 声网出现异常,上传错误日志 connectException * 声网出现异常,上传错误日志 connectException
*/ */
@SuppressLint("CheckResult") @SuppressLint("CheckResult")
fun uploadException(connectException: ConnectExceptionCommand, callback: UploadExceptionCallback?) { fun uploadException(connectException: ConnectExceptionCommand,
AudioApiRequestUtil.connectException(connectException).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) callback: UploadExceptionCallback?) {
AudioApiRequestUtil.connectException(connectException).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
callback?.onSuccess() callback?.onSuccess()
}, { }, {
...@@ -347,7 +355,7 @@ class YDLavManager { ...@@ -347,7 +355,7 @@ class YDLavManager {
/** /**
* 实时消息全局监听 * 实时消息全局监听
*/ */
private val listener = object :InitListener{ private val listener = object : InitListener {
override fun onTokenExpired() { override fun onTokenExpired() {
LogUtil.e("[agora]onTokenExpired") LogUtil.e("[agora]onTokenExpired")
...@@ -362,6 +370,5 @@ class YDLavManager { ...@@ -362,6 +370,5 @@ class YDLavManager {
sdkStatus = state sdkStatus = state
LogUtil.i("[agora]onConnectionStateChanged:state:${state} -->reason:$reason") LogUtil.i("[agora]onConnectionStateChanged:state:${state} -->reason:$reason")
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment