update 随机PK 新增请求连麦超时管理

This commit is contained in:
zlzw 2022-12-10 16:08:04 +08:00
parent e0287899f8
commit 26f02065df
3 changed files with 41 additions and 2 deletions

View File

@ -2,6 +2,9 @@ package com.yunbao.common.manager;
import static cn.rongcloud.rtc.base.RTCErrorCode.JOIN_CHAT_ROOM_TIMEOUT;
import android.os.Handler;
import android.os.Looper;
import com.yunbao.common.utils.ToastUtil;
import java.util.ArrayList;
@ -10,6 +13,7 @@ import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import cn.rongcloud.rtc.api.RCRTCEngine;
import cn.rongcloud.rtc.api.RCRTCRemoteUser;
import cn.rongcloud.rtc.api.RCRTCRoom;
import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback;
@ -77,6 +81,7 @@ public class IMRTCManager {
*/
public void requestJoinOtherRoom(String liveUid, boolean inviterAutoMix, String extra, IRCRTCResultCallback callback) {
if (requestUid.contains(liveUid)) {
ToastUtil.show("主动拦截");
callback.onFailed(RTCErrorCode.RongRTCCodeJoinRepeatedRoom);
return;
}
@ -103,6 +108,10 @@ public class IMRTCManager {
@Override
public void onFailed(RTCErrorCode errorCode) {
ToastUtil.show("邀请失败 " + errorCode.getValue());
if (RandomPkManager.getInstance().isRequestPk()) {
RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE);
}
requestUid.remove(liveUid);
callback.onFailed(errorCode);
}
});
@ -111,6 +120,11 @@ public class IMRTCManager {
}
}
/**
* 注册监听对方通知类还没搞清楚具体用法先搁置
*
* @param listener
*/
public void registerRoomListener(IRCRTCRoomEventsListener listener) {
if (rtcRoom != null) {
rtcRoom.registerRoomListener(new IRCRTCRoomEventsListener() {
@ -199,18 +213,26 @@ public class IMRTCManager {
public void run() {
if (!requestUid.contains(liveUid)) {
cancel();
return;
}
if (waitTime-- == 0) {
new Handler(Looper.getMainLooper()).post(() -> ToastUtil.show("超时清除"));
//callback.onFailed(JOIN_CHAT_ROOM_TIMEOUT);
cancelRequestJoinOtherRoom(liveUid, "extra", new IRCRTCResultCallback() {
@Override
public void onSuccess() {
requestUid.remove(liveUid);
if (RandomPkManager.getInstance().isRequestPk()) {
RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE);
}
}
@Override
public void onFailed(RTCErrorCode errorCode) {
requestUid.remove(liveUid);
if (RandomPkManager.getInstance().isRequestPk()) {
RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE);
}
}
});
cancel();
@ -218,4 +240,20 @@ public class IMRTCManager {
}
}, 1000, 1000);
}
public void leaveOtherRoom(String roomId,
boolean notifyFinished,
IRCRTCResultCallback callBack) {
RCRTCEngine.getInstance().leaveOtherRoom(roomId, notifyFinished, new IRCRTCResultCallback() {
@Override
public void onSuccess() {
callBack.onSuccess();
}
@Override
public void onFailed(RTCErrorCode rtcErrorCode) {
callBack.onFailed(rtcErrorCode);
}
});
}
}

View File

@ -1124,7 +1124,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
} else {
ToastUtil.show("主播正在PK稍後再試");
if (RandomPkManager.getInstance().isRankModel()) {
if (RandomPkManager.getInstance().isRequestPk()) {
RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE);
}
}

View File

@ -288,6 +288,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
@Override
public void onResponseJoinOtherRoom(String inviterRoomId, String inviterUserId, String inviteeRoomId, String inviteeUserId, boolean agree, String extra) {
super.onResponseJoinOtherRoom(inviterRoomId, inviterUserId, inviteeRoomId, inviteeUserId, agree, extra);
IMRTCManager.getInstance().callPkSuccess(inviterRoomId);
runOnUiThread(new Runnable() {
@Override
public void run() {