文档

点赞

更新时间:

本文介绍如何发送点赞和接收点赞消息。

说明

  • 点赞操作会在内部进行合流操作,用于支持用户连续点赞。合流操作会发送一定时间段内的所有点赞数给服务端。

API使用示例

iOS:

id<AIRBRoomChannelProtocol> room = [[AIRBRoomEngine sharedInstance] getRoomChannelWithRoomID:@"xxx"]
[room.chat sendLike];

Android:

// 内部会做调用优化
chatService.sendLike();

Web:

chatService.sendLike()

Windows:

auto room_ptr = alibaba::meta_space::MetaSpace::GetInstance()->GetRoomInstance(room_id);
std::shared_ptr<IChat> chat_plugin = std::dynamic_pointer_cast<IChat>(room_ptr->GetPlugin(PluginChat));
chat_plugin->SendLike([]() {
}, [](const alibaba::dps::DPSError& err) {
});

接收点赞消息通知的API使用示例

iOS:

// 需要设置AIRBRoomChannelProtocol的delegate并实现以下方法,监听如下事件,解析JSON内容
- (void) onAIRBRoomChannelEvent:(AIRBRoomChannelEvent) event info:(NSDictionary*)info 
{
   case AIRBRoomChannelEventMessageReceived: {
        AIRBRoomChannelMessageType type = [[info valueForKey:@"type"] intValue];
        switch (type) 
        {
            case AIRBRoomChannelMessageTypeChatLikeReceived: 
           {
                NSData *turnData = [[info valueForKey:@"data"] dataUsingEncoding:NSUTF8StringEncoding];
                NSDictionary *dataDic = [NSJSONSerialization JSONObjectWithData:turnData options:NSJSONReadingMutableLeaves error:nil];
                NSLog(@"收到点赞数:%@", [[dataDic valueForKey:@"likeCount"] intValue]);
           }
           break;
           ... ...
} 

Android:

chatService.addEventHandler(new SampleChatEventHandler() {
    @Override
    public void onLikeReceived(LikeEvent event) {
        // 监听到点赞信息
    }
});

Web:

// 获取事件列表
const { EventNameEnum } = window.RoomPaasSdk
// 监听点赞消息通知
chatService.on(EventNameEnum.PaaSChatReciveLike, (event) => {
  console.log(event.data)
})

Windows:

//继承ChatEventListener,并重写OnLikeCountChange方法
virtual void OnLikeCountChange(const LikeEventModel& event) override {

}
  • 本页导读 (1)
文档反馈