麦位管理
更新时间: 2024/11/22 10:04:30
NERoom 的麦位管理功能包括:上麦、下麦、抱麦、踢麦等。在语聊房、 K 歌、直播等场景中,主播和观众连麦是非常热门的玩法。通过多人实时互动,可以活跃房间氛围、激发观众参与热情,进而提升产品活跃度。
注意事项
- 您可以在创建房间时,设置麦位相关的初始化配置,包括麦位数量和麦位申请审批模式,具体请参见 创建房间 。
- 目前只支持在创建房间时设置麦位数量,麦位数量最大为 20,在房间正常使用过程中无法修改麦位数量。
添加麦位事件监听
主播和观众进入房间后,调用 addSeatListener
接口,监听麦位相关的事件。
示例代码如下:
NERoomService roomService = NERoomKit.getInstance().getService(NERoomService.class);
NERoomContext roomContext = roomService.getRoomContext(roomUuid);
if (roomContext != null) {
roomContext.getSeatController().addSeatListener(new NESeatEventListener() {
@Override
public void onSeatManagerAdded(List<String> managers) {
}
@Override
public void onSeatManagerRemoved(List<String> managers) {
}
@Override
public void onSeatRequestSubmitted(int seatIndex, String user) {
}
@Override
public void onSeatRequestCancelled(int seatIndex, String user) {
}
@Override
public void onSeatRequestApproved(int seatIndex, String user, String operateBy, boolean isAutoAgree) {
}
@Override
public void onSeatRequestRejected(int seatIndex, String user, String operateBy) {
}
@Override
public void onSeatInvitationReceived(int seatIndex, String user, String operateBy) {
}
@Override
public void onSeatInvitationCancelled(int seatIndex, String user, String operateBy) {
}
@Override
public void onSeatInvitationAccepted(int seatIndex,String user, boolean isAutoAgree) {
}
@Override
public void onSeatInvitationRejected(int seatIndex, String user) {
}
@Override
public void onSeatLeave(int seatIndex, String user) {
}
@Override
public void onSeatKicked(int seatIndex, String user, String operateBy) {
}
@Override
public void onSeatListChanged(List<NESeatItem> seatItems) {
}
});
}
主播邀请观众上麦(抱麦)
API 调用时序图
sequenceDiagram
actor hostClientA as 主播A client
participant NERoomA as NERoom
participant app_server as NERoom_Server
participant NERoomB as NERoom
actor audienceB as 观众 B client
note over app_server:抱观众上麦
hostClientA ->> NERoomA:邀请上麦<br>sendSeatInvitation
NERoomA ->> app_server:邀请上麦<br>sendSeatInvitation
app_server ->> NERoomB:自动同意上麦的回调<br>onSeatInvitationAccepted
NERoomB ->> audienceB:自动同意上麦的回调<br>onSeatInvitationAccepted
app_server ->> NERoomB:麦位变更的回调<br>onSeatListChanged
NERoomB ->> audienceB:麦位变更的回调<br>onSeatListChanged
app_server ->> NERoomA:自动同意上麦的回调<br>onSeatInvitationAccepted
NERoomA ->> hostClientA:自动同意上麦的回调<br>onSeatInvitationAccepted
app_server ->> NERoomA:麦位变更的回调<br>onSeatListChanged
NERoomA ->> hostClientA:麦位变更的回调<br>onSeatListChanged
audienceB ->>audienceB:刷新UI
hostClientA ->>hostClientA:刷新UI
实现方法
-
主播调用
sendSeatInvitation
接口邀请观众上麦。参数 类型 描述 seatIndex Integer 麦位位置。
麦位的最大数量可以在创建房间时设置。user String 待邀请的观众的用户 ID。 -
(可选)观众调用
acceptSeatInvitation
接口同意上麦邀请,或调用rejectSeatInvitation
接口拒绝上麦邀请。 -
触发同意上麦的回调
onSeatInvitationAccepted
和麦位变更的回调onSeatListChanged
。 -
房间内所有成员收到
onSeatListChanged
回调后,刷新麦位展示的 UI。
示例代码
主播邀请观众上麦的示例代码如下:
String userId = "56789";
NERoomService roomService = NERoomKit.getInstance().getService(NERoomService.class);
NERoomContext roomContext = roomService.getRoomContext(roomUuid);
if (roomContext != null) {
roomContext.getSeatController().sendSeatInvitation(userId,new NECallback2<Unit>() {
@Override
public void onSuccess(@Nullable Unit unit) {
super.onSuccess(unit);
Log.d(TAG,"success");
}
@Override
public void onError(int code, @Nullable String message) {
super.onError(code, message);
Log.d(TAG,"error");
}
});
}
主播邀请观众上麦时指定麦位的示例代码如下:
String userId = "56789";
int index = 2;
NERoomService roomService = NERoomKit.getInstance().getService(NERoomService.class);
NERoomContext roomContext = roomService.getRoomContext(roomUuid);
if (roomContext != null) {
roomContext.getSeatController().sendSeatInvitation(index,userId,new NECallback2<Unit>() {
@Override
public void onSuccess(@Nullable Unit unit) {
super.onSuccess(unit);
Log.d(TAG,"success");
}
@Override
public void onError(int code, @Nullable String message) {
super.onError(code, message);
Log.d(TAG,"error");
}
});
}
观众申请上麦
API 调用时序
sequenceDiagram
actor hostClientA as 主播A client
participant NERoomA as NERoom
participant app_server as NERoom_Server
participant NERoomB as NERoom
actor audienceB as 观众 B client
note over app_server:观众申请上麦
audienceB ->> NERoomB:申请上麦<br>submitSeatRequest
NERoomB ->> app_server:申请上麦<br>submitSeatRequest
app_server ->> NERoomA:观众B申请上麦的回调<br>onSeatRequestSubmitted
NERoomA ->> hostClientA:观众B申请上麦的回调<br>onSeatRequestSubmitted
app_server ->> NERoomA:麦位变更的回调<br>onSeatListChanged
NERoomA ->> hostClientA:麦位变更的回调<br>onSeatListChanged
hostClientA ->>hostClientA:刷新UI
alt 主播同意上麦申请
hostClientA ->>NERoomA:主播同意上麦申请<br>approveSeatRequest
NERoomA ->>app_server:主播同意上麦申请<br>approveSeatRequest
app_server ->>NERoomA:主播同意上麦申请的回调<br>onSeatRequestApproved
NERoomA ->>hostClientA:主播同意上麦申请的回调<br>onSeatRequestApproved
app_server ->> NERoomA:麦位变更的回调<br>onSeatListChanged
NERoomA ->> hostClientA:麦位变更的回调<br>onSeatListChanged
app_server ->>NERoomB:主播同意上麦申请的回调<br>onSeatRequestApproved
NERoomB ->>audienceB:主播同意上麦申请的回调<br>onSeatRequestApproved
app_server ->> NERoomB:麦位变更的回调<br>onSeatListChanged
NERoomB ->> audienceB:麦位变更的回调<br>onSeatListChanged
audienceB ->>audienceB:刷新UI
hostClientA ->>hostClientA:刷新UI
else 主播拒绝上麦申请
hostClientA ->>NERoomA:主播不同意上麦申请<br>rejectRequestSeat
NERoomA ->>app_server:主播不同意上麦申请<br>rejectRequestSeat
app_server ->>NERoomA:主播拒绝观众B上麦的回调<br>onSeatRequestRejected
NERoomA ->>hostClientA:主播拒绝观众B上麦的回调<br>onSeatRequestRejected
app_server ->> NERoomA:麦位变更的回调<br>onSeatListChanged
NERoomA ->> hostClientA:麦位变更的回调<br>onSeatListChanged
app_server ->>NERoomB:主播拒绝观众B上麦的回调<br>onSeatRequestRejected
NERoomB ->>audienceB:主播拒绝观众B上麦的回调<br>onSeatRequestRejected
audienceB ->>audienceB:刷新UI
hostClientA ->>hostClientA:刷新UI
end
实现方法
-
观众 B 调用
submitSeatRequest
接口申请上麦。参数 类型 描述 seatIndex Integer 指定上麦后的麦位位置。
该参数为可选,如果不传该参数,则自动占用当前空的麦位中的第一个。
麦位的最大数量可以在创建房间时设置。 -
主播收到观众 B 申请上麦的回调
onSeatRequestSubmitted
。 -
主播同意或拒绝观众 B 上麦。
-
主播调用
approveSeatRequest
接口同意观众 B 上麦。 -
主播调用
rejectSeatRequest
接口拒绝观众 B 上麦。
参数 类型 描述 user String 申请上麦的观众的用户 ID。 -
-
观众 B 收到主播同意上麦申请的回调
onSeatRequestApproved
或主播拒绝上麦申请的回调onSeatRequestRejected
。
示例代码
//观众申请上麦时不指定麦位
NERoomService roomService = NERoomKit.getInstance().getService(NERoomService.class);
NERoomContext roomContext = roomService.getRoomContext(roomUuid);
if (roomContext != null) {
roomContext.getSeatController().submitSeatRequest(new NECallback2<Unit>() {
@Override
public void onSuccess(@Nullable Unit unit) {
super.onSuccess(unit);
Log.d(TAG,"success");
}
@Override
public void onError(int code, @Nullable String message) {
super.onError(code, message);
Log.d(TAG,"error");
}
});
}
//观众申请上麦时指定麦位
int seatIndex = 2;
NERoomService roomService = NERoomKit.getInstance().getService(NERoomService.class);
NERoomContext roomContext = roomService.getRoomContext(roomUuid);
if (roomContext != null) {
roomContext.getSeatController().submitSeatRequest(seatIndex,new NECallback2<Unit>() {
@Override
public void onSuccess(@Nullable Unit unit) {
super.onSuccess(unit);
Log.d(TAG,"success");
}
@Override
public void onError(int code, @Nullable String message) {
super.onError(code, message);
Log.d(TAG,"error");
}
});
}
//主播同意上麦申请
String userId = "56789";
NERoomService roomService = NERoomKit.getInstance().getService(NERoomService.class);
NERoomContext roomContext = roomService.getRoomContext(roomUuid);
if (roomContext != null) {
roomContext.getSeatController().approveSeatRequest(userId,new NECallback2<Unit>() {
@Override
public void onSuccess(@Nullable Unit unit) {
super.onSuccess(unit);
Log.d(TAG,"success");
}
@Override
public void onError(int code, @Nullable String message) {
super.onError(code, message);
Log.d(TAG,"error");
}
});
}
// 主播拒绝上麦申请
String userId = "56789";
NERoomService roomService = NERoomKit.getInstance().getService(NERoomService.class);
NERoomContext roomContext = roomService.getRoomContext(roomUuid);
if (roomContext != null) {
roomContext.getSeatController().rejectSeatRequest(userId,new NECallback2<Unit>() {
@Override
public void onSuccess(@Nullable Unit unit) {
super.onSuccess(unit);
Log.d(TAG,"success");
}
@Override
public void onError(int code, @Nullable String message) {
super.onError(code, message);
Log.d(TAG,"error");
}
});
}
主播将观众移出麦位(踢麦)
API 调用时序
sequenceDiagram
actor hostClientA as 主播A client
participant NERoomA as NERoom
participant app_server as NERoom_Server
participant NERoomB as NERoom
actor audienceB as 观众 B client
note over app_server:将观众移出麦位
hostClientA ->> NERoomA:主播踢观众B下麦<br>kickSeat
NERoomA ->> app_server:主播踢观众B下麦<br>kickSeat
app_server ->> NERoomB:主播踢观众B下麦的回调<br>onSeatKicked
NERoomB ->> audienceB:主播踢观众B下麦的回调<br>onSeatKicked
app_server ->> NERoomB:麦位变更的回调<br>onSeatListChanged
NERoomB ->> audienceB:麦位变更的回调<br>onSeatListChanged
app_server ->> NERoomA:主播踢观众B下麦的回调<br>onSeatKicked
NERoomA ->> hostClientA:主播踢观众B下麦的回调<br>onSeatKicked
app_server ->> NERoomA:麦位变更的回调<br>onSeatListChanged
NERoomA ->> hostClientA:麦位变更的回调<br>onSeatListChanged
audienceB ->>audienceB:刷新UI
hostClientA ->>hostClientA:刷新UI
实现方法
-
主播调用
kickSeat
接口将观众移出麦位。参数 类型 描述 user String 待移出麦位的观众的用户 ID。 -
房间内所有成员会收到主播将观众移出麦位的回调
onSeatKicked
和麦位变更的回调onSeatListChanged
。
示例代码
String userId = "56789";
NERoomService roomService = NERoomKit.getInstance().getService(NERoomService.class);
NERoomContext roomContext = roomService.getRoomContext(roomUuid);
if (roomContext != null) {
roomContext.getSeatController().kickSeat(userId,new NECallback2<Unit>() {
@Override
public void onSuccess(@Nullable Unit unit) {
super.onSuccess(unit);
Log.d(TAG,"success");
}
@Override
public void onError(int code, @Nullable String message) {
super.onError(code, message);
Log.d(TAG,"error");
}
});
}
观众取消申请上麦
API 调用时序
sequenceDiagram
actor hostClientA as 主播A client
participant NERoomA as NERoom
participant app_server as NERoom_Server
participant NERoomB as NERoom
actor audienceB as 观众 B client
note over app_server:观众取消申请上麦
audienceB ->>NERoomB:取消申请上麦<br>cancelSeatRequest
NERoomB ->>app_server:取消申请上麦<br>cancelSeatRequest
app_server ->>NERoomA:观众B取消上麦的回调<br>onSeatRequestCancelled
NERoomA ->>hostClientA:观众B取消上麦的回调<br>onSeatRequestCancelled
app_server ->> NERoomA:麦位变更的回调<br>onSeatListChanged
NERoomA ->> hostClientA:麦位变更的回调<br>onSeatListChanged
app_server ->>NERoomB:观众B取消上麦的回调<br>onSeatRequestCancelled
NERoomB ->>audienceB:观众B取消上麦的回调<br>onSeatRequestCancelled
app_server ->> NERoomB:麦位变更的回调<br>onSeatListChanged
NERoomB ->> audienceB:麦位变更的回调<br>onSeatListChanged
audienceB ->>audienceB:刷新UI
hostClientA ->>hostClientA:刷新UI
实现方法
- 观众调用
cancelSeatRequest
接口取消申请上麦。 - 取消申请上麦后,主播收到观众取消上麦的回调
onSeatRequestCancelled
和麦位变更的回调onSeatListChanged
。
示例代码
NERoomService roomService = NERoomKit.getInstance().getService(NERoomService.class);
NERoomContext roomContext = roomService.getRoomContext(roomUuid);
if (roomContext != null) {
roomContext.getSeatController().cancelSeatRequest(new NECallback2<Unit>() {
@Override
public void onSuccess(@Nullable Unit unit) {
super.onSuccess(unit);
Log.d(TAG,"success");
}
@Override
public void onError(int code, @Nullable String message) {
super.onError(code, message);
Log.d(TAG,"error");
}
});
}
观众主动下麦
API 调用时序
sequenceDiagram
actor hostClientA as 主播A client
participant NERoomA as NERoom
participant app_server as NERoom_Server
participant NERoomB as NERoom
actor audienceB as 观众 B client
note over app_server:观众主动下麦
audienceB ->>NERoomB:下麦<br>leaveSeat
NERoomB ->>app_server:下麦<br>leaveSeat
app_server ->>NERoomA:观众B成功下麦的回调<br>onSeatLeave
NERoomA ->>hostClientA:观众B成功下麦的回调<br>onSeatLeave
app_server ->> NERoomA:麦位变更的回调<br>onSeatListChanged
NERoomA ->> hostClientA:麦位变更的回调<br>onSeatListChanged
app_server ->>NERoomB:观众B成功下麦的回调<br>onSeatLeave
NERoomB ->>audienceB:观众B成功下麦的回调<br>onSeatLeave
app_server ->> NERoomB:麦位变更的回调<br>onSeatListChanged
NERoomB ->> audienceB:麦位变更的回调<br>onSeatListChanged
audienceB ->>audienceB:刷新UI
hostClientA ->>hostClientA:刷新UI
实现方法
- 观众调用
leaveSeat
接口下麦。 - 下麦成功后,房间内所有成员收到观众成功下麦的回调
onSeatLeave
和麦位变更的回调onSeatListChanged
。
示例代码
NERoomService roomService = NERoomKit.getInstance().getService(NERoomService.class);
NERoomContext roomContext = roomService.getRoomContext(roomUuid);
if (roomContext != null) {
roomContext.getSeatController().leaveSeat(new NECallback2<Unit>() {
@Override
public void onSuccess(@Nullable Unit unit) {
super.onSuccess(unit);
Log.d(TAG,"success");
}
@Override
public void onError(int code, @Nullable String message) {
super.onError(code, message);
Log.d(TAG,"error");
}
});
}
相关错误码
错误码 | 错误码描述 |
---|---|
1302 | 麦位已打开 |
1303 | 观众已申请上麦 |
1304 | 观众未申请上麦 |
1305 | 麦位已被其他观众占位 |
1306 | 观众已在麦上 |
1307 | 麦序未初始化 |
1308 | 麦序已初始化 |
1309 | 主播未将观众抱上麦 |
1310 | 麦位已关闭 |
1311 | 麦位都已被占,没有可用的麦位 |
1312 | 观众已被抱麦,无法再次被抱麦 |
1313 | 观众未在麦位上 |
1314 | 麦位数量不能超过 20 个 |
此文档是否对你有帮助?