更新多人连麦主播端部分代码注释

限制多人连麦直播端仅允许同意/邀请三人
This commit is contained in:
zlzw 2022-11-23 15:21:44 +08:00
parent d42835231e
commit 91fdef55c7
3 changed files with 74 additions and 38 deletions

View File

@ -66,6 +66,7 @@ import com.yunbao.live.bean.LiveGuardInfo;
import com.yunbao.live.bean.LiveKsyConfigBean;
import com.yunbao.live.bean.LiveReceiveGiftBean;
import com.yunbao.live.bean.LiveUserGiftBean;
import com.yunbao.live.bean.MicUserBean;
import com.yunbao.live.dialog.LiveLinkMicListDialogFragment;
import com.yunbao.live.dialog.LiveMicAnchorDialogFragment;
import com.yunbao.live.dialog.LiveNewFunctionDialogFragment;
@ -1321,7 +1322,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
}
break;
case LINK_MIC:
if(!StringUtil.isEmpty(((LinkMicUserBean) event.getObject()).getUid())) {
if (!StringUtil.isEmpty(((LinkMicUserBean) event.getObject()).getUid())) {
mMicQueueList.put(((LinkMicUserBean) event.getObject()).getUid(), (LinkMicUserBean) event.getObject());
}
if (micListener != null) {
@ -1338,7 +1339,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
List<LinkMicUserBean> list = (List<LinkMicUserBean>) event.getObject();
mMicQueueList.clear();
for (LinkMicUserBean bean : list) {
if(!StringUtil.isEmpty(bean.getUid())) {
if (!StringUtil.isEmpty(bean.getUid())) {
mMicQueueList.put(bean.getUid(), bean);
}
}
@ -1355,4 +1356,26 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
}
}
/**
* 检查指定直播间连麦人数
*
* @param mLiveUid 直播间
*/
public static void checkMicUserLength(String mLiveUid, LiveFunctionClickListener listener) {
LiveHttpUtil.getMicList(mLiveUid, 0, new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0) {
try {
JSONObject obj = JSON.parseObject(info[0]);
List<MicUserBean> list = JSON.parseArray(obj.getString("userlist"), MicUserBean.class);
listener.onClick(list.size());
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
}

View File

@ -27,11 +27,14 @@ import com.yunbao.common.http.API;
import com.yunbao.common.http.ResponseModel;
import com.yunbao.common.utils.CommonIconUtil;
import com.yunbao.common.utils.SVGAViewUtils;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.live.R;
import com.yunbao.live.activity.LiveActivity;
import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.activity.LiveRyAnchorActivity;
import com.yunbao.live.bean.MicUserBean;
import com.yunbao.live.event.LiveRoomChangeEvent;
import com.yunbao.live.interfaces.LiveFunctionClickListener;
import com.yunbao.live.socket.SocketSendBean;
import org.greenrobot.eventbus.EventBus;
@ -116,12 +119,23 @@ public class AnchorUserMicInfoAdapter extends RefreshAdapter<MicUserBean> {
mBtn.setOnClickListener(v -> {
if (v.getTag() != null) {
MicUserBean tag = (MicUserBean) v.getTag();
if (tag.getType() == TYPE_MIC_REQUEST) {
applyMic(tag, 4, createSocketSendBean());
} else if (tag.getType() == TYPE_MIC_INVITE) {
SocketSendBean bean = createSocketSendBean().param("targetId", tag.getId());
applyMic(tag, 1, bean);
}
LiveRyAnchorActivity.checkMicUserLength(mLiveUid, new LiveFunctionClickListener() {
@Override
public void onClick(int length) {
//只允许最多3人连麦加主播4人
if (length < 4) {
if (tag.getType() == TYPE_MIC_REQUEST) {
applyMic(tag, 4, createSocketSendBean());
} else if (tag.getType() == TYPE_MIC_INVITE) {
SocketSendBean bean = createSocketSendBean().param("targetId", tag.getId());
applyMic(tag, 1, bean);
}
}else{
ToastUtil.show("仅允许三人与主播连麦");
}
}
});
}
});
mClose.setOnClickListener(v -> {
@ -149,6 +163,10 @@ public class AnchorUserMicInfoAdapter extends RefreshAdapter<MicUserBean> {
.param("uid", CommonAppConfig.getInstance().getUid());
}
/**
* 发送IM消息
* @param action 4为同意请求1为邀请其余见 {@link com.yunbao.live.socket.SocketRyClient} Constants.LIAN_MAI解析
*/
void applyMic(MicUserBean bean, int action, SocketSendBean msg) {
msg.param("action", action);
msg.create();

View File

@ -153,44 +153,35 @@ public class LiveMicAnchorDialogFragment extends AbsDialogFragment implements Vi
mNoMoreDesc = mRootView.findViewById(R.id.no_more_desc);
Tips = bundle.getString("By");
listMicbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isOpenRoom()) {
return;
}
Tips = "1";
Up();
type = "guanzhong";
mRefreshView.initData();
listMicbtn.setOnClickListener(view -> {
if (!isOpenRoom()) {
return;
}
Tips = "1";
Up();
type = "guanzhong";
mRefreshView.initData();
});
requestMicBtn = mRootView.findViewById(R.id.guard_btn);
requestMicBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isOpenRoom()) {
return;
}
Tips = "2";
Up();
type = "guard";
mRefreshView.initData();
requestMicBtn.setOnClickListener(view -> {
if (!isOpenRoom()) {
return;
}
Tips = "2";
Up();
type = "guard";
mRefreshView.initData();
});
inviteMicBtn = mRootView.findViewById(R.id.fans_btn);
inviteMicBtn.setVisibility(View.VISIBLE);
inviteMicBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isOpenRoom()) {
return;
}
Tips = "3";
Up();
type = "fans";
mRefreshView.initData();
inviteMicBtn.setOnClickListener(view -> {
if (!isOpenRoom()) {
return;
}
Tips = "3";
Up();
type = "fans";
mRefreshView.initData();
});
mOpenMicBtn.setOnClickListener(v -> {
API.get().pdLiveApi(mContext)
@ -362,6 +353,7 @@ public class LiveMicAnchorDialogFragment extends AbsDialogFragment implements Vi
@Override
public void onSuccess(int code, String msg, String[] info) {
System.out.println("code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info));
//非0认为未开通连麦权限
if (code != 0) {
mOpenMicLayout.setVisibility(View.VISIBLE);
mRefreshView.setVisibility(View.GONE);
@ -399,6 +391,9 @@ public class LiveMicAnchorDialogFragment extends AbsDialogFragment implements Vi
}
/**
* 用于更新连麦对话框数据
*/
public interface OnMicListener {
void updateMicList(TreeMap<String, LinkMicUserBean> list);