SeatGridView
的麦位管理能力。SeatGridView
支持如下麦位管理能力:SeatGridView
模块,然后创建一个 SeatGridView 视图对象,并将其添加到自己的视图上。import UIKitimport RTCRoomEngineimport SeatGridViewclass SeatManagementController: UIViewController {private let seatGridView: SeatGridView = {let view = SeatGridView()return view}()override func viewDidLoad() {super.viewDidLoad()seatGridView.addObserver(observer: self)// 将 seatGridView 添加到视图上,同时设置好布局约束}deinit {seatGridView.removeObserver(observer: self)}}
import com.trtc.uikit.livekit.seatGridView.SeatGridView;public class SeatManagementActivity extends AppCompatActivity {@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);SeatGridView seatGridView = new SeatGridView(this);addContentView(seatGridView,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));}}
applyToTake
)”时,申请上麦需要等待房主同意才可上麦。freeToTake
)”时,申请上麦无需等待房主同意,可直接上麦。takeSeat
接口,传入两个参数: 麦位索引和超时时长。let index = 1 // 请将这里替换成您想要申请的麦位号let timeout = 30 // 请将这里替换成您申请上麦的超时时间,单位秒,如果设置为 0,SDK 不会做超时检测,也不会触发超时回调self.seatGridView.takeSeat(index: index, timeout: timeout) { userInfo in// 上麦申请被接受} onRejected: { userInfo in// 上麦申请被拒绝} onCancelled: { userInfo in// 上麦申请被取消} onTimeout: { userInfo in// 上麦申请已超时} onError: { userInfo, code, message in// 上麦异常}
int index = 1; // 请将这里替换成您想要申请的麦位号int timeout = 30; // 请将这里替换成您申请上麦的超时时间,单位秒,如果设置为 0,SDK 不会做超时检测,也不会触发超时回调seatGridView.takeSeat(index, timeout, new TUIRoomDefine.RequestCallback() {@Overridepublic void onAccepted(String requestId, String userId) {// 上麦申请被接受}@Overridepublic void onRejected(String requestId, String userId, String message) {// 上麦申请被拒绝}@Overridepublic void onCancelled(String requestId, String userId) {// 上麦申请被取消}@Overridepublic void onTimeout(String requestId, String userId) {// 上麦申请已超时}@Overridepublic void onError(String requestId, String userId, TUICommonDefine.Error error, String message) {// 上麦异常}});
onSeatRequestReceived
回调,您可通过调用 responseRemoteRequest
同意/拒绝对方的上麦申请。func onSeatRequestReceived(type: SGRequestType, userInfo: TUIUserInfo) {if type == .applyToTakeSeat {let agree = true // true为self.seatGridView.responseRemoteRequest(userId: userInfo.userId, agree: true) {// 同意上麦成功} onError: { code, message in// 同意上麦失败}}}
void onSeatRequestReceived(VoiceRoomDefine.RequestType type, TUIRoomDefine.UserInfo userInfo) {if (type == APPLY_TO_TAKE_SEAT) {boolean agree = true; // true:同意连麦, false:拒绝连麦seatGridView.seatGridView.responseRemoteRequest(userInfo.userId, agree, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess () {// 同意上麦成功}@Overridepublic void onError (TUICommonDefine.Error error, String message) {// 同意上麦成功}});}}
leaveSeat
接口。self.seatGridView.leaveSeat {// 主动下麦成功} onError: { code, message in// 主动下麦失败}
seatGridView.leaveSeat(new TUIRoomDefine.ActionCallback {@Overridepublic void onSuccess () {// 主动下麦成功}@Overridepublic void onError (TUICommonDefine.Error error, String message) {// 主动下麦失败}});
moveToSeat
接口,传入需要切换的麦位索引。let index = 2self.seatGridView.moveToSeat(index: destinationIndex) {// 移动麦位成功} onError: { code, message in// 移动麦位失败}
int index = 2;seatGridView.moveToSeat(index, new TUIRoomDefine.ActionCallback {@Overridepublic void onSuccess () {//移动麦位成功}@Overridepublic void onError (TUICommonDefine.Error error, String message) {// 移动麦位失败}});
takeUserOnSeatByAdmin
接口,传入三个参数:被邀请上麦的麦位索引、超时时间和被邀请上麦的用户Id。let tartgetIndex = 4let timeout = 30let targetUserId = "100002" // 请替换成您想要踢下麦的主播的用户Idself.takeUserOnSeatByAdmin
(
index
:
targetIndex
,
timeout
:
timeout
,
userId
:
targetUserId
)
{
// 上麦邀请被接受
}
onRejected: { userInfo in
// 上麦邀请被拒绝
} onTimeout: { userInfo in
// 上麦邀请超时
} onCancelled: { userInfo in
// 上麦邀请被取消
} onError: { userInfo, code, message in
// 上麦邀请异常
}
int tartgetIndex = 4;int timeout = 30;String targetUserId = "100002"; // 请替换成您想要踢下麦的主播的用户IdseatGridView.takeUserOnSeatByAdmin(targetIndex, timeout, targetUserId, new new TUIRoomDefine.RequestCallback() {@Overridepublic void onAccepted(String requestId, String userId) {// 上麦邀请被接受}@Overridepublic void onRejected(String requestId, String userId, String message) {// 上麦邀请被拒绝}@Overridepublic void onCancelled(String requestId, String userId) {// 上麦邀请被取消}@Overridepublic void onTimeout(String requestId, String userId) {// 上麦邀请已超时}@Overridepublic void onError(String requestId, String userId, TUICommonDefine.Error error, String message) {// 上麦邀请异常}});
responseRemoteRequest
同意/拒绝对方的上麦邀请。func onSeatRequestReceived(type: SGRequestType, userInfo: TUIUserInfo) {if type == .inviteToTakeSeat {let isAccepted = true // true表示同意邀请, false表示拒绝邀请self.seatGridView.responseRemoteRequest(userId: userInfo.userId, agree: isAccepted) {// 同意上麦邀请成功} onError: { code, message in// 同意上麦邀请失败}}}
void onSeatRequestReceived(VoiceRoomDefine.RequestType type, TUIRoomDefine.UserInfo userInfo) {if (type == INVITE_TO_TAKE_SEAT) {boolean isAccepted = true; // true表示同意邀请, false表示拒绝邀请seatGridView.responseRemoteRequest(userInfo.userId, isAccepted, new TUIRoomDefine.ActionCallback {@Overridepublic void onSuccess () {// 同意上麦邀请成功}@Overridepublic void onError (TUICommonDefine.Error error, String message) {// 同意上麦邀请失败}});}}
kickUserOffSeatByAdmin
接口,传入想要踢下麦的用户Id。let targetUserId = "100002" // 请替换成您想要踢下麦的主播的用户Idself.seatGridView.kickUserOffSeatByAdmin
(
userId
:
targetUserId
)
{
// 踢人下麦成功
}
onError
:
{
code
,
message
in
// 踢人下麦失败
}
String targetUserId = "100002"; // 请替换成您想要踢下麦的主播的用户IdseatGridView.kickUserOffSeatByAdmin(targetUserId, new TUIRoomDefine.ActionCallback {@Overridepublic void onSuccess () {// 踢人下麦成功}@Overridepublic void onError (TUICommonDefine.Error error, String message) {// 踢人下麦失败}});
lockSeat
接口,传入两个参数:将要锁定的麦位索引和锁定模式。TUISeatLockParams
)的结构如下:属性名称 | 字段含义 | 补充说明 | 数据类型 | 填写示例 |
lockSeat | 锁定麦位 | 锁定对应麦位则该麦位不允许申请上麦。 | 布尔值 | 当锁定麦位时为true |
lockVideo | 锁定麦位摄像头 | 锁定对应麦位摄像头则该麦位不再发布视频流。 | 布尔值 | false |
lockAudio | 锁定麦位麦克风 | 锁定对应麦位摄像头则该麦位不再发布音频流。 | 布尔值 | 当锁定麦位麦克风时为true |
// 锁定麦位let lockSeatIndex = 5let lockSeatParam = TUISeatLockParams()lockSeatParam.lockSeat = trueself.seatGridView.lockSeat(index: lockSeatIndex, lockMode: lockSeatParam) {// 锁定麦位成功} onError: { code, message in// 锁定麦位失败}// 锁定麦位麦克风let lockSeatAudioIndex = 6let lockSeatAudioParam = TUISeatLockParams()lockSeatAudioParam.lockAudio = trueself.seatGridView.lockSeat(index: lockSeatAudioIndex, lockMode: lockSeatAudioParam) {// 锁定麦位麦克风成功} onError: { code, message in// 锁定麦位麦克风失败}
// 锁定麦位int lockSeatIndex = 5;TUIRoomDefine.SeatLockParams lockSeatParam = new TUIRoomDefine.SeatLockParams();lockSeatParam.lockSeat = true;seatGridView.lockSeat(lockSeatIndex, lockSeatParam, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// 锁定麦位成功}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// 锁定麦位失败}});// 锁定麦位麦克风int lockSeatIndex = 6;TUIRoomDefine.SeatLockParams lockSeatAudioParam = new TUIRoomDefine.SeatLockParams();lockSeatAudioParam.lockAudio = true;seatGridView.lockSeat(lockSeatIndex, lockSeatAudioParam, new TUIRoomDefine.ActionCallback() {@Overridepublic void onSuccess() {// 锁定麦位麦克风成功}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// 锁定麦位麦克风失败}});
本页内容是否解决了您的问题?