优化代码:游戏房去掉RTC,修复无法显示IM消息问题

This commit is contained in:
Martin 2024-09-23 16:21:35 +08:00
parent 03b05d0de0
commit b23b975edd
2 changed files with 61 additions and 4 deletions

View File

@ -1,16 +1,25 @@
package com.yunbao.common.manager.imrongcloud;
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yunbao.common.CommonAppContext;
import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.bean.SudGameChatImModel;
import com.yunbao.common.bean.SudGameUserModel;
import com.yunbao.common.event.SudGameSocketImEvent;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.WordUtil;
import java.util.ArrayList;
import java.util.List;
import cn.rongcloud.rtc.api.RCRTCRemoteUser;
import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback;
import cn.rongcloud.rtc.api.stream.RCRTCInputStream;
import cn.rongcloud.rtc.base.RTCErrorCode;
import io.rong.imlib.IRongCallback;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation;
@ -41,6 +50,42 @@ public class GameSwMicManager {
mMeetingCallback = null;
}
/**
* 处理游戏房Im消息
*/
public void processingMessage(SudGameSocketImEvent socketImModel) {
List<SudGameSocketImEvent.MsgDTO> msgDTOS = socketImModel.getMsg();
if (msgDTOS.isEmpty()) return;
SudGameSocketImEvent.MsgDTO msgDTO = msgDTOS.get(0);
//正常文字消息
if (TextUtils.equals(msgDTO.getMethod(), "SendMsg")) {
getView().insertItem(new SudGameChatImModel().setWelcomMessage(false).setNickname(msgDTO.getUname()).setTextMessage(msgDTO.getCt()));
} else if (TextUtils.equals(msgDTO.getMethod(), "welcomMessage")) {
// 欢迎用户名进入房间 Welcome (username) to the room
StringBuffer stringBuffer = new StringBuffer();
if (WordUtil.isNewZh()) {
stringBuffer.append("歡迎 ").append(msgDTO.getCt()).append(" 進入房間");
} else {
stringBuffer.append("Welcome ").append(msgDTO.getCt()).append(" to enter the room");
}
getView().insertItem(new SudGameChatImModel().setWelcomMessage(true).setNickname(msgDTO.getCt()).setTextMessage(stringBuffer.toString()));
} else if (TextUtils.equals(msgDTO.getMethod(), "sudGameRoomVoiceList")) {
List<SudGameUserModel> personList = new Gson().fromJson(msgDTO.getCt(), new TypeToken<List<SudGameUserModel>>() {
}.getType());
getView().refreshSudGameUserList(personList);
//refreshStreams(personList);
}
}
public void refreshStreams(String userID, boolean mute, int position) {
getView().onSubscribeSuccess(userID, mute, position);
}
private void sendChatMessage(String textMessage, String method) {
IMLoginModel loginModel = IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getUserInfo();
SudGameSocketImEvent sudGameSocketImEvent = new SudGameSocketImEvent();
@ -111,6 +156,8 @@ public class GameSwMicManager {
void onUnPublishStreamsSuccess();
void onSubscribeSuccess(String userID, boolean mute, int position);
void insertItem(SudGameChatImModel sudGameChatImModel);
void refreshSudGameUserList(List<SudGameUserModel> personList);
}
}

View File

@ -747,6 +747,20 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSudGameSocketImEvent(SudGameSocketImEvent event) {
gameMicManager.processingMessage(event);
}
@Override
public void insertItem(SudGameChatImModel sudGameChatImModel) {
mLiveChatAdapter.insertItem(sudGameChatImModel);
}
@Override
public void refreshSudGameUserList(List<SudGameUserModel> personList) {
sudGameUserListAdapter.refreshSudGameUserList(personList, muteUser);
}
@Override
public void onUnPublishStreamsSuccess() {
runOnUiThread(new Runnable() {
@ -771,10 +785,6 @@ public class SudSwGameActivity extends AbsActivity implements GameSwMicManager.M
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSudGameSocketImEvent(SudGameSocketImEvent event) {
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSudGameUserModel(SudGameUserModel model) {
if (model.isNullUser()) {