文档

处理邀请

更新时间:

本文介绍收到邀请连麦消息之后,如何接受或拒绝连麦邀请以及对应的消息通知。

说明

  • 收到邀请连麦消息,并且其中的被邀请用户ID与自己的相同,可以选择接受或拒绝,如果接受则直接加入连麦,如果拒绝则发出拒绝连麦邀请的消息。

  • 拒绝连麦邀请之后,房间的成员会收到拒绝连麦邀请的消息,具体请看连麦邀请被拒绝消息通知示例

邀请连麦消息通知示例

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 AIRBRoomChannelMessageTypeOnRTCCalled:{
                    NSData *turnData = [[info valueForKey:@"data"] dataUsingEncoding:NSUTF8StringEncoding];
                    NSDictionary *dataDic = [NSJSONSerialization JSONObjectWithData:turnData options:NSJSONReadingMutableLeaves error:nil];
                    NSString *userIDCalled = [[[data valueForKey:@"calleeList"] objectAtIndex:0] valueForKey:@"userId"];
                    // 自定义处理
                }
                break;
                .....
            }
        }
        break;
        .....
    }
}

Android端(Java):

// 通过调用RtcService.addEventHandler添加的事件监听器的回调触发来判断操作状态
rtc.addEventHandler(new SampleRtcEventHandler(){
    @Override
    public void onRtcUserInvited(ConfInviteEvent event) {
        // 邀请连麦的消息
    }
});

Windows端(c++):

// 邀请连麦的消息
// 继承RtcEventListener,并重写OnRtcUserInvited方法
virtual void OnRtcUserInvited(const ConfInviteEvent& event) override {
 
} 

接受连麦邀请

可以直接加入连麦

拒绝连麦邀请API使用示例

iOS端(Objective-C):

// 拒绝连麦邀请
id<AIRBRoomChannelProtocol> room = [[AIRBRoomEngine sharedInstance] getRoomChannelWithRoomID:@"xxx"]
[room.rtc acceptCall:NO];

// 拒绝连麦邀请失败,需要监听AIRBRTCDelegate中的如下错误事件
- (void) onAIRBRTCErrorWithCode:(AIRBErrorCode)code message:(NSString*)msg{
    switch (code) {
        case AIRBRTCFailedToReportJoinChannelStatus:
        break;
        .....
    }
}

Android端(Java):

// 拒绝连麦邀请
// 通过调用RtcService.addEventHandler添加的事件监听器的回调触发来判断操作状态
rtc.addEventHandler(new SampleRtcEventHandler(){
    @Override
    public void onRtcUserInvited(ConfInviteEvent event) {
        for (ConfUserModel userModel : event.calleeList) {
            if (isSelf(userModel.userId)) {
                rtcService.reportJoinStatus(RtcUserStatus.JOIN_FAILED, null);
            }
        }
    }
});

Windows端(c++):

// 拒绝连麦邀请
virtual void OnRtcUserInvited(const ConfInviteEvent& event) override {
  bool about_self = false;
  for (auto user : event.callee_list) {
    if (user.user_id == self_user_id) {
      about_self = true;
      break;
    }
  }
  if(!about_self) return;
  auto room_ptr = alibaba::meta_space::MetaSpace::GetInstance()->GetRoomInstance(room_id);
  std::shared_ptr<IRtc> rtc_plugin = std::dynamic_pointer_cast<IRtc>(room_ptr->GetPlugin(PluginRtc));
  rtc_plugin->ApproveLinkMic(self_user_id, false, []() {},[](const DPSError& err) {});
}