本文介绍在加入连麦成功之后如何退出连麦,以及与退出连麦相关的消息通知。
说明
如果加入了连麦,在离开房间之前应当退出连麦。
退出连麦成功之后,会有消息通知连麦中的全部成员(包括自己)。
房主退出连麦时可以选择结束连麦,也可以通过服务端接口DeleteConference - 删除会议来结束。连麦结束成功会有消息通知房间中的全部成员。
房主只退出连麦,不结束连麦,还可以再次加入连麦,并且与原有的连麦插件相同。
房主退出连麦并且结束连麦,再次加入连麦时,会创建新的连麦插件,与原有的连麦插件不同。
退出连麦API使用示例
iOS端(Objective-C):
// 退出连麦
id<AIRBRoomChannelProtocol> room = [[AIRBRoomEngine sharedInstance] getRoomChannelWithRoomID:@"xxx"]
[room.rtc leaveChannel:NO];
// 退出并结束连麦(只有房主可以结束连麦)
id<AIRBRoomChannelProtocol> room = [[AIRBRoomEngine sharedInstance] getRoomChannelWithRoomID:@"xxx"]
[room.rtc leaveChannel:YES];
// 退出连麦成功,需要通过实现AIRBRTCProtocol的AIRBRTCDelegate中的如下方法和事件来通知,
- (void) onAIRBRTCEvent:(AIRBRTCEvent)event info:(NSDictionary*)info{
switch (event) {
case AIRBRTCEventLeaveSucceeded:
break;
.....
}
}
// 退出连麦失败,需要监听AIRBRTCDelegate中的如下错误事件
- (void) onAIRBRTCErrorWithCode:(AIRBErrorCode)code message:(NSString*)msg{
switch (code) {
case AIRBRTCFailedToReportLeaveChannelStatus:
break;
.....
}
}
// 结束连麦成功,需要通过实现AIRBRTCProtocol的AIRBRTCDelegate中的如下方法和事件来通知,
- (void) onAIRBRTCEvent:(AIRBRTCEvent)event info:(NSDictionary*)info{
switch (event) {
case AIRBRTCEventDestroySucceeded:
break;
.....
}
}
// 结束连麦失败,需要监听AIRBRTCDelegate中的如下错误事件
- (void) onAIRBRTCErrorWithCode:(AIRBErrorCode)code message:(NSString*)msg{
switch (code) {
case AIRBRTCFailedToDestroy:
break;
.....
}
}
Android端(Java):
// 退出连麦
rtcService.leaveRtc(false/*是否需要销毁会议*/);
// 退出并结束连麦(只有房主可以结束连麦)
rtcService.leaveRtc(true/*是否需要销毁会议*/);
// 通过调用RtcService.addEventHandler添加的事件监听器的回调触发来判断操作状态
rtc.addEventHandler(new SampleRtcEventHandler(){...});
// 退出连麦成功
new SampleRtcEventHandler(){
@Override
public void onRtcLeaveUser(ConfUserEvent leaveUserEvent) {
}
}
// 退出连麦失败
暂无
// 结束连麦成功
new SampleRtcEventHandler(){
@Override
public void onRtcEnd(ConfEvent confEndEvent) {
}
}
// 结束连麦失败
暂无
Windows端(c++):
auto room_ptr = alibaba::meta_space::MetaSpace::GetInstance()->GetRoomInstance(room_id);
auto rtc_plugin = std::dynamic_pointer_cast<IRtc>(room_ptr->GetPlugin(PluginRtc));
bool destory_rtc = false;
rtc_plugin->JoinRtc(destory_rtc , []() {
},
[](const DPSError& err) {
});
退出连麦相关消息通知示例
iOS端(Objective-C):
// 有人退出连麦的消息,需要通过实现AIRBRoomChannelProtocol的AIRBRoomChannelDelegate中的如下方法和事件来通知,
- (void) onAIRBRoomChannelEvent:(AIRBRoomChannelEvent) event info:(NSDictionary*)info{
switch (event) {
case AIRBRoomChannelEventMessageReceived:{
AIRBRoomChannelMessageType messageType = [[info valueForKey:@"type"] integerValue];
switch (messageType) {
case AIRBRoomChannelMessageTypePeerLeaveRTC:
break;
.....
}
}
break;
.....
}
}
// 连麦被结束的消息,需要通过实现AIRBRoomChannelProtocol的AIRBRoomChannelDelegate中的如下方法和事件来通知,
- (void) onAIRBRoomChannelEvent:(AIRBRoomChannelEvent) event info:(NSDictionary*)info{
switch (event) {
case AIRBRoomChannelEventMessageReceived:{
AIRBRoomChannelMessageType messageType = [[info valueForKey:@"type"] integerValue];
switch (messageType) {
case AIRBRoomChannelMessageTypeRTCStopped:
break;
.....
}
}
break;
.....
}
}
Android端(Java):
// 通过调用RtcService.addEventHandler添加的事件监听器的回调触发来判断操作状态
rtc.addEventHandler(new SampleRtcEventHandler(){
@Override
public void onRtcLeaveUser(ConfUserEvent leaveUserEvent) {
// 有人退出连麦的消息
}
@Override
public void onRtcEnd(ConfEvent confEndEvent) {
// 连麦被结束的消息
}
});
Windows端(c++):
//继承RtcEventListener,并重写OnRtcLeaveUser方法
virtual void OnRtcLeaveUser(const ConfUserEvent & event) override {
}
反馈
- 本页导读 (1)
文档反馈