Commit b3c3fac4 by 严久程

咨询接入声网逻辑

parent c791b7b6
......@@ -42,7 +42,7 @@ ext {
ydlPublishVersion = [
// -------------- 业务模块 --------------
//第三步 若干
"m-confide" : "0.0.48.7.12",
"m-confide" : "0.0.48.7.14",
"m-consultant" : "0.0.57.4",
"m-fm" : "0.0.29.3",
"m-user" : "0.0.60.1",
......@@ -75,7 +75,7 @@ ext {
"ydl-webview" : "0.0.38.24",
"ydl-media" : "0.0.20",
"ydl-pay" : "0.0.17",
"m-audioim" : "0.0.48.2.6",
"m-audioim" : "0.0.48.3.4",
"ydl-flutter-base": "0.0.10.9",
//以下 几乎不会动
......@@ -121,7 +121,7 @@ ext {
"ydl-webview" : "0.0.38.24",
"ydl-media" : "0.0.20",
"ydl-pay" : "0.0.17",
"m-audioim" : "0.0.48.3.2",
"m-audioim" : "0.0.48.3.4",
"ydl-flutter-base": "0.0.10.9",
//以下 几乎不会动
......
......@@ -35,15 +35,11 @@ import com.ydl.audioim.presenter.AudioHomePresenterImpl
import com.ydl.audioim.utils.AudioLogUtils
import com.ydl.audioim.utils.DateUtils
import com.ydl.audioim.widget.AxbConfirmDialog
import com.ydl.burypointlib.ToastUtil
import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity
import com.ydl.webview.RefreshWebEvent
import com.ydl.ydl_av.chat.bean.AudioMessageBean
import com.ydl.ydl_av.messge_service.YDLRTMClient
import com.ydl.ydl_av.messge_service.callback.CallListener
import com.ydl.ydl_av.messge_service.response.CallLocalResponse
import com.ydl.ydl_av.messge_service.response.CallRemoteResponse
import com.ydl.ydl_av.voice.listener.IYDLVoiceEventHandler
import com.ydl.ydl_av.voice.manager.YDLVoiceManager
import com.ydl.ydl_image.config.SimpleImageOpConfiger
......@@ -60,7 +56,6 @@ import com.ydl.ydlcommon.utils.remind.ToastHelper
import com.yidianling.user.api.service.IUserService
import de.greenrobot.event.EventBus
import io.agora.rtc.IRtcEngineEventHandler
import io.agora.rtm.RtmStatusCode
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
......@@ -273,7 +268,7 @@ class AudioHomeActivity :
LogUtil.e("[agora]$uid 用户声网重新加入频道成功:channel=$channel")
runOnUiThread {
//自己加入频道成功
if(!isConnectSuccess){
if (!isConnectSuccess) {
connectSuccess()
}
}
......@@ -472,7 +467,11 @@ class AudioHomeActivity :
userCloseCalling()
}
ActionCountUtils.count("shengwang_popup_layer_page|shengwang_popup_layer_refuse_click", YdlCommonRouterManager.getYdlCommonRoute().getUid().toString(), uid = YdlCommonRouterManager.getYdlCommonRoute().getUid().toString())
ActionCountUtils.count(
"shengwang_popup_layer_page|shengwang_popup_layer_refuse_click",
YdlCommonRouterManager.getYdlCommonRoute().getUid().toString(),
uid = YdlCommonRouterManager.getYdlCommonRoute().getUid().toString()
)
}
//免提
......@@ -630,7 +629,8 @@ class AudioHomeActivity :
.subscribeOn(Schedulers.computation())
.take(603)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ var result = it.toFloat() / 2.5f
.subscribe({
var result = it.toFloat() / 2.5f
progress_view.setProgress(result)
if (result >= 100f && !iv_hang_up.isEnabled) {
//挂断按钮可点击
......@@ -658,7 +658,7 @@ class AudioHomeActivity :
noticeServerPush(true)
}
fun rtcCall(){
fun rtcCall() {
YDLRTMClient.instances.call(listenerUid!!, channelId, sendDoctocrMsg)
}
......@@ -1040,7 +1040,7 @@ class AudioHomeActivity :
/**
* 声网离开频道
*/
fun leaveChannel() {
fun leaveChannel() {
if (!isLeavelChannel) {
isLeavelChannel = true
//刷新h5页面
......@@ -1060,7 +1060,11 @@ class AudioHomeActivity :
)
ActionCountUtils.count("shengwang_popup_layer_page|shengwang_popup_layer_page_visit", "", uid = YdlCommonRouterManager.getYdlCommonRoute().getUid().toString())
ActionCountUtils.count(
"shengwang_popup_layer_page|shengwang_popup_layer_page_visit",
"",
uid = YdlCommonRouterManager.getYdlCommonRoute().getUid().toString()
)
}
override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {
......@@ -1120,7 +1124,7 @@ class AudioHomeActivity :
}
fun uploadLog() {
fun uploadLog() {
if (!hasUpLoadLog) {
hasUpLoadLog = true
LogHelper.getInstance().uploadLog(false)
......
......@@ -4,9 +4,12 @@ import com.google.gson.Gson
import com.ydl.audioim.bean.AgoraTokenResponse
import com.ydl.audioim.bean.ConnectBean
import com.ydl.audioim.http.command.*
import com.ydl.consultantim.bean.ListenTokenBean
import com.ydl.consultantim.command.ListenTokenCmd
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.BaseResponse
import com.ydl.ydlcommon.data.http.RxUtils
import com.ydl.ydlcommon.utils.NetworkParamsUtils
import com.ydl.ydlnet.YDLHttpUtils
import io.reactivex.Observable
import okhttp3.MediaType
......@@ -85,5 +88,12 @@ class AudioApiRequestUtil {
fun getAgoraToken(): Observable<BaseAPIResponse<AgoraTokenResponse>>{
return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).getAgoraToken()
}
/**
* 获取声网登录token
*/
fun listenToken(cmd: ListenTokenCmd): Observable<BaseResponse<ListenTokenBean>>{
return YDLHttpUtils.obtainApi(AudioNetAPi::class.java).listenToken(NetworkParamsUtils.getMaps(cmd))
}
}
}
\ No newline at end of file
......@@ -68,4 +68,5 @@ interface AudioNetAPi {
@POST("listen/token")
fun listenToken(@FieldMap map: Map<String, String>): Observable<BaseResponse<ListenTokenBean>>
}
\ No newline at end of file
......@@ -95,6 +95,7 @@ class ConsultantAudioHomeActivity :
* 本次倾述倒计时
*/
private var totalDisposable: Disposable? = null
private var connectingStatusDisposable: Disposable? = null
//频道管理器
// private var channelManager: ChannelManager? = null
......@@ -102,6 +103,11 @@ class ConsultantAudioHomeActivity :
//频道token
private var channelToken: String? = null
private var hasUpLoadLog = false
/**
* 是否连接成功
*/
private var isConnectSuccess: Boolean = false
/**
* 事件回调 (SDK 通过指定的事件通知应用程序 SDK 的运行事件,如: 加入或离开频道,新用户加入频道等)
*/
......@@ -126,6 +132,11 @@ class ConsultantAudioHomeActivity :
runOnUiThread {
tv_toast.visibility = View.VISIBLE
tv_toast.text = "连接中..."
voiceManage!!.getVoiceApi().setEnableSpeakerphone(false)
//5s倒计时,5s后还是连接中,则直接关闭页面
connectingStatusWaitingTimeCount()
}
}
......@@ -134,6 +145,7 @@ class ConsultantAudioHomeActivity :
LogUtil.e("[agora]远端用户加入频道回调")
//另一方加入频道成功
runOnUiThread {
isConnectSuccess = true
//通话开始,刷新ui开始倒计时
updateStartUi()
status = STATUS_ANSWERED
......@@ -204,6 +216,19 @@ class ConsultantAudioHomeActivity :
override fun onRejoinChannelSuccess(channel: String?, uid: Int, elapsed: Int) {
super.onRejoinChannelSuccess(channel, uid, elapsed)
LogUtil.e("[agora]$uid 重新加入频道回调")
runOnUiThread {
if (!isConnectSuccess) {
tv_toast.visibility = View.VISIBLE
tv_toast.text = "连接中..."
voiceManage!!.getVoiceApi().setEnableSpeakerphone(false)
//5s倒计时,5s后还是连接中,则直接关闭页面
connectingStatusWaitingTimeCount()
}
}
}
/**
......@@ -336,6 +361,8 @@ class ConsultantAudioHomeActivity :
if (!TextUtils.isEmpty(json)) {
writeAgoraLog(json)
mAudioMessageBean = Gson().fromJson(json, AudioMessageBean::class.java)
YDLavManager.instances.login(ModularServiceManager.provide(IUserService::class.java).getUserInfo()?.uid)
}
} else {
close(RESULT_NOT_ANSWERED_CODE, "通话异常")
......@@ -482,6 +509,18 @@ class ConsultantAudioHomeActivity :
}
}
/**
* 更新ui
*/
private fun updateUI() {
tv_toast.visibility = View.VISIBLE
tv_toast.text = "正在建立连接..."
rl_call.visibility = View.GONE
rl_hands_free.visibility = View.VISIBLE
}
//申请音频权限
@SuppressLint("CheckResult")
private fun requestPermission() {
......@@ -524,20 +563,10 @@ class ConsultantAudioHomeActivity :
*/
voiceManage = YDLVoiceManager(this, BuildConfig.AGORA_APPID, mRtcEventHandler)
voiceManage!!.init()
//默认听筒模式
voiceManage!!.getVoiceApi().setEnableSpeakerphone(false)
}
/**
* 更新ui
*/
private fun updateUI() {
rl_call.visibility = View.GONE
rl_hands_free.visibility = View.VISIBLE
}
/**
* 加入频道
*/
private fun joinChannel() {
......@@ -568,13 +597,16 @@ class ConsultantAudioHomeActivity :
rl_remain_time.visibility = View.VISIBLE
totalDisposable = Observable.interval(0, 1, TimeUnit.SECONDS)
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
tv_remain_time.text = DateUtils.formatTime(it.toString())
}, {})
}, {
//通话结束或挂断时,上传日志文件
uploadLog()
close(RESULT_NOT_ANSWERED_CODE, "对方异常")
})
}
/**
......@@ -797,6 +829,25 @@ class ConsultantAudioHomeActivity :
}
/**
*连接中状态倒计时:5s后如果还是处于连接中,则直接退出当前页面
*/
private fun connectingStatusWaitingTimeCount() {
if (connectingStatusDisposable == null) {
connectingStatusDisposable = Observable.interval(0, 1, TimeUnit.SECONDS)
.subscribeOn(Schedulers.computation())
.take(6)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({}, {}, {
if (!isConnectSuccess) {
ToastUtil.toastShort(this, "用户已挂断")
close(RESULT_NOT_ANSWERED_CODE, "")
}
})
}
}
/**
* 离开频道
*/
private fun leaveChannel() {
......@@ -804,6 +855,11 @@ class ConsultantAudioHomeActivity :
if (totalDisposable != null) {
totalDisposable!!.dispose()
}
if (connectingStatusDisposable != null) {
connectingStatusDisposable!!.dispose()
}
if (null != voiceManage && null != voiceManage!!.getVoiceApi()) {
voiceManage!!.getVoiceApi().leaveChannel()
voiceManage!!.getVoiceApi().destroy()
......@@ -871,6 +927,7 @@ class ConsultantAudioHomeActivity :
LogUtil.e("http-------------onDestory")
leaveChannel()
voiceDestory()
isConnectSuccess = false
status = STATUS_NOT_ANSWERED
hasUpLoadLog = false
EventBus.getDefault().unregister(this)
......
package com.ydl.consultantim.presenter
import android.annotation.SuppressLint
import com.ydl.audioim.http.AudioApiRequestUtil
import com.ydl.consultantim.command.ListenTokenCmd
import com.ydl.consultantim.contract.IConsultantAudioHomeActivityContract
import com.ydl.consultantim.model.ConsultantAudioHomeModelImpl
......@@ -7,6 +9,8 @@ import com.ydl.ydl_av.chat.bean.AudioMessageBean
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.mvp.base.BasePresenter
import com.yidianling.user.api.service.IUserService
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
/**
* @author jiucheng
......@@ -30,6 +34,7 @@ class ConsultantAudioHomePresenterImpl :
// })
}
@SuppressLint("CheckResult")
override fun getChannelToken(msgBean: AudioMessageBean?, needJoinChannel: Boolean) {
if (ModularServiceManager.provide(IUserService::class.java).isLogin()) {
if (null != ModularServiceManager.provide(IUserService::class.java).getUserInfo()) {
......@@ -40,15 +45,13 @@ class ConsultantAudioHomePresenterImpl :
tokenParam.account = acount.toString()
tokenParam.uid = acount.toString()
tokenParam.channelId = msgBean?.channelId
//todo
// RetrofitUtils.listenToken(tokenParam)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe({
// view.channelTokenResponse(it.data.token, needJoinChannel)
// }, {
// RetrofitUtils.handleError(it)
// })
AudioApiRequestUtil.listenToken(tokenParam)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
mView.channelTokenResponse(it.data.token, needJoinChannel)
}, {
})
}
}
}
......
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