Forráskód Böngészése

新增全部下麦和全部拒绝连麦申请消息和逻辑

Pq 3 éve
szülő
commit
b2a3feaadb

+ 4 - 0
rong_im/live/src/main/java/com/rong/io/live/LiveRoomMsgConstants.java

@@ -18,6 +18,8 @@ public class LiveRoomMsgConstants {
     public static final int ACTION_SEND_PAUSE_LIVE = -110;//暂停直播
     public static final int ACTION_CANCEL_ON_MIC_BY_TEACHER = -111;//主播将观众下麦
     public static final int ACTION_SWITCH_MIC_MODE = -112;//主播切换连麦模式
+    public static final int ACTION_SEND_REFUSE_ALL_MIC_APPLY_MSG= -113;//拒绝全部连麦申请
+    public static final int ACTION_SEND_UNDER_ALL_MIC_MSG= -114;//全部下麦消息
 
     public static final int MIC_ACTION_INVITE_SEAT_BY_CREATE = 1;//连麦-主讲人邀请
     public static final int MIC_ACTION_CANCEL_INVITE_SEAT_BY_CREATE = 2;//连麦-主讲人取消邀请
@@ -53,5 +55,7 @@ public class LiveRoomMsgConstants {
     public static final String TAG_LIVE_REMOVE_BLACK_USER= "RC:UNBLOCK_BLACK_USER"; //解除黑名单
     public static final String TAG_LIVE_MEMBER_COUNT_SYNC = "RC:Chatroom:MemberCountUp"; //人员数量同步
     public static final String TAG_LIVE_FINISH_MSG = "RC:ForcedOffline"; //直播间结束消息
+    public static final String TAG_LIVE_UNDER_ALL_MIC = "RC:Chatroom:DownSeatAll"; //全部下麦
+    public static final String TAG_LIVE_REFUSE_ALL_MIC_APPLY = "RC:Chatroom:RejectSeatAll"; //拒绝全部连麦申请
 
 }

+ 96 - 0
rong_im/live/src/main/java/com/rong/io/live/message/RCLiveRefuseAllMicApplyMessage.java

@@ -0,0 +1,96 @@
+package com.rong.io.live.message;
+
+import android.os.Parcel;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.UnsupportedEncodingException;
+
+import io.rong.common.ParcelUtils;
+import io.rong.imlib.MessageTag;
+import io.rong.imlib.model.MessageContent;
+import io.rong.imlib.model.UserInfo;
+
+/**
+ * Author by pq, Date on 2022/4/1.
+ * 拒绝全部申请上麦消息
+ */
+@MessageTag(value = "RC:Chatroom:RejectSeatAll", flag = MessageTag.STATUS)
+public class RCLiveRefuseAllMicApplyMessage extends MessageContent {
+
+
+    public RCLiveRefuseAllMicApplyMessage() {
+    }
+
+
+    public RCLiveRefuseAllMicApplyMessage(byte[] data) {
+        String jsonStr = null;
+        try {
+            jsonStr = new String(data, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        try {
+            JSONObject jsonObject = new JSONObject(jsonStr);
+
+            if (jsonObject.has("user")) {
+                setUserInfo(this.parseJsonToUserInfo(jsonObject.getJSONObject("user")));
+            }
+
+
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public byte[] encode() {
+        JSONObject jsonObj = new JSONObject();
+        try {
+            // 消息携带用户信息时, 自定义消息需添加下面代码
+            JSONObject jsonUserInfo = this.getJSONUserInfo();
+            if (jsonUserInfo != null) {
+                jsonObj.putOpt("user", jsonUserInfo);
+            }
+
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+
+        try {
+            return jsonObj.toString().getBytes("UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        ParcelUtils.writeToParcel(dest, getExtra());
+        ParcelUtils.writeToParcel(dest, getUserInfo());
+    }
+
+    protected RCLiveRefuseAllMicApplyMessage(Parcel in) {
+        this.setExtra(ParcelUtils.readFromParcel(in));
+        this.setUserInfo((UserInfo) ParcelUtils.readFromParcel(in, UserInfo.class));
+    }
+
+    public static final Creator<RCLiveRefuseAllMicApplyMessage> CREATOR = new Creator<RCLiveRefuseAllMicApplyMessage>() {
+        @Override
+        public RCLiveRefuseAllMicApplyMessage createFromParcel(Parcel source) {
+            return new RCLiveRefuseAllMicApplyMessage(source);
+        }
+
+        @Override
+        public RCLiveRefuseAllMicApplyMessage[] newArray(int size) {
+            return new RCLiveRefuseAllMicApplyMessage[size];
+        }
+    };
+}

+ 96 - 0
rong_im/live/src/main/java/com/rong/io/live/message/RCLiveUnderAllMicMessage.java

@@ -0,0 +1,96 @@
+package com.rong.io.live.message;
+
+import android.os.Parcel;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.UnsupportedEncodingException;
+
+import io.rong.common.ParcelUtils;
+import io.rong.imlib.MessageTag;
+import io.rong.imlib.model.MessageContent;
+import io.rong.imlib.model.UserInfo;
+
+/**
+ * Author by pq, Date on 2022/4/1.
+ * 全部下麦消息
+ */
+@MessageTag(value = "RC:Chatroom:DownSeatAll", flag = MessageTag.STATUS)
+public class RCLiveUnderAllMicMessage extends MessageContent {
+
+
+    public RCLiveUnderAllMicMessage() {
+    }
+
+
+    public RCLiveUnderAllMicMessage(byte[] data) {
+        String jsonStr = null;
+        try {
+            jsonStr = new String(data, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        try {
+            JSONObject jsonObject = new JSONObject(jsonStr);
+
+            if (jsonObject.has("user")) {
+                setUserInfo(this.parseJsonToUserInfo(jsonObject.getJSONObject("user")));
+            }
+
+
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public byte[] encode() {
+        JSONObject jsonObj = new JSONObject();
+        try {
+            // 消息携带用户信息时, 自定义消息需添加下面代码
+            JSONObject jsonUserInfo = this.getJSONUserInfo();
+            if (jsonUserInfo != null) {
+                jsonObj.putOpt("user", jsonUserInfo);
+            }
+
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+
+        try {
+            return jsonObj.toString().getBytes("UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        ParcelUtils.writeToParcel(dest, getExtra());
+        ParcelUtils.writeToParcel(dest, getUserInfo());
+    }
+
+    protected RCLiveUnderAllMicMessage(Parcel in) {
+        this.setExtra(ParcelUtils.readFromParcel(in));
+        this.setUserInfo((UserInfo) ParcelUtils.readFromParcel(in, UserInfo.class));
+    }
+
+    public static final Creator<RCLiveUnderAllMicMessage> CREATOR = new Creator<RCLiveUnderAllMicMessage>() {
+        @Override
+        public RCLiveUnderAllMicMessage createFromParcel(Parcel source) {
+            return new RCLiveUnderAllMicMessage(source);
+        }
+
+        @Override
+        public RCLiveUnderAllMicMessage[] newArray(int size) {
+            return new RCLiveUnderAllMicMessage[size];
+        }
+    };
+}

+ 4 - 1
student/src/main/java/com/cooleshow/student/App.java

@@ -26,6 +26,8 @@ import com.rong.io.live.message.RCChatroomLocationMessage;
 import com.rong.io.live.message.RCLiveBlackUserBlockMessage;
 import com.rong.io.live.message.RCLiveBlackUserUnBlockMessage;
 import com.rong.io.live.message.RCLiveGoodsChangeMessage;
+import com.rong.io.live.message.RCLiveRefuseAllMicApplyMessage;
+import com.rong.io.live.message.RCLiveUnderAllMicMessage;
 import com.rong.io.live.message.RCOnSnappingUpMessage;
 import com.rong.io.live.message.RCPauseLiveMessage;
 import com.rong.io.live.message.RCUserAddLikeMessage;
@@ -172,7 +174,8 @@ public class App extends BaseApplication {
         RongIMClient.registerMessageType(RCOnSnappingUpMessage.class);//XXX正在抢购
         RongIMClient.registerMessageType(RCLiveBlackUserBlockMessage.class);//添加黑名单
         RongIMClient.registerMessageType(RCLiveBlackUserUnBlockMessage.class);//解除黑名单
-
+        RongIMClient.registerMessageType(RCLiveUnderAllMicMessage.class);//全部下麦消息
+        RongIMClient.registerMessageType(RCLiveRefuseAllMicApplyMessage.class);//拒绝全部连麦申请消息
         LiveRTCEngineInitHelper.initRTC();
         EmojiManager.install(new IosEmojiProvider());
         /**

+ 14 - 1
student/src/main/java/com/cooleshow/student/contract/LiveRoomContract.java

@@ -153,10 +153,12 @@ public interface LiveRoomContract {
 
         /**
          * 黑名单用户状态切换
+         *
          * @param userId
          * @param isAddBlack
          */
-        void changeBlackUserStatus(String userId,boolean isAddBlack);
+        void changeBlackUserStatus(String userId, boolean isAddBlack);
+
         /**
          * 加入房间消息
          *
@@ -173,9 +175,20 @@ public interface LiveRoomContract {
 
         /**
          * 远端有用户推流
+         *
          * @param remoteUserId
          */
         void onRemoteUserPublishResource(String remoteUserId);
+
+        /**
+         * 拒绝全部连麦申请
+         */
+        void onRefuseAllMicApply();
+
+        /**
+         * 全部下麦
+         */
+        void onUnderAllMic();
     }
 
     interface Presenter {

+ 17 - 1
student/src/main/java/com/cooleshow/student/presenter/live/LiveRoomPresenter.java

@@ -102,7 +102,7 @@ public class LiveRoomPresenter extends BasePresenter<LiveRoomContract.view> impl
 
                     @Override
                     public void onFail(int errorCode, String errorStr) {
-                        LogUtils.i("pq","subscribeTargetStream fail:errorCode:"+errorCode+"errorStr:"+errorStr);
+                        LogUtils.i("pq", "subscribeTargetStream fail:errorCode:" + errorCode + "errorStr:" + errorStr);
                     }
                 });
             }
@@ -878,6 +878,22 @@ public class LiveRoomPresenter extends BasePresenter<LiveRoomContract.view> impl
                             }
                             return;
                         }
+
+                        if (TextUtils.equals(message.getObjectName(), LiveRoomMsgConstants.TAG_LIVE_UNDER_ALL_MIC)) {
+                            //全部下麦消息
+                            if (getView() != null) {
+                                getView().onUnderAllMic();
+                            }
+                            return;
+                        }
+
+                        if (TextUtils.equals(message.getObjectName(), LiveRoomMsgConstants.TAG_LIVE_REFUSE_ALL_MIC_APPLY)) {
+                            //拒绝全部连麦
+                            if (getView() != null) {
+                                getView().onRefuseAllMicApply();
+                            }
+                            return;
+                        }
                     }
                 });
         disposablesManager.add(subscribe);

+ 20 - 0
student/src/main/java/com/cooleshow/student/ui/live/LiveRoomActivity.java

@@ -1182,6 +1182,26 @@ public class LiveRoomActivity extends BaseMVPActivity<ActivityLiveroomLayoutBind
     }
 
     @Override
+    public void onRefuseAllMicApply() {
+        if (isFinishing() || isDestroyed()) {
+            return;
+        }
+        updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_NORMAL);
+        ToastUtil.getInstance().show(LiveRoomActivity.this, getString(R.string.create_refuse_seat_tip));
+    }
+
+    @Override
+    public void onUnderAllMic() {
+        if (isFinishing() || isDestroyed()) {
+            return;
+        }
+        if (presenter != null) {
+            presenter.exitMic();
+        }
+        ToastUtil.getInstance().show(LiveRoomActivity.this, getString(R.string.down_mic_by_create_tip));
+    }
+
+    @Override
     public void syncMemberCount(String count) {
         //同步成员数量
         Log.i("pq", "syncMemberCount" + count);

+ 5 - 0
teacher/src/main/java/com/cooleshow/teacher/App.java

@@ -20,6 +20,8 @@ import com.rong.io.live.message.RCChatModeMessage;
 import com.rong.io.live.message.RCChatRoomCloseMessage;
 import com.rong.io.live.message.RCChatRoomMemberNumMessage;
 import com.rong.io.live.message.RCChatroomLocationMessage;
+import com.rong.io.live.message.RCLiveRefuseAllMicApplyMessage;
+import com.rong.io.live.message.RCLiveUnderAllMicMessage;
 import com.rong.io.live.message.RCOnSnappingUpMessage;
 import com.rong.io.live.message.RCPauseLiveMessage;
 import com.rong.io.live.message.RCUserAddLikeMessage;
@@ -64,6 +66,7 @@ import io.rong.push.pushconfig.PushConfig;
  */
 public class App extends BaseApplication {
     public static boolean isRefresh = false;
+
     //static 代码段可以防止内存泄露
     static {
         //设置全局的Header构建器
@@ -158,6 +161,8 @@ public class App extends BaseApplication {
         RongIMClient.registerMessageType(RCUserAddLikeMessage.class);//点赞数量消息
         RongIMClient.registerMessageType(RCChatRoomMemberNumMessage.class);//成员数量同步
         RongIMClient.registerMessageType(RCPauseLiveMessage.class);//暂停直播消息
+        RongIMClient.registerMessageType(RCLiveUnderAllMicMessage.class);//全部下麦消息
+        RongIMClient.registerMessageType(RCLiveRefuseAllMicApplyMessage.class);//拒绝全部连麦申请消息
         LiveRTCEngineInitHelper.initRTC();
         EmojiManager.install(new IosEmojiProvider());
 

+ 16 - 0
teacher/src/main/java/com/cooleshow/teacher/presenter/live/LiveRoomPresenter.java

@@ -27,6 +27,8 @@ import com.rong.io.live.manager.RCChatRoomMessageManager;
 import com.rong.io.live.message.RCChatJoinRoomMessage;
 import com.rong.io.live.message.RCChatRoomMemberNumMessage;
 import com.rong.io.live.message.RCChatroomLocationMessage;
+import com.rong.io.live.message.RCLiveRefuseAllMicApplyMessage;
+import com.rong.io.live.message.RCLiveUnderAllMicMessage;
 import com.rong.io.live.message.RCOnSnappingUpMessage;
 import com.rong.io.live.message.RCPauseLiveMessage;
 import com.rong.io.live.message.RCUserAddLikeMessage;
@@ -393,6 +395,20 @@ public class LiveRoomPresenter extends BasePresenter<LiveRoomContract.LiveRoomVi
             sendMessage(pauseLiveMessage, false);
             return;
         }
+
+        if (action == LiveRoomMsgConstants.ACTION_SEND_REFUSE_ALL_MIC_APPLY_MSG) {
+            //发送拒绝全部连麦申请消息
+            RCLiveRefuseAllMicApplyMessage rcLiveRefuseAllMicApplyMessage = new RCLiveRefuseAllMicApplyMessage();
+            sendMessage(rcLiveRefuseAllMicApplyMessage, false);
+            return;
+        }
+
+        if (action == LiveRoomMsgConstants.ACTION_SEND_UNDER_ALL_MIC_MSG) {
+            //发送全部下麦消息
+            RCLiveUnderAllMicMessage rcLiveUnderAllMicMessage = new RCLiveUnderAllMicMessage();
+            sendMessage(rcLiveUnderAllMicMessage, false);
+            return;
+        }
     }
 
     /**

+ 7 - 3
teacher/src/main/java/com/cooleshow/teacher/ui/live/LiveOnMicFragment.java

@@ -29,7 +29,7 @@ import androidx.recyclerview.widget.RecyclerView;
  * Author by pq, Date on 2022/6/13.
  * 直播间连麦中列表页面
  */
-public class LiveOnMicFragment extends BaseFragment<FragmentLiveOnMicLayoutBinding> {
+public class LiveOnMicFragment extends BaseFragment<FragmentLiveOnMicLayoutBinding> implements View.OnClickListener {
     RecyclerView recyclerView;
     private LiveMicManagerDialog.OnEventListener mEventListener;
     private ArrayList<User> mList = new ArrayList<>();
@@ -50,14 +50,15 @@ public class LiveOnMicFragment extends BaseFragment<FragmentLiveOnMicLayoutBindi
     protected void initData() {
         LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
         recyclerView.setLayoutManager(linearLayoutManager);
+        mViewBinding.tvDownAllMic.setOnClickListener(this);
         mAdapter = new Adapter(R.layout.item_live_mic_manager_layout, mList);
         mAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
             @Override
             public void onItemChildClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                 int id = view.getId();
-                if(id == R.id.tv_handle){
+                if (id == R.id.tv_handle) {
                     //下麦操作
-                    if(mAdapter!=null && position<mAdapter.getData().size()){
+                    if (mAdapter != null && position < mAdapter.getData().size()) {
                         User user = mAdapter.getData().get(position);
                         if (mEventListener != null) {
                             mEventListener.onUnderMic(user);
@@ -73,6 +74,9 @@ public class LiveOnMicFragment extends BaseFragment<FragmentLiveOnMicLayoutBindi
         int id = view.getId();
         if (id == R.id.tv_down_all_mic) {
             //全部下麦
+            if (mEventListener != null) {
+                mEventListener.onUnderAllMic();
+            }
             return;
         }
     }

+ 20 - 0
teacher/src/main/java/com/cooleshow/teacher/ui/live/TeacherLiveRoomActivity.java

@@ -1246,14 +1246,34 @@ public class TeacherLiveRoomActivity extends BaseMVPActivity<ActivityTeacherLive
                         mRoomMicMemberHelper.delAllApplyUser();
                     }
                     updateMicManagerData();
+                    if (presenter != null) {
+                        presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_REFUSE_ALL_MIC_APPLY_MSG);
+                    }
                 }
 
                 @Override
                 public void onSwitchMicMode(boolean isEnable) {
+                    if (isEnable) {
+                        if (mRoomMicMemberHelper != null) {
+                            mRoomMicMemberHelper.delAllApplyUser();
+                        }
+                        updateMicManagerData();
+                    }
                     if (presenter != null) {
                         presenter.handleAction(LiveRoomMsgConstants.ACTION_SWITCH_MIC_MODE, isEnable);
                     }
                 }
+
+                @Override
+                public void onUnderAllMic() {
+                    if (mRoomMicMemberHelper != null) {
+                        mRoomMicMemberHelper.delAllOnMicUser();
+                    }
+                    updateMicManagerData();
+                    if (presenter != null) {
+                        presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_UNDER_ALL_MIC_MSG);
+                    }
+                }
             });
         }
         if (!mLiveMicManagerDialog.isShowing()) {

+ 2 - 0
teacher/src/main/java/com/cooleshow/teacher/widgets/dialog/LiveMicManagerDialog.java

@@ -168,5 +168,7 @@ public class LiveMicManagerDialog extends Dialog implements View.OnClickListener
 
         //连麦模式控制
         void onSwitchMicMode(boolean isEnable);
+        //全部下麦
+        void onUnderAllMic();
     }
 }