You need to enable JavaScript to run this app.
导航

回调

最近更新时间2023.11.03 16:17:51

首次发布时间2022.09.14 20:26:33

RTSDelegate
@protocol RTSDelegate <NSObject>

RTSDelegate 协议包含了SDK提供的回调方法,SDK通过代理向应用程序上报一些运行时事件

成员函数

返回名称
voidrtsEngine:onConnectionStateChanged:
voidrtsEngine:onNetworkTypeChanged:
voidrtsEngine:onCreateRoomStateChanged:errorCode:
voidrtsEngine:onLocalProxyStateChanged:withProxyState:withProxyError:
voidrtsEngine:onSysStats:
voidrtsEngine:onLoginResult:errorCode:elapsed:
voidrtsEngineOnLogout:
voidrtsEngine:onServerParamsSetResult:
voidrtsEngine:onGetPeerOnlineStatus:status:
voidrtsEngine:onMessageReceived:message:
voidrtsEngine:onBinaryMessageReceived:message:
voidrtsEngine:onMessageSendResult:error:
voidrtsEngine:onServerMessageSendResult:error:message:

函数说明

rtsEngine:onConnectionStateChanged:

- (void)rtsEngine:(RTS * _Nonnull)engine onConnectionStateChanged:(ByteRTCConnectionState)state;

SDK 与信令服务器连接状态改变回调。连接状态改变时触发。

传入参数

参数名类型说明
engineRTS*RTS 对象。
stateByteRTCConnectionState当前 SDK 与信令服务器连接状态。详细定义参见 ByteRTCConnectionState

注意
更多信息参见 连接状态提示

rtsEngine:onNetworkTypeChanged:

- (void)rtsEngine:(RTS * _Nonnull)engine onNetworkTypeChanged:(ByteRTCNetworkType)type;

SDK 当前网络连接类型改变回调。当 SDK 的当前网络连接类型发生改变时回调该事件。

传入参数

参数名类型说明
engineRTS*RTS 对象。
typeByteRTCNetworkTypeSDK 当前的网络连接类型。参看 ByteRTCNetworkType

rtsEngine:onCreateRoomStateChanged:errorCode:

- (void)rtsEngine:(RTS *_Nonnull)engine onCreateRoomStateChanged:(NSString * _Nonnull)roomId errorCode:(NSInteger)errorCode;

创建房间失败回调。

传入参数

参数名类型说明
engineRTS*RTS 对象。
roomIdNSString*房间 ID。
errorCodeNSInteger创建房间错误码:
• -1007:无效 roomId;
• -1013:相同 roomId 的房间已存在。

rtsEngine:onLocalProxyStateChanged:withProxyState:withProxyError:

- (void)rtsEngine:(RTS * _Nonnull)engine onLocalProxyStateChanged:(ByteRTCLocalProxyType)type withProxyState:(ByteRTCLocalProxyState)state withProxyError:(ByteRTCLocalProxyError)error;

本地代理状态发生改变回调。调用 setLocalProxy: 设置本地代理后,SDK 会触发此回调,返回代理连接的状态。

传入参数

参数名类型说明
typeByteRTCLocalProxyType本地代理类型。参看 ByteRTCLocalProxyType
stateByteRTCLocalProxyState本地代理状态。参看 ByteRTCLocalProxyState
errorByteRTCLocalProxyError本地代理错误。参看 ByteRTCLocalProxyError

rtsEngine:onSysStats:

- (void)rtsEngine:(RTS * _Nonnull)engine onSysStats:(const ByteRTCSysStats * _Nonnull)stats;

周期性(2s)地发出回调,报告当前 cpu 与内存的使用率

传入参数

参数名类型说明
engineRTS*RTS 对象
statsconst ByteRTCSysStats*返回包含当前系统状态信息的结构体,详见 ByteRTCSysStats

rtsEngine:onLoginResult:errorCode:elapsed:

- (void)rtsEngine:(RTS * _Nonnull)engine onLoginResult:(NSString * _Nonnull)uid errorCode:(ByteRTCLoginErrorCode)errorCode elapsed:(NSInteger)elapsed;

登录 RTS 服务器结果回调。

传入参数

参数名类型说明
engineRTS*RTS 对象
uidNSString*登录用户 ID
errorCodeByteRTCLoginErrorCode登录结果,详见 ByteRTCLoginErrorCode
elapsedNSInteger从调用 login:uid: 接口开始到返回结果所用时长,单位为 ms。

注意
调用 login:uid: 后,会收到此回调。

rtsEngineOnLogout:

- (void)rtsEngineOnLogout:(RTS * _Nonnull)engine;

登出结果回调

传入参数

参数名类型说明
engineRTS*RTS 对象

注意
调用 logout 后,会收到此回调。

rtsEngine:onServerParamsSetResult:

- (void)rtsEngine:(RTS * _Nonnull)engine onServerParamsSetResult:(NSInteger)errorCode;

设置应用服务器参数的返回结果

传入参数

参数名类型说明
engineRTS*RTS 对象
errorCodeNSInteger设置结果:
• 返回 200,设置成功
• 返回其他,设置失败

注意
调用 setServerParams:url: 后,会收到此回调。

rtsEngine:onGetPeerOnlineStatus:status:

- (void)rtsEngine:(RTS * _Nonnull)engine onGetPeerOnlineStatus:(NSString * _Nonnull)peerUserId status:(ByteRTCUserOnlineStatus)status;

查询对端或本端用户登录状态的返回结果

传入参数

参数名类型说明
engineRTS*RTS 对象
peerUserIdNSString*需要查询的用户 ID
statusByteRTCUserOnlineStatus查询的用户登录状态,详见 ByteRTCUserOnlineStatus.

注意
必须先调用 getPeerOnlineStatus:,才能收到此回调。

rtsEngine:onMessageReceived:message:

- (void)rtsEngine:(RTS * _Nonnull)engine onMessageReceived:(NSString * _Nonnull)uid message:(NSString * _Nonnull)message;

收到远端用户调用 sendMessage:message:config: 发来的文本消息时,会收到此回调。

传入参数

参数名类型说明
engineRTS*RTS 对象
uidNSString*消息发送者 ID
messageNSString*收到的文本消息内容

rtsEngine:onBinaryMessageReceived:message:

- (void)rtsEngine:(RTS * _Nonnull)engine onBinaryMessageReceived:(NSString * _Nonnull)uid message:(NSData * _Nonnull)message;

收到房间外用户调用 sendBinaryMessage:message:config: 发来的二进制消息时,会收到此回调。

传入参数

参数名类型说明
engineRTS*RTS 对象
uidNSString*消息发送者 ID
messageNSData*收到的二进制消息内容

rtsEngine:onMessageSendResult:error:

- (void)rtsEngine:(RTS * _Nonnull)engine onMessageSendResult:(int64_t)msgid error:(ByteRTCUserMessageSendResult)error;

发送 p2p 消息的结果回调。

传入参数

参数名类型说明
engineRTS*RTS 对象
msgidint64_t本条消息的 ID。所有的 P2P 和 P2Server 消息共用一个 ID 序列。
errorByteRTCUserMessageSendResult消息发送结果,详见 ByteRTCUserMessageSendResult

注意
当调用 sendMessage:message:config:sendBinaryMessage:message:config: 发送消息后,会收到此回调。

rtsEngine:onServerMessageSendResult:error:message:

- (void)rtsEngine:(RTS * _Nonnull)engine onServerMessageSendResult:(int64_t)msgid error:(ByteRTCUserMessageSendResult)error message:(NSData * _Nonnull)message;

发送 p2server 消息的结果回调。

传入参数

参数名类型说明
engineRTS*RTS 对象
msgidint64_t本条消息的 ID。所有的 P2P 和 P2Server 消息共用一个 ID 序列。
errorByteRTCUserMessageSendResult消息发送结果。详见 ByteRTCUserMessageSendResult

注意
当调用 sendServerMessage:sendServerBinaryMessage: 接口发送消息后,会收到此回调。

RTSRoomDelegate
@protocol RTSRoomDelegate <NSObject>

语音房间事件回调接口

成员函数

返回名称
voidrtsRoom:onRoomStateChanged:withUid:state:extraInfo:
voidrtsRoomOnLeaveRoom:
voidrtsRoom:onUserJoined:elapsed:
voidrtsRoom:onUserLeave:reason:
voidrtsRoom:onRoomMessageReceived:message:
voidrtsRoom:onRoomBinaryMessageReceived:message:
voidrtsRoom:onRoomMessageSendResult:error:

函数说明

rtsRoom:onRoomStateChanged:withUid:state:extraInfo:

- (void)rtsRoom:(RTSRoom * _Nonnull)rtcRoom onRoomStateChanged:(NSString * _Nonnull)roomId withUid:(nonnull NSString *)uid state:(NSInteger)state extraInfo:(nonnull NSString *)extraInfo;

房间状态改变回调,加入房间、异常退出房间、发生房间相关的警告或错误时会收到此回调。

传入参数

参数名类型说明
roomIdNSString*房间 ID。
uidNSString*用户 ID。
stateNSInteger房间状态码。
• 0: 加入房间成功。
• !0: 加入房间失败、异常退房、发生房间相关的警告或错误。
extraInfoNSString*额外信息,如 {"elapsed":1187,"join_type":0}
join_type表示加入房间的类型,0为首次进房,1为重连进房。
elapsed表示加入房间耗时,即本地用户从调用 joinRoom 到加入房间成功所经历的时间间隔,单位为 ms。

rtsRoomOnLeaveRoom:

- (void)rtsRoomOnLeaveRoom:(RTSRoom *_Nonnull)rtsRoom;

离开房间成功回调。

用户调用 leaveRoom 方法后,SDK 会停止房间内消息的收发,并在释放所有相关资源后,通过此回调通知用户离开房间成功。

传入参数

参数名类型说明
rtsRoomRTSRoom*rtsRoom 对象。

注意
用户调用 leaveRoom 方法离开房间后,如果立即销毁 RTC 引擎,则将无法收到此回调事件。

rtsRoom:onUserJoined:elapsed:

- (void)rtsRoom:(RTSRoom * _Nonnull)rtcRoom onUserJoined:(NSString * _Nonnull)uid elapsed:(NSInteger)elapsed;

远端用户首次进房,或断网后重新连入房间时,房间内其他用户将收到该事件。

传入参数

参数名类型说明
rtcRoomRTSRoom*RTSRoom 对象。
uidNSString*加入房间的用户 ID。
elapsedNSInteger保留字段,无意义

rtsRoom:onUserLeave:reason:

- (void)rtsRoom:(RTSRoom * _Nonnull)rtcRoom onUserLeave:(NSString * _Nonnull)uid reason:(ByteRTCUserOfflineReason)reason;

远端用户离开房间时,本地用户会收到此事件

传入参数

参数名类型说明
rtcRoomRTSRoom*RTSRoom 对象。
uidNSString*离开房间的远端用户 ID 。
reasonByteRTCUserOfflineReason用户离开房间的原因,参看 ByteRTCUserOfflineReason

rtsRoom:onRoomMessageReceived:message:

- (void)rtsRoom:(RTSRoom * _Nonnull)rtcRoom onRoomMessageReceived:(NSString * _Nonnull)uid message:(NSString * _Nonnull)message;

收到房间中调用 sendRoomMessage: 发送的广播文本消息时,收到此回调。

传入参数

参数名类型说明
rtcRoomRTSRoom*RTSRoom 对象
uidNSString*消息发送者 ID 。
messageNSString*收到的文本消息内容。

rtsRoom:onRoomBinaryMessageReceived:message:

- (void)rtsRoom:(RTSRoom * _Nonnull)rtcRoom onRoomBinaryMessageReceived:(NSString * _Nonnull)uid message:(NSData * _Nonnull)message;

收到房间中调用 sendRoomBinaryMessage: 发送的广播二进制消息时,收到此回调。

传入参数

参数名类型说明
rtcRoomRTSRoom*RTSRoom 对象
uidNSString*消息发送者 ID 。
messageNSData*收到的二进制消息内容。

rtsRoom:onRoomMessageSendResult:error:

- (void)rtsRoom:(RTSRoom * _Nonnull)rtcRoom onRoomMessageSendResult:(int64_t)msgid error:(ByteRTCRoomMessageSendResult)error;

向房间内所有用户群发文本或二进制消息后,消息发送方会收到该消息发送结果回调。

传入参数

参数名类型说明
rtcRoomRTSRoom*RTSRoom 对象。
msgidint64_t本条消息的 ID。
errorByteRTCRoomMessageSendResult消息发送结果,详见 ByteRTCRoomMessageSendResult

注意