From b4adf4c77c42f0fc048e6a85f44afdd480e22dea Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Tue, 30 Apr 2024 18:29:09 +0800 Subject: [PATCH] =?UTF-8?q?add[=E5=A3=B0=E6=9C=9B=E5=8D=87=E7=BA=A7-?= =?UTF-8?q?=E5=A4=9A=E4=BA=BAPK]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/bean/EnterRoomInfoModel.java | 11 + .../yunbao/common/bean/LivePkMicModel.java | 36 +++ .../faceunity/agora/SWAuManager.java | 7 +- .../beautyapi/faceunity/agora/SWManager.java | 13 +- .../live/activity/LiveRyAnchorActivity.java | 1 + .../presenter/LiveLinkMicPkPresenter.java | 5 +- .../presenter/LiveRyLinkMicPkPresenter.java | 229 ++++++++++-------- .../yunbao/live/socket/SocketRyClient.java | 7 +- .../live/views/LivePlayRyViewHolder.java | 78 +++--- .../live/views/LivePushRyViewHolder.java | 4 +- .../yunbao/live/views/LiveRoomViewHolder.java | 4 +- .../live/views/PortraitLiveManager.java | 24 +- .../main/res/layout/view_live_play_ksy.xml | 2 +- 13 files changed, 268 insertions(+), 153 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/bean/LivePkMicModel.java diff --git a/common/src/main/java/com/yunbao/common/bean/EnterRoomInfoModel.java b/common/src/main/java/com/yunbao/common/bean/EnterRoomInfoModel.java index ec265a735..d32508ad6 100644 --- a/common/src/main/java/com/yunbao/common/bean/EnterRoomInfoModel.java +++ b/common/src/main/java/com/yunbao/common/bean/EnterRoomInfoModel.java @@ -114,6 +114,17 @@ public class EnterRoomInfoModel extends BaseModel { @SerializedName("gift_wall_lighten_total") private String giftWallLightenTotal; + @SerializedName("connection_info") + private LivePkMicModel connectionInfo; + + public LivePkMicModel getConnectionInfo() { + return connectionInfo; + } + + public void setConnectionInfo(LivePkMicModel connectionInfo) { + this.connectionInfo = connectionInfo; + } + public String getGiftWallLightenNumber() { return giftWallLightenNumber; } diff --git a/common/src/main/java/com/yunbao/common/bean/LivePkMicModel.java b/common/src/main/java/com/yunbao/common/bean/LivePkMicModel.java new file mode 100644 index 000000000..8a152613a --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/LivePkMicModel.java @@ -0,0 +1,36 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +public class LivePkMicModel extends BaseModel { + @SerializedName("pkuid") + private String pkuid; + @SerializedName("pkuname") + private String pkuname; + @SerializedName("pkuimg") + private String pkuimg; + + public String getPkuid() { + return pkuid; + } + + public void setPkuid(String pkuid) { + this.pkuid = pkuid; + } + + public String getPkuname() { + return pkuname; + } + + public void setPkuname(String pkuname) { + this.pkuname = pkuname; + } + + public String getPkuimg() { + return pkuimg; + } + + public void setPkuimg(String pkuimg) { + this.pkuimg = pkuimg; + } +} diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index c918292b3..4869923a3 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -232,7 +232,6 @@ public class SWAuManager extends BaseCacheManager { }); } - /** * 退出对方直播间 * @param uid 自己的ID @@ -246,7 +245,11 @@ public class SWAuManager extends BaseCacheManager { } public static String getChannelName(String liveUid) { - return CommonAppConfig.SWChannelPrefix + liveUid; + if(liveUid.contains("g")){ + return liveUid; + }else{ + return CommonAppConfig.SWChannelPrefix + liveUid; + } } //远程监听 diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 98c2124ab..7a780c229 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -218,7 +218,7 @@ public class SWManager extends BaseCacheManager { surfaceView.setZOrderMediaOverlay(true); frameLayout.addView(surfaceView); - VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN, uid); + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN , uid); mRtcEngine.setupLocalVideo(videoCanvas); } @@ -262,7 +262,7 @@ public class SWManager extends BaseCacheManager { SurfaceView surfaceView = new SurfaceView(mContext); surfaceView.setZOrderMediaOverlay(true); pkContainer.addView(surfaceView); - VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid)); + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN ,Integer.parseInt(toUid)); mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); } }); @@ -310,6 +310,7 @@ public class SWManager extends BaseCacheManager { rtcConnection.channelId = channelName; //對方主播的頻道 rtcConnection.localUid = tempUid;//自己的ID L.eSw("strUid:" + tempUid + "_token:" + token + "_channelName:" + channelName); + // 用内部通知,刷新多人PK的用户信息 mRtcEngine.joinChannelEx(token, rtcConnection, options, new IRtcEngineEventHandler() { @Override public void onJoinChannelSuccess(String channel, int scUid, int elapsed) { @@ -321,7 +322,7 @@ public class SWManager extends BaseCacheManager { SurfaceView surfaceView = new SurfaceView(mContext); surfaceView.setZOrderMediaOverlay(true); frameLayout.addView(surfaceView); - VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT,Integer.parseInt(toUid)); + VideoCanvas videoCanvas = new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_HIDDEN ,Integer.parseInt(toUid)); mRtcEngine.setupRemoteVideoEx(videoCanvas, rtcConnection); } }); @@ -450,6 +451,10 @@ public class SWManager extends BaseCacheManager { this.linkUserContainer = linkUserContainer; } public static String getChannelName(String liveUid) { - return CommonAppConfig.SWChannelPrefix + liveUid; + if(liveUid.contains("g")){ + return liveUid; + }else{ + return CommonAppConfig.SWChannelPrefix + liveUid; + } } } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index 6d3b6f6af..c35ee493d 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -406,6 +406,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl public void onSuccess(int code, String msg, String[] info) { if (code == 0) { + LiveRyLinkMicPkPresenter.mApplyUid = CommonAppConfig.getInstance().getUid(); btn_start_dr_pk.setVisibility(View.VISIBLE); // dr_pk_view.setVisibility(View.VISIBLE); final SocketSendBean msg1 = new SocketSendBean() diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java index 851145c90..6c18b6bf8 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveLinkMicPkPresenter.java @@ -112,7 +112,7 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { mIsAnchor = isAnchor; mRoot = root; mPkContainer = linkMicViewHolder.getPkContainer(); - mPkTimeString2 =mContext.getString(R.string.live_pk_time_2); + mPkTimeString2 = mContext.getString(R.string.live_pk_time_2); //从本地取数据 String pkTime = CommonAppConfig.getInstance().getAnchorPkTime(); @@ -773,7 +773,8 @@ public class LiveLinkMicPkPresenter implements View.OnClickListener { final SocketSendBean msg = new SocketSendBean() .param("_method_", Constants.SOCKET_LIVE_DRPK) .param("action", 2) - .param("uid", CommonAppConfig.getInstance().getUid()); + .param("uid", u.getId()) + .param("pkuid",CommonAppConfig.getInstance().getUid()); msg.create(); V2TIMManager.getInstance().sendC2CTextMessage(msg.mResult.toString(), list.get(i).getId() + "", new V2TIMSendCallback() { @Override diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index 1d470ddda..03204fba6 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -1022,42 +1022,68 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { drPkbeans.remove(removeIndex); L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); } - for (int i = 0; i < drPkbeans.size(); i++) { - if (!CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { - final SocketSendBean msg1 = new SocketSendBean().param("_method_", SOCKET_LIVE_DRPK).param("action", 2).param("uname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()).param("pkuid", drPkbeans.get(i).getId()).param("uid", CommonAppConfig.getInstance().getUid()).param("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()).param("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.create(); - String targetId = "g" + drPkbeans.get(i).getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + HttpClient.getInstance().get("Live.getDRPKroom", "Live.getDRPKroom").params("uid", CommonAppConfig.getInstance().getUid()).params("roomid", mApplyUid).execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (info.length > 0) { + JSONObject obj = JSONObject.parseObject(info[0]); + drPkbeans = JSONObject.parseArray(obj.getString("userlist"), DrPkbean.class); + int removeIndex = -1; + for (int i = 0; i < drPkbeans.size(); i++) { + if (CommonAppConfig.getInstance().getUid().equals(String.valueOf(drPkbeans.get(i).getId()))) { + removeIndex = i; } } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("tx", "aaa" + errorCode.toString()); - ToastUtil.show(errorCode.code + ":" + errorCode.msg); + if (removeIndex != -1) { + drPkbeans.remove(removeIndex); } - }); - // - int index = livePushRyViewHolder.setAnDrPkRtc(String.valueOf(drPkbeans.get(i).getId()), -1); - L.eSw("onLinkDRMicPkApplyOk(UserBean u)-点击接收 " + u.getUserNiceName()); + for (int i = 0; i 0) { @@ -1235,7 +1261,6 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } if (removeIndex != -1) { drPkbeans.remove(removeIndex); - L.eSw("将自己从多人pk列表里剔除" + new Gson().toJson(drPkbeans)); } setDrPkUserInfoView(drPkbeans); } @@ -1244,74 +1269,84 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } private void setDrPkUserInfoView(List drPkbeanList) { - for (int j = 0; j drMicUserList = new ArrayList<>(); -boolean isAdd = true; + boolean isAdd = true; @Override public void setDrMicInfo(UserBean u) { - L.eSw("setDrMicInfo:"+u.getId()+" drMicUserList:"+new Gson().toJson(drMicUserList)); - for (int i = 0; i 0) { mPkTimeCount2 = time; drPKtIME = time; diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 13a9589dc..0c6667b0c 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -38,6 +38,7 @@ import com.yunbao.common.bean.BannerBean; import com.yunbao.common.bean.CreateSudRoomModel; import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.bean.LiveBean; +import com.yunbao.common.bean.LivePkMicModel; import com.yunbao.common.bean.LiveRoomActivityModel; import com.yunbao.common.bean.LiveUserGiftBean; import com.yunbao.common.bean.MsgModel; @@ -644,17 +645,22 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if(mLivePlayViewHolder != null && data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")){ JSONArray array = pkInfo.getJSONArray("userlist"); //判断是否是多人连麦 - if(array!=null){//多人連麥 + if(array.size()>0){//多人連麥 if (mLivePlayViewHolder != null) { for (int j = 0; j < array.size(); j++) { UserBean drPkbean = new UserBean(); JSONObject da = array.getJSONObject(j); - drPkbean.setId(String.valueOf(da.getIntValue("id"))); - mLivePlayViewHolder.setDrMicInfo(drPkbean); + if(!String.valueOf(da.getIntValue("id")).equals(String.valueOf(data.getLiveInfo().getUid()))){ + drPkbean.setId(String.valueOf(da.getIntValue("id"))); + mLivePlayViewHolder.setDrMicInfo(drPkbean); + } } } }else{//单人连麦 - mLivePlayViewHolder.setPkView(data.getEnterRoomInfo().getPkinfo().getPkuid()); + LivePkMicModel connection_info = data.getEnterRoomInfo().getConnectionInfo(); + if(!StringUtil.isEmpty(connection_info.getPkuid())){ + mLivePlayViewHolder.setPkView(connection_info.getPkuid()); + } } } if (mLiveRoomViewHolder != null) { @@ -709,8 +715,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe for (int j = 0; j < array.size(); j++) { UserBean drPkbean = new UserBean(); JSONObject da = array.getJSONObject(j); - drPkbean.setId(String.valueOf(da.getIntValue("id"))); - mLivePlayViewHolder.setDrMicInfo(drPkbean); + if(!String.valueOf(da.getIntValue("id")).equals(data.getLiveInfo().getUid())){ + drPkbean.setId(String.valueOf(da.getIntValue("id"))); + mLivePlayViewHolder.setDrMicInfo(drPkbean); + } } } @@ -768,10 +776,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.showPrizePoolLevel(String.valueOf(giftPrizePoolLevel)); } } + //liveHandler.postDelayed(loadTimeoutRunnableGone, 15_000); AppManager.runDebugCode(() -> { - // liveHandler.postDelayed(loadTimeoutRunnableGone, 1_000); + liveHandler.postDelayed(loadTimeoutRunnableGone, 1_000); }); - liveHandler.postDelayed(loadTimeoutRunnableGone, 15_000); if (TextUtils.equals(data.getEnterRoomInfo().getIsconnection(), "1")) { //通知心愿单位置换地方 EventBus.getDefault().post(new LiveAudienceEvent() diff --git a/live/src/main/res/layout/view_live_play_ksy.xml b/live/src/main/res/layout/view_live_play_ksy.xml index 7cbf9004a..cdcd20495 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -72,7 +72,7 @@ android:layout_height="270dp" android:layout_marginTop="130dp" android:orientation="horizontal" - android:visibility="visible"> + android:visibility="gone">