文档

房间踢人

更新时间:

本文介绍如何在房间内踢出某成员。

说明

  • 只有当前房间的房主或者管理员才能踢人。

  • 某成员被踢出房间后,其他成员都会收到消息通知。

房间踢人API使用示例

iOS端(Objective-C):

//房主或者管理从房间内把某成员踢出
[id<AIRBRoomChannelProtocol>room kickRoomUserWithUserID:userID onSuccess:^{
   NSLog@(@"踢人成功");
} onFailure:^(NSString * _Nonnull errorMessage) {
   NSLog@(@"踢人失败,错误信息是%@", errorMessage);
}];

Android端(Java):

roomChannel.kickUser(userId, new Callback<Void>() {
    @Override
    public void onSuccess(Void data) {
        // 成功回调
    }
    @Override
    public void onError(String errorMsg) {
        // 失败回调
    }
});

Web端(JavaScript):

//房主或者管理从房间内把某成员踢出
roomChannel.kickUser(userId).then(() => {
  // 踢人成功
})

Windows端(c++):

std::string uid;
auto room_ptr = alibaba::meta_space::MetaSpace::GetInstance()->GetRoomInstance(room_id);
room_ptr->KickRoomUser(uid, [](){}, [](const ::alibaba::dps::DPSError & error){});

接收房间内踢人消息通知的API使用示例

iOS端(Objective-C):

//房间内其他人通过AIRBRoomChannelDelegate中的房间消息事件AIRBRoomChannelEventMessageReceived
//中具体的AIRBRoomChannelMessageTypeRoomOneUserKickedOut消息来收到某成员被踢出的通知
- (void) onAIRBRoomChannelEvent:(AIRBRoomChannelEvent) event info:(NSDictionary*)info {
    switch (event) {
    case AIRBRoomChannelEventMessageReceived: {
        AIRBRoomChannelMessageType type = [[info valueForKey:@"type"] intValue];
        switch (type) {
                case AIRBRoomChannelMessageTypeRoomOneUserKickedOut:{
                    NSString* newTitle = [info valueForKey:@"data"];
                ... ...
    }
}

Android端(Java):

roomChannel.addEventHandler(new SampleRoomEventHandler() {
    @Override
    public void onRoomUserKicked(KickUserEvent event) {
        Logger.i(TAG, String.format("%s被移除了房间", event.kickUserName));
    }
});

Web端(JavaScript):

// 获取事件列表
const { EventNameEnum } = window.RoomPaasSdk
// 监听更新房间公告事件
roomChannel.on(EventNameEnum.PaaSRoomKickUser, (event) => {
  console.log(event.data.kickUser)
})

Windows端(c++):

继承RoomEventListener,并重写OnRoomUserKicked函数
virtual void OnRoomUserKicked(const KickUserEventModel & event) override {
}