SeatGridView

最近更新时间:2024-12-25 15:07:02

我的收藏

API 简介

SeatGridView 是我们开发语音聊天室 UIKit 的一个基础控件,该核心控件提供了开启语音聊天室、关闭语音聊天室,直播间内麦位管理,如申请上麦,邀请上麦,移动麦位,踢人下麦等丰富的 API。

API 概览

API
描述
创建 SeatGridView 对象
打开本地麦克风
关闭本地麦克风
暂停发布本地的音频流
恢复发布本地的音频流
主播创建直播间并开始推流
主播停止推流并销毁直播间
观众加入某个主播的直播间
观众离开某个主播的直播间
更新房间麦位模式
主播响应上麦申请/观众响应上麦邀请
主播取消上麦邀请/观众取消上麦申请
takeSeat
上麦
移麦
leaveSeat
下麦
主播邀请用户上麦
主播踢用户下麦
lockSeat
主播锁定麦位(包括位置锁定、音频状态锁定和视频状态锁定)
主播设置麦位列表的布局模式
为麦位视图设置代理
设置事件回调
移除事件回调

API 详情

SeatGridView

创建一个 SeatGridView 对象实例。
SeatGridView()

startMicrophone

打开本地麦克风。
func startMicrophone(onSuccess: @escaping SGOnSuccess,
onError: @escaping SGOnError)
参数:
参数
类型
含义
onSuccess
SGOnSuccess
成功回调
onError
SGOnError
失败回调

stopMicrophone

关闭本地麦克风。
func stopMicrophone()

muteMicrophone

暂停发布本地的音频流。
func muteMicrophone()

unmuteMicrophone

恢复发布本地的音频流。
func unmuteMicrophone(onSuccess: @escaping SGOnSuccess,
onError: @escaping SGOnError)
参数:
参数
类型
含义
onSuccess
SGOnSuccess
成功回调
onError
SGOnError
失败回调

startVoiceRoom

主播创建直播间并开始推流。
func startVoiceRoom(roomInfo: TUIRoomInfo,
onSuccess: @escaping SGOnRoomSuccess,
onError: @escaping SGOnError)
参数:
参数
类型
含义
roomInfo
TUIRoomInfo
创建直播间的信息
onSuccess
SGOnRoomSuccess
成功回调(含有新的直播间信息)
onError
SGOnError
失败回调

stopVoiceRoom

主播停止推流并销毁直播间。
func stopVoiceRoom(onSuccess: @escaping SGOnSuccess,
onError: @escaping SGOnError)
参数:
参数
类型
含义
onSuccess
SGOnSuccess
成功回调
onError
SGOnError
失败回调

joinVoiceRoom

观众加入某个主播的直播间。
func joinVoiceRoom(roomId: String,
onSuccess: @escaping SGOnRoomSuccess,
onError: @escaping SGOnError)
参数:
参数
类型
含义
roomId
String
直播间 ID
onSuccess
SGOnRoomSuccess
成功回调(含有直播间信息)
onError
SGOnError
失败回调

leaveVoiceRoom

观众离开某个主播的直播间。
func leaveVoiceRoom(onSuccess: @escaping SGOnSuccess,
onError: @escaping SGOnError)
参数:
参数
类型
含义
onSuccess
SGOnSuccess
成功回调
onError
SGOnError
失败回调

updateRoomSeatMode

更新房间麦位模式。
func updateRoomSeatMode(seatMode: TUISeatMode,
onSuccess: @escaping SGOnSuccess,
onError: @escaping SGOnError)
参数:
参数
类型
含义
seatMode
TUISeatMode
freeToTake:自由上麦模式,观众可以自由上麦,无需申请;
applyToTake:申请上麦模式,观众上麦需要主播同意后才能上麦。
onSuccess
SGOnSuccess
成功回调
onError
SGOnError
失败回调

responseRemoteRequest

主播响应上麦申请/观众响应上麦邀请。
func responseRemoteRequest(userId: String,
agree: Bool,
onSuccess: @escaping SGOnSuccess,
onError: @escaping SGOnError)
参数:
参数
类型
含义
userId
String
响应用户的用户 ID,如果当前身份是观众,ID 可填空
agree
Bool
是否接受请求,true:同意请求,false:拒绝请求
onSuccess
SGOnSuccess
成功回调
onError
SGOnError
失败回调

cancelRequest

主播取消上麦邀请/观众取消上麦申请
func cancelRequest(userId: String,
onSuccess: @escaping SGOnSuccess,
onError: @escaping SGOnError)
参数:
参数
类型
含义
userId
String
取消的用户 ID,如果当前身份是观众,ID 可填空
onSuccess
SGOnSuccess
成功回调
onError
SGOnError
失败回调

takeSeat

上麦(上麦发言模式下,需要申请)
func takeSeat(index: Int,
timeout: Int,
onAccepted: @escaping SGOnRequestAccepted,
onRejected: @escaping SGOnRequestRejected,
onCancelled: @escaping SGOnRequestCancelled,
onTimeout: @escaping SGOnRequestTimeout,
onError: @escaping SGOnRequestError)
参数:
参数
类型
含义
index
Int
上麦的麦位编号
timeout
Int
超时时间,单位秒,如果设置为 0,SDK 不会做超时检测,也不会触发超时回调
onAccepted
SGOnRequestAccepted
上麦申请被同意回调
onRejected
SGOnRequestRejected
上麦申请被拒绝回调
onCancelled
SGOnRequestCancelled
上麦申请已取消回调
onTimeout
SGOnRequestTimeout
上麦申请超时回调
onError
SGOnRequestError
上麦申请错误回调

moveToSeat

移麦(已经在麦位上的用户才可以调用此函数)
func moveToSeat(index: Int,
onSuccess: @escaping SGOnSuccess,
onError: @escaping SGOnError)
参数:
参数
类型
含义
index
Int
需要移动过去的麦位编号
onSuccess
SGOnSuccess
成功回调
onError
SGOnError
失败回调

leaveSeat

主动下麦
func leaveSeat(onSuccess: @escaping SGOnSuccess, onError: @escaping SGOnError)
参数:
参数
类型
含义
onSuccess
SGOnSuccess
成功回调
onError
SGOnError
失败回调

takeUserOnSeatByAdmin

主播邀请用户上麦
func takeUserOnSeatByAdmin(index: Int,
userId: String,
onAccepted: @escaping SGOnRequestAccepted,
onRejected: @escaping SGOnRequestRejected,
onCancelled: @escaping SGOnRequestCancelled,
onTimeout: @escaping SGOnRequestTimeout,
onError: @escaping SGOnRequestError)
参数:
参数
类型
含义
index
Int
被邀请的麦位编号
userId
String
被邀请的用户 ID
timeout
Int
超时时间,单位秒,如果设置为 0,SDK 不会做超时检测,也不会触发超时回调
onAccepted
SGOnRequestAccepted
邀请上麦请求被同意回调
onRejected
SGOnRequestRejected
邀请上麦请求被拒绝回调
onCancelled
SGOnRequestCancelled
邀请上麦请求被取消回调
onTimeout
SGOnRequestTimeout
邀请上麦请求已超时回调
onError
SGOnRequestError
邀请上麦请求错误回调

kickUserOffSeatByAdmin

主播踢用户下麦
func kickUserOffSeatByAdmin(userId: String,
onSuccess: @escaping SGOnSuccess,
onError: @escaping SGOnError)
参数:
参数
类型
含义
userId
String
被踢下麦的用户 ID
onSuccess
SGOnSuccess
成功回调
onError
SGOnError
失败回调

lockSeat

锁麦,主播锁定麦位(包括位置锁定、音频状态锁定和视频状态锁定)
func lockSeat(index: Int,
lockMode: TUISeatLockParams,
onSuccess: @escaping SGOnSuccess,
onError: @escaping SGOnError)
参数:
参数
类型
含义
seatIndex
int
需要锁定麦位的麦位编号
params
TUISeatLockParams
锁麦参数。详情参见:TUIRoomDefine.SeatLockParams
onSuccess
SGOnSuccess
成功回调
onError
SGOnError
失败回调

setLayoutMode

设置麦位列表的布局模式。
func setLayoutMode(layoutMode: SGLayoutMode,
layoutConfig: SeatViewLayoutConfig? = nil
参数:
参数
类型
含义
layoutModel
麦位列表的布局模式,支持元素布局、宫格布局、纵向布局、自由布局。
layoutConfig
布局配置信息,只有自由布局模式下才生效

setSeatViewDelegate

为麦位视图设置适配器。
func setSeatViewDelegate(_ delegate: SGSeatViewDelegate)
参数:
参数
类型
含义
delegate
麦位视图代理

addObserver

设置事件回调。
func addObserver(observer: SeatGridViewObserver)
参数:
参数
类型
含义
observer
核心组件的回调对象

removeObserver

移除事件回调。
func removeObserver(observer: SeatGridViewObserver)
参数:
参数
类型
含义
observer
核心组件的回调对象