Commit 6ce6a104 by 万齐军

feat: IImService注册自定义通知改造,AudioHomeActivity处理自定义消息

parent 613d0d77
......@@ -25,6 +25,7 @@ import com.alibaba.android.arouter.launcher.ARouter
import com.google.gson.Gson
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.XXPermissions
import com.ydl.audioim.bean.AgoraInvitationBean
import com.ydl.audioim.bean.AgoraLogInfoBean
import com.ydl.audioim.contract.IAudioHomeActivityContract
import com.ydl.audioim.http.command.ConnectCommand
......@@ -49,6 +50,7 @@ import com.ydl.ydl_image.config.SimpleImageOpConfiger
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.ydl.ydlcommon.base.BaseMvpActivity
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.modular.findRouteService
import com.ydl.ydlcommon.router.YdlCommonRouterManager
import com.ydl.ydlcommon.utils.LogUtil
import com.ydl.ydlcommon.utils.StatusBarUtils
......@@ -58,6 +60,8 @@ import com.ydl.ydlcommon.utils.log.AliYunLogConfig
import com.ydl.ydlcommon.utils.log.AliYunRichLogsHelper
import com.ydl.ydlcommon.utils.log.LogHelper
import com.ydl.ydlcommon.utils.remind.ToastHelper
import com.yidianling.common.tools.ToastUtil
import com.yidianling.im.api.bean.IMRegisterObserverCustomNotificationCallBack
import com.yidianling.im.api.service.IImService
import com.yidianling.user.api.service.IUserService
import de.greenrobot.event.EventBus
......@@ -227,6 +231,36 @@ class AudioHomeActivity :
private var canChangeRoute: Boolean = false
private val notificationCallback = object : IMRegisterObserverCustomNotificationCallBack {
override fun onObserverCustomNotification(fromUid: String, toUid: String, content: String) {
if (fromUid == listenerUid) {
try {
val bean = Gson().fromJson(content, AgoraInvitationBean::class.java)
when (bean.callType) {
"2" -> {//接受
runOnUiThread {
joinChannel()
onPeerAccepted()
}
}
"4" -> {//拒绝
runOnUiThread {
ToastUtil.toastShort("对方已挂断")
writeAgoraLog("被叫(专家)拒绝了通话邀请")
//通话结束或挂断时,上传日志文件
uploadLog()
leaveChannel()
uploadExceptionStatus("对方已拒绝", 2)
}
}
}
} catch (throwable: Throwable) {
LogUtil.e(throwable.message)
}
}
}
}
/**
* 声网事件回调 (SDK 通过指定的事件通知应用程序 SDK 的运行事件,如: 加入或离开频道,新用户加入频道等)
*/
......@@ -484,6 +518,7 @@ class AudioHomeActivity :
setClickEvent()
//权限申请
requestPermission()
findRouteService(IImService::class.java).registerObserveCustomNotification(notificationCallback)
ActionCountUtils.record("call_phone_page", "call_phone_page_visit", listenerUid ?: "0", "1")
}
......@@ -1545,6 +1580,7 @@ class AudioHomeActivity :
override fun onDestroy() {
super.onDestroy()
findRouteService(IImService::class.java).unregisterObserveCustomNotification(notificationCallback)
uploadLog()
phoneHandler?.removeCallbacksAndMessages(null)
if (isConnectSuccess) {
......
......@@ -41,10 +41,7 @@ import java.util.concurrent.Executors
* Des:
*/
class ImObserversHelper {
var imCustomNotificationCallBack: IMRegisterObserverCustomNotificationCallBack? = null
set(value) {
field = value
}
internal val imCustomNotificationCallBack: MutableList<IMRegisterObserverCustomNotificationCallBack> = arrayListOf()
companion object {
fun getInstance(): ImObserversHelper {
......@@ -172,9 +169,9 @@ class ImObserversHelper {
false
}
private var receiveSystemMessageObserver: Observer<CustomNotification> = Observer<CustomNotification> {
LogUtil.e(it.content)
imCustomNotificationCallBack?.onObserverCustomNotification(it.fromAccount, it.sessionId, it.content)
private var receiveSystemMessageObserver: Observer<CustomNotification> = Observer<CustomNotification> { notification ->
LogUtil.e(notification.content)
imCustomNotificationCallBack.forEach { it.onObserverCustomNotification(notification.fromAccount, notification.sessionId, notification.content) }
}
private var msgRevokeFilter = MsgRevokeFilter { message ->
......
......@@ -39,7 +39,6 @@ import com.yidianling.im.session.SessionHelper
import com.yidianling.im.session.extension.CustomAttachModifyTime
import com.yidianling.im.session.extension.CustomAttachSubScriptTime
import com.yidianling.im.session.extension.CustomAttachmentTest
import com.yidianling.im.ui.activity.CmsExamQuestionPaperActivity
import com.yidianling.im.ui.page.NewMultiMessageFragment
import com.yidianling.nimbase.common.media.picker.PickImageHelper
import com.yidianling.uikit.api.NimUIKit
......@@ -257,7 +256,11 @@ class IMServiceImpl : IImService {
}
override fun registerObserveCustomNotification(callback: IMRegisterObserverCustomNotificationCallBack) {
ImObserversHelper.getInstance().imCustomNotificationCallBack=callback
ImObserversHelper.getInstance().imCustomNotificationCallBack.add(callback)
}
override fun unregisterObserveCustomNotification(callback: IMRegisterObserverCustomNotificationCallBack) {
ImObserversHelper.getInstance().imCustomNotificationCallBack.remove(callback)
}
override fun getMultiMessageFragment(): Fragment {
......
......@@ -16,15 +16,15 @@ import com.netease.nimlib.sdk.msg.MsgServiceObserve;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.CustomNotification;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.ydl.ydlcommon.modular.ModularServiceManagerKt;
import com.ydl.ydlcommon.utils.log.AliYunLogConfig;
import com.ydl.ydlcommon.utils.log.AliYunRichLogsHelper;
import com.yidianling.common.tools.ToastUtil;
import com.yidianling.im.R;
import com.yidianling.im.api.bean.IMRegisterObserverCustomNotificationCallBack;
import com.yidianling.im.api.service.IImService;
import com.yidianling.im.bean.ServiceBean;
import com.yidianling.im.bridge.P2PCustomActionHandlerImpl;
import com.yidianling.im.config.constants.ImConstants;
import com.yidianling.im.helper.ImObserversHelper;
import com.yidianling.im.session.SessionHelper;
import com.yidianling.nimbase.api.model.session.SessionCustomization;
import com.yidianling.nimbase.api.model.user.UserInfoObserver;
......@@ -54,6 +54,7 @@ public class YDLP2PMessageActivity extends YDLBaseMessageActivity {
protected YDLMessageFragment messageFragment;
private boolean isChangeDoctor = false;
String oldName="";
private IMRegisterObserverCustomNotificationCallBack notificationCallBack;
/**
* @param context
......@@ -129,23 +130,24 @@ public class YDLP2PMessageActivity extends YDLBaseMessageActivity {
NIMClient.getService(MsgService.class).clearUnreadCount(sessionId, SessionTypeEnum.P2P);
// 转客服通知监听
ImObserversHelper.Companion.getInstance().setImCustomNotificationCallBack(new IMRegisterObserverCustomNotificationCallBack() {
notificationCallBack = new IMRegisterObserverCustomNotificationCallBack() {
@Override
public void onObserverCustomNotification(@NotNull String fromUid, @NotNull String toUid, @NotNull String content) {
try {
ServiceBean serviceBean = new Gson().fromJson(content, ServiceBean.class);
// 切换到客服
if (serviceBean != null && serviceBean.getData() != null&&serviceBean.getBusiness()!=null && serviceBean.getBusiness().equals("change_doctor")) {
isChangeDoctor = true;
String serviceUid = String.valueOf(serviceBean.getData().getToUid());
tb.setTitle(serviceBean.getData().getName());
YDLP2PMessageActivity.startChangeDoctor(YDLP2PMessageActivity.this, serviceUid, SessionHelper.getP2pCustomization(-1), null, new P2PCustomActionHandlerImpl(serviceUid, serviceBean.getData().getName(), serviceUid));
}
}catch (Exception e){
com.ydl.ydlcommon.utils.LogUtil.e("exception:"+e.getMessage());
}
try {
ServiceBean serviceBean = new Gson().fromJson(content, ServiceBean.class);
// 切换到客服
if (serviceBean != null && serviceBean.getData() != null && serviceBean.getBusiness() != null && serviceBean.getBusiness().equals("change_doctor")) {
isChangeDoctor = true;
String serviceUid = String.valueOf(serviceBean.getData().getToUid());
tb.setTitle(serviceBean.getData().getName());
YDLP2PMessageActivity.startChangeDoctor(YDLP2PMessageActivity.this, serviceUid, SessionHelper.getP2pCustomization(-1), null, new P2PCustomActionHandlerImpl(serviceUid, serviceBean.getData().getName(), serviceUid));
}
} catch (Exception e) {
com.ydl.ydlcommon.utils.LogUtil.e("exception:" + e.getMessage());
}
}
});
};
ModularServiceManagerKt.findRouteService(IImService.class).registerObserveCustomNotification(notificationCallBack);
}
@Override
......@@ -156,6 +158,10 @@ public class YDLP2PMessageActivity extends YDLBaseMessageActivity {
registerObservers(false);
super.onDestroy();
if (notificationCallBack != null) {
ModularServiceManagerKt.findRouteService(IImService.class).registerObserveCustomNotification(notificationCallBack);
}
AliYunRichLogsHelper.Companion.getInstance().sendRichLog(AliYunLogConfig.YUNXIN,"退出聊天页面");
}
......
......@@ -110,6 +110,8 @@ interface IImService : IProvider {
*/
fun registerObserveCustomNotification(callback: IMRegisterObserverCustomNotificationCallBack)
fun unregisterObserveCustomNotification(callback: IMRegisterObserverCustomNotificationCallBack)
fun getMultiMessageFragment(): Fragment
......
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