Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨凯
YDL-Component-Medical
Commits
82809e56
Commit
82809e56
authored
Apr 23, 2020
by
严久程
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
声网流程优化
parent
3072a1cf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
321 additions
and
338 deletions
+321
-338
AudioHomeActivity.kt
m-audioim/src/main/java/com/ydl/audioim/AudioHomeActivity.kt
+9
-34
YDLavManager.kt
m-audioim/src/main/java/com/ydl/audioim/YDLavManager.kt
+312
-304
No files found.
m-audioim/src/main/java/com/ydl/audioim/AudioHomeActivity.kt
View file @
82809e56
...
@@ -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
()
}
}
}
}
...
...
m-audioim/src/main/java/com/ydl/audioim/YDLavManager.kt
View file @
82809e56
...
@@ -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,327 +42,333 @@ import java.util.concurrent.TimeUnit
...
@@ -41,327 +42,333 @@ import java.util.concurrent.TimeUnit
*/
*/
class
YDLavManager
{
class
YDLavManager
{
companion
object
{
const
val
FILE_NAME
=
"consult"
//当前sdk的登录状态
var
sdkStatus
=
-
1
companion
object
{
val
instances
:
YDLavManager
by
lazy
(
mode
=
LazyThreadSafetyMode
.
SYNCHRONIZED
)
{
const
val
FILE_NAME
=
"consult"
YDLavManager
()
//当前sdk的登录状态
var
sdkStatus
=
-
1
val
instances
:
YDLavManager
by
lazy
(
mode
=
LazyThreadSafetyMode
.
SYNCHRONIZED
)
{
YDLavManager
()
}
}
private
constructor
()
fun
init
(
context
:
Context
,
appId
:
String
){
YDLRTMClient
.
instances
.
init
(
context
,
appId
,
listener
)
EventBus
.
getDefault
().
register
(
this
)
//设置回调
setCallback
()
val
uid
=
ModularServiceManager
.
provide
(
IUserService
::
class
.
java
).
getUserInfo
()
?.
uid
if
(!
TextUtils
.
isEmpty
(
uid
)
&&
!
TextUtils
.
equals
(
"0"
,
uid
))
{
//不延时,可能会导致请求api报 network not unablibale
Handler
().
postDelayed
({
login
(
uid
)
},
300
)
}
}
public
fun
onEvent
(
event
:
UserLoginEvent
)
{
instances
.
login
(
event
.
uid
)
}
public
fun
onEvent
(
event
:
UserLogoutEvent
)
{
instances
.
logout
()
}
private
fun
setCallback
()
{
YDLRTMClient
.
instances
.
setCallListener
(
object
:
CallListener
{
override
fun
onCallRecivedByPeer
(
response
:
CallLocalResponse
?)
{
//返回给主叫:被叫已收到呼叫邀请
LogUtil
.
e
(
"[agora]${response?.calleeId}已收到呼叫邀请,频道号${response?.ChannelId}"
)
val
act
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
if
(
act
is
AudioHomeActivity
)
{
act
.
runOnUiThread
{
act
.
playWaitingMusic
()
}
}
}
override
fun
onCallAccepted
(
response
:
CallLocalResponse
?,
msg
:
String
?)
{
//返回给主叫
LogUtil
.
e
(
"[agora]${response?.calleeId}已接收呼叫邀请"
)
//加入声网频道时机修改:用户收到专家接受邀请的回调后再加入声网频道
val
act
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
if
(
act
is
AudioHomeActivity
)
{
act
.
runOnUiThread
{
act
.
joinChannel
()
}
}
}
override
fun
onCallRefused
(
response
:
CallLocalResponse
?,
msg
:
String
?)
{
//返回给主叫
LogUtil
.
e
(
"[agora]${response?.calleeId}已拒绝呼叫邀请"
)
val
act
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
if
(
act
is
AudioHomeActivity
)
{
act
.
runOnUiThread
{
ToastUtil
.
toastShort
(
"对方已挂断"
)
act
.
writeAgoraLog
(
"被叫拒绝了通话邀请"
)
//通话结束或挂断时,上传日志文件
act
.
uploadLog
()
act
.
leaveChannel
()
}
}
}
override
fun
onCallCanceled
(
response
:
CallLocalResponse
?)
{
//返回给主叫
LogUtil
.
e
(
"[agora]主叫已取消呼叫邀请"
)
val
act
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
if
(
act
is
AudioHomeActivity
)
{
act
.
runOnUiThread
{
act
.
writeAgoraLog
(
"主叫呼叫取消:超时或主动取消"
)
}
}
}
override
fun
onCallFailure
(
response
:
CallLocalResponse
?,
errorCode
:
Int
)
{
//返回给主叫
LogUtil
.
e
(
"[agora]呼叫${response?.calleeId}用户失败:${response?.response}"
)
val
act
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
//专家离线或者30 秒后仍未收到专家响应,重新再邀请一次
when
(
errorCode
)
{
//被叫不在线 呼叫邀请发出 30 秒后被叫仍未 ACK 响应呼叫邀请
RtmStatusCode
.
LocalInvitationError
.
LOCAL_INVITATION_ERR_PEER_OFFLINE
,
RtmStatusCode
.
LocalInvitationError
.
LOCAL_INVITATION_ERR_PEER_NO_RESPONSE
->
{
if
(
act
is
AudioHomeActivity
)
{
act
.
runOnUiThread
{
act
.
rtcCall
()
}
}
}
RtmStatusCode
.
LocalInvitationError
.
LOCAL_INVITATION_ERR_INVITATION_EXPIRE
->
{
//呼叫邀请过期。被叫 ACK 响应呼叫邀请后 60 秒呼叫邀请未被取消、接受、拒绝,则呼叫邀请过期。
if
(
act
is
AudioHomeActivity
)
{
act
.
runOnUiThread
{
act
.
writeAgoraLog
(
"呼叫失败:${errorCode}"
)
// //通话结束或挂断时,上传日志文件
// act.uploadLog()
// act.leaveChannel()
}
}
}
}
}
override
fun
onRemoteInvitationReceived
(
response
:
CallRemoteResponse
?)
{
//返回给被叫
LogUtil
.
e
(
"[agora]收到来自${response?.callerId}的呼叫邀请"
)
receivedCall
(
response
?.
content
,
"来自RTM"
)
}
override
fun
onRemoteInvitationAccepted
(
response
:
CallRemoteResponse
?)
{
//返回给被叫
LogUtil
.
e
(
"[agora]接受来自${response?.callerId}的呼叫成功"
)
}
override
fun
onRemoteInvitationRefused
(
response
:
CallRemoteResponse
?)
{
//返回给被叫
LogUtil
.
e
(
"[agora]已拒绝来自${response?.callerId}的呼叫"
)
}
override
fun
onRemoteInvitationCanceled
(
response
:
CallRemoteResponse
?)
{
//返回给被叫
LogUtil
.
e
(
"[agora]主叫${response?.callerId}已取消呼叫邀请"
)
AudioLogUtils
.
writeAgoraLog
(
"呼叫邀请被取消:主叫主动取消"
,
FILE_NAME
)
closePage
()
}
override
fun
onRemoteInvitationFailure
(
response
:
CallRemoteResponse
?,
errorCode
:
Int
)
{
//返回给被叫
LogUtil
.
e
(
"[agora]来自主叫${response?.callerId}的呼叫邀请进程失败:${response?.response}"
)
if
(
errorCode
==
RtmStatusCode
.
RemoteInvitationError
.
REMOTE_INVITATION_ERR_INVITATION_EXPIRE
)
{
//呼叫邀请过期
AudioLogUtils
.
writeAgoraLog
(
"呼叫邀请被取消:呼叫邀请过期"
,
FILE_NAME
)
}
else
{
AudioLogUtils
.
writeAgoraLog
(
"呼叫邀请被取消:错误原因(${errorCode})"
,
FILE_NAME
)
}
//关闭页面
closePage
()
}
override
fun
onOtherMsg
(
error
:
String
?)
{
LogUtil
.
e
(
"[agora]其它消息:${error}"
)
}
})
AudioImIn
.
registerObserveCustomNotification
(
object
:
IMRegisterObserverCustomNotificationCallBack
{
override
fun
onObserverCustomNotification
(
content
:
String
)
{
}
})
}
}
}
fun
rtcCall
(
listenerUid
:
String
?,
channelId
:
String
?,
sendDoctocrMsg
:
String
?)
{
YDLRTMClient
.
instances
.
call
(
listenerUid
,
channelId
,
sendDoctocrMsg
)
private
constructor
()
fun
init
(
context
:
Context
,
appId
:
String
)
{
YDLRTMClient
.
instances
.
init
(
context
,
appId
,
listener
)
EventBus
.
getDefault
().
register
(
this
)
//设置回调
setCallback
()
val
uid
=
ModularServiceManager
.
provide
(
IUserService
::
class
.
java
).
getUserInfo
()
?.
uid
if
(!
TextUtils
.
isEmpty
(
uid
)
&&
!
TextUtils
.
equals
(
"0"
,
uid
))
{
//不延时,可能会导致请求api报 network not unablibale
Handler
().
postDelayed
({
login
(
uid
)
},
300
)
}
}
}
fun
cancelCall
()
public
fun
onEvent
(
event
:
UserLoginEvent
)
{
instances
.
login
(
event
.
uid
)
fun
login
(
userId
:
String
?)
{
}
login
(
userId
)
{
_
,
_
->
public
fun
onEvent
(
event
:
UserLogoutEvent
)
{
instances
.
logout
()
}
private
fun
setCallback
()
{
YDLRTMClient
.
instances
.
setCallListener
(
object
:
CallListener
{
override
fun
onCallRecivedByPeer
(
response
:
CallLocalResponse
?)
{
//返回给主叫:被叫已收到呼叫邀请
LogUtil
.
e
(
"[agora]${response?.calleeId}已收到呼叫邀请,频道号${response?.ChannelId}"
)
val
act
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
if
(
act
is
AudioHomeActivity
)
{
act
.
runOnUiThread
{
act
.
playWaitingMusic
()
}
}
}
}
}
override
fun
onCallAccepted
(
response
:
CallLocalResponse
?,
msg
:
String
?)
{
@SuppressLint
(
"CheckResult"
)
//返回给主叫
fun
login
(
userId
:
String
?,
event
:
(
isSuccess
:
Boolean
,
msg
:
String
?)
->
Unit
)
{
LogUtil
.
e
(
"[agora]${response?.calleeId}已接收呼叫邀请"
)
if
(
TextUtils
.
isEmpty
(
userId
)
||
userId
?:
"0"
<=
"0"
)
{
//如果uid为空或小于等于0 ,则不进行登录,因为uid为0也会登录成功,会导致后面uid正确时无法登录
//加入声网频道时机修改:用户收到专家接受邀请的回调后再加入声网频道
LogUtil
.
e
(
"[agora]login-uid:$userId"
)
val
act
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
return
if
(
act
is
AudioHomeActivity
)
{
act
.
runOnUiThread
{
act
.
joinChannel
()
}
}
}
//登录实时消息
}
//获取token
AudioApiRequestUtil
.
getAgoraToken
().
subscribeOn
(
Schedulers
.
io
()).
observeOn
(
AndroidSchedulers
.
mainThread
()).
subscribe
({
override
fun
onCallRefused
(
response
:
CallLocalResponse
?,
msg
:
String
?)
{
if
(
"200"
.
equals
(
it
.
code
))
{
//返回给主叫
LogUtil
.
e
(
"[agora]登录av的login-uid:$userId"
)
LogUtil
.
e
(
"[agora]${response?.calleeId}已拒绝呼叫邀请"
)
YDLRTMClient
.
instances
.
login
(
LoginParam
(
userId
,
it
.
data
.
token
),
object
:
LoginCallback
{
override
fun
onSuccess
()
{
val
act
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
//登陆成功,发起呼叫
if
(
act
is
AudioHomeActivity
)
{
LogUtil
.
e
(
"[agora]实时消息登录成功"
)
act
.
runOnUiThread
{
event
(
true
,
""
)
ToastUtil
.
toastShort
(
"对方已挂断"
)
}
act
.
writeAgoraLog
(
"被叫拒绝了通话邀请"
)
//通话结束或挂断时,上传日志文件
override
fun
onFailure
(
msg
:
String
?)
{
act
.
uploadLog
()
LogUtil
.
e
(
"[agora]实时消息登录失败:$msg"
)
act
.
leaveChannel
()
event
(
false
,
msg
)
}
}
}
}
})
}
else
{
override
fun
onCallCanceled
(
response
:
CallLocalResponse
?)
{
LogUtil
.
e
(
"声网token获取失败uid:"
+
userId
+
" error:"
+
it
.
msg
)
//返回给主叫
LogHelper
.
getInstance
().
writeLogSync
(
"声网token获取失败uid:"
+
userId
+
" error:"
+
it
.
msg
)
LogUtil
.
e
(
"[agora]主叫已取消呼叫邀请"
)
}
val
act
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
},
{
if
(
act
is
AudioHomeActivity
)
{
LogUtil
.
e
(
"声网token获取异常uid:"
+
userId
+
" error:"
+
it
.
message
)
act
.
runOnUiThread
{
})
act
.
writeAgoraLog
(
"主叫呼叫取消:超时或主动取消"
)
}
}
}
}
/**
* 收到邀请
override
fun
onCallFailure
(
response
:
CallLocalResponse
?,
errorCode
:
Int
)
{
*/
//返回给主叫
@SuppressLint
(
"CheckResult"
)
LogUtil
.
e
(
"[agora]呼叫${response?.calleeId}用户失败:${response?.response}"
)
fun
receivedCall
(
content
:
String
?,
from
:
String
=
""
)
{
val
act
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
if
(!
TextUtils
.
isEmpty
(
content
))
{
//专家离线或者30 秒后仍未收到专家响应,重新再邀请一次
//如果已经接听了用户电话 再有电话进来 是不能接听的
when
(
errorCode
)
{
if
(!
activityIsExists
(
ConsultantAudioHomeActivity
::
class
.
java
)
&&
!
activityIsExists
(
AudioHomeActivity
::
class
.
java
))
{
//被叫不在线 呼叫邀请发出 30 秒后被叫仍未 ACK 响应呼叫邀请
//延时启动通话界面,防止刚打开就被main遮挡
RtmStatusCode
.
LocalInvitationError
.
LOCAL_INVITATION_ERR_PEER_OFFLINE
,
RtmStatusCode
.
LocalInvitationError
.
LOCAL_INVITATION_ERR_PEER_NO_RESPONSE
->
{
Observable
.
timer
(
1000
,
TimeUnit
.
MILLISECONDS
).
subscribeOn
(
Schedulers
.
io
()).
observeOn
(
AndroidSchedulers
.
mainThread
()).
subscribe
{
if
(
act
is
AudioHomeActivity
)
{
LogUtil
.
e
(
"[agora]启动通话界面"
)
act
.
runOnUiThread
{
//邀请加入频道消息,跳转通话界面
act
.
rtcCall
()
ARouter
.
getInstance
().
build
(
"/av/ConsultantAudioHomeActivity"
).
withString
(
"param"
,
content
).
navigation
()
}
}
AudioLogUtils
.
writeAgoraLog
(
"收到主叫方通话邀请($from)"
,
FILE_NAME
,
false
)
}
}
RtmStatusCode
.
LocalInvitationError
.
LOCAL_INVITATION_ERR_INVITATION_EXPIRE
->
{
//呼叫邀请过期。被叫 ACK 响应呼叫邀请后 60 秒呼叫邀请未被取消、接受、拒绝,则呼叫邀请过期。
}
else
{
if
(
act
is
AudioHomeActivity
)
{
LogUtil
.
d
(
"[agora]收到声网邀请,但界面实例已存在"
)
act
.
runOnUiThread
{
act
.
writeAgoraLog
(
"呼叫失败:${errorCode}"
)
}
}
}
}
}
}
override
fun
onRemoteInvitationReceived
(
response
:
CallRemoteResponse
?)
{
//返回给被叫
LogUtil
.
e
(
"[agora]收到来自${response?.callerId}的呼叫邀请"
)
receivedCall
(
response
?.
content
,
"来自RTM"
)
}
override
fun
onRemoteInvitationAccepted
(
response
:
CallRemoteResponse
?)
{
//返回给被叫
LogUtil
.
e
(
"[agora]接受来自${response?.callerId}的呼叫成功"
)
}
override
fun
onRemoteInvitationRefused
(
response
:
CallRemoteResponse
?)
{
//返回给被叫
LogUtil
.
e
(
"[agora]已拒绝来自${response?.callerId}的呼叫"
)
}
override
fun
onRemoteInvitationCanceled
(
response
:
CallRemoteResponse
?)
{
//返回给被叫
LogUtil
.
e
(
"[agora]主叫${response?.callerId}已取消呼叫邀请"
)
AudioLogUtils
.
writeAgoraLog
(
"呼叫邀请被取消:主叫主动取消"
,
FILE_NAME
)
closePage
()
}
override
fun
onRemoteInvitationFailure
(
response
:
CallRemoteResponse
?,
errorCode
:
Int
)
{
//返回给被叫
LogUtil
.
e
(
"[agora]来自主叫${response?.callerId}的呼叫邀请进程失败:${response?.response}"
)
if
(
errorCode
==
RtmStatusCode
.
RemoteInvitationError
.
REMOTE_INVITATION_ERR_INVITATION_EXPIRE
)
{
//呼叫邀请过期
AudioLogUtils
.
writeAgoraLog
(
"呼叫邀请被取消:呼叫邀请过期"
,
FILE_NAME
)
}
else
{
}
else
{
LogUtil
.
d
(
"[agora]收到声网邀请,但response==null"
)
AudioLogUtils
.
writeAgoraLog
(
"呼叫邀请被取消:错误原因(${errorCode})"
,
FILE_NAME
)
}
}
}
//关闭页面
closePage
()
}
private
fun
activityIsExists
(
cls
:
Class
<*>):
Boolean
{
for
(
activity
in
ActivityManager
.
getInstance
().
getActivitys
())
{
override
fun
onOtherMsg
(
error
:
String
?)
{
if
(
activity
.
javaClass
==
cls
)
{
LogUtil
.
e
(
"[agora]其它消息:${error}"
)
return
true
}
}
})
AudioImIn
.
registerObserveCustomNotification
(
object
:
IMRegisterObserverCustomNotificationCallBack
{
override
fun
onObserverCustomNotification
(
content
:
String
)
{
}
})
}
fun
rtcCall
(
listenerUid
:
String
?,
channelId
:
String
?,
sendDoctocrMsg
:
String
?)
{
YDLRTMClient
.
instances
.
call
(
listenerUid
,
channelId
,
sendDoctocrMsg
)
}
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
)
}
}
return
false
}
override
fun
onSuccess
()
{
}
})
}
/**
fun
login
(
userId
:
String
?)
{
* 关闭通话界面
login
(
userId
)
{
_
,
_
->
*/
}
fun
closePage
()
{
}
var
act
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
if
(
act
is
ConsultantAudioHomeActivity
)
{
@SuppressLint
(
"CheckResult"
)
//未接通时,收到呼叫进程失败关闭页面,已接通无需关闭
fun
login
(
userId
:
String
?,
event
:
(
isSuccess
:
Boolean
,
msg
:
String
?)
->
Unit
)
{
if
(
act
.
status
==
ConsultantAudioHomeActivity
.
STATUS_NOT_ANSWERED
)
{
if
(
TextUtils
.
isEmpty
(
userId
)
||
userId
?:
"0"
<=
"0"
)
{
act
.
close
(
ConsultantAudioHomeActivity
.
RESULT_USER_CANCEL
,
""
)
//如果uid为空或小于等于0 ,则不进行登录,因为uid为0也会登录成功,会导致后面uid正确时无法登录
}
LogUtil
.
e
(
"[agora]login-uid:$userId"
)
return
}
//登录实时消息
//获取token
AudioApiRequestUtil
.
getAgoraToken
().
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
()).
subscribe
({
if
(
"200"
.
equals
(
it
.
code
))
{
LogUtil
.
e
(
"[agora]登录av的login-uid:$userId"
)
YDLRTMClient
.
instances
.
login
(
LoginParam
(
userId
,
it
.
data
.
token
),
object
:
LoginCallback
{
override
fun
onSuccess
()
{
//登陆成功,发起呼叫
LogUtil
.
e
(
"[agora]实时消息登录成功"
)
event
(
true
,
""
)
}
override
fun
onFailure
(
msg
:
String
?)
{
LogUtil
.
e
(
"[agora]实时消息登录失败:$msg"
)
event
(
false
,
msg
)
}
})
}
else
{
LogUtil
.
e
(
"声网token获取失败uid:"
+
userId
+
" error:"
+
it
.
msg
)
LogHelper
.
getInstance
()
.
writeLogSync
(
"声网token获取失败uid:"
+
userId
+
" error:"
+
it
.
msg
)
}
}
},
{
LogUtil
.
e
(
"声网token获取异常uid:"
+
userId
+
" error:"
+
it
.
message
)
})
}
/**
* 收到邀请
*/
@SuppressLint
(
"CheckResult"
)
fun
receivedCall
(
content
:
String
?,
from
:
String
=
""
)
{
if
(!
TextUtils
.
isEmpty
(
content
))
{
//如果已经接听了用户电话 再有电话进来 是不能接听的
if
(!
activityIsExists
(
ConsultantAudioHomeActivity
::
class
.
java
)
&&
!
activityIsExists
(
AudioHomeActivity
::
class
.
java
)
)
{
//延时启动通话界面,防止刚打开就被main遮挡
Observable
.
timer
(
1000
,
TimeUnit
.
MILLISECONDS
).
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
()).
subscribe
{
LogUtil
.
e
(
"[agora]启动通话界面"
)
//邀请加入频道消息,跳转通话界面
ARouter
.
getInstance
().
build
(
"/av/ConsultantAudioHomeActivity"
)
.
withString
(
"param"
,
content
).
navigation
()
AudioLogUtils
.
writeAgoraLog
(
"收到主叫方通话邀请($from)"
,
FILE_NAME
,
false
)
}
}
else
{
LogUtil
.
d
(
"[agora]收到声网邀请,但界面实例已存在"
)
}
}
else
{
LogUtil
.
d
(
"[agora]收到声网邀请,但response==null"
)
}
}
}
private
fun
activityIsExists
(
cls
:
Class
<*>):
Boolean
{
/**
for
(
activity
in
ActivityManager
.
getInstance
().
getActivitys
())
{
* 退出登录
if
(
activity
.
javaClass
==
cls
)
{
*/
return
true
fun
logout
(){
}
EventBus
.
getDefault
().
unregister
(
this
)
YDLRTMClient
.
instances
.
logout
(
object
:
LoginCallback
{
override
fun
onSuccess
()
{
//退出登陆成功
LogUtil
.
d
(
"[agora]实时消息退出成功"
)
}
override
fun
onFailure
(
msg
:
String
?)
{
LogUtil
.
d
(
"[agora]实时消息退出失败:$msg"
)
}
})
}
}
return
false
/**
}
* RTM登录异常,上传错误日志 msg
* 声网出现异常,上传错误日志 connectException
/**
*/
* 关闭通话界面
@SuppressLint
(
"CheckResult"
)
*/
fun
uploadException
(
connectException
:
ConnectExceptionCommand
,
callback
:
UploadExceptionCallback
?)
{
fun
closePage
()
{
AudioApiRequestUtil
.
connectException
(
connectException
).
subscribeOn
(
Schedulers
.
io
()).
observeOn
(
AndroidSchedulers
.
mainThread
())
var
act
=
ActivityManager
.
getInstance
().
getTopTaskActivity
()
if
(
act
is
ConsultantAudioHomeActivity
)
{
.
subscribe
({
//未接通时,收到呼叫进程失败关闭页面,已接通无需关闭
callback
?.
onSuccess
()
if
(
act
.
status
==
ConsultantAudioHomeActivity
.
STATUS_NOT_ANSWERED
)
{
},
{
act
.
close
(
ConsultantAudioHomeActivity
.
RESULT_USER_CANCEL
,
""
)
LogUtil
.
e
(
"agora"
,
"声网上传异常与错误日志接口调用失败:"
+
it
.
message
)
}
})
}
}
}
/**
* 上传异常错误回调
/**
*/
* 退出登录
interface
UploadExceptionCallback
{
*/
fun
onSuccess
()
fun
logout
()
{
EventBus
.
getDefault
().
unregister
(
this
)
YDLRTMClient
.
instances
.
logout
(
object
:
LoginCallback
{
override
fun
onSuccess
()
{
//退出登陆成功
LogUtil
.
d
(
"[agora]实时消息退出成功"
)
}
override
fun
onFailure
(
msg
:
String
?)
{
LogUtil
.
d
(
"[agora]实时消息退出失败:$msg"
)
}
})
}
/**
* RTM登录异常,上传错误日志 msg
* 声网出现异常,上传错误日志 connectException
*/
@SuppressLint
(
"CheckResult"
)
fun
uploadException
(
connectException
:
ConnectExceptionCommand
,
callback
:
UploadExceptionCallback
?)
{
AudioApiRequestUtil
.
connectException
(
connectException
).
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
({
callback
?.
onSuccess
()
},
{
LogUtil
.
e
(
"agora"
,
"声网上传异常与错误日志接口调用失败:"
+
it
.
message
)
})
}
/**
* 上传异常错误回调
*/
interface
UploadExceptionCallback
{
fun
onSuccess
()
}
/**
* 实时消息全局监听
*/
private
val
listener
=
object
:
InitListener
{
override
fun
onTokenExpired
()
{
LogUtil
.
e
(
"[agora]onTokenExpired"
)
instances
.
login
(
ModularServiceManager
.
provide
(
IUserService
::
class
.
java
).
getUserInfo
()
?.
uid
)
}
}
/**
override
fun
onMessageReceived
(
message
:
RTMMesssage
,
userId
:
Int
)
{
* 实时消息全局监听
LogUtil
.
i
(
"[agora]onMessageReceived:${message.text} -->uid:$userId"
)
*/
}
private
val
listener
=
object
:
InitListener
{
override
fun
onTokenExpired
()
{
LogUtil
.
e
(
"[agora]onTokenExpired"
)
instances
.
login
(
ModularServiceManager
.
provide
(
IUserService
::
class
.
java
).
getUserInfo
()
?.
uid
)
}
override
fun
onMessageReceived
(
message
:
RTMMesssage
,
userId
:
Int
)
{
LogUtil
.
i
(
"[agora]onMessageReceived:${message.text} -->uid:$userId"
)
}
override
fun
onConnectionStateChanged
(
state
:
Int
,
reason
:
Int
)
{
sdkStatus
=
state
LogUtil
.
i
(
"[agora]onConnectionStateChanged:state:${state} -->reason:$reason"
)
}
override
fun
onConnectionStateChanged
(
state
:
Int
,
reason
:
Int
)
{
sdkStatus
=
state
LogUtil
.
i
(
"[agora]onConnectionStateChanged:state:${state} -->reason:$reason"
)
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment