直播聊天室消息类型

xiaoxiao2021-02-28  60

直播聊天室中是使用的自定义消息;具体的类是在CustomAttachment文件夹里面;主要有

CustomTextAttachment  普通文本消息:

CustomGiftAttachment  礼物与优惠券消息;

CustomLikeAttachment  点赞消息(暂时没用到)

CustomSystemAttachment  系统消息(暂时也没用到) 

DefaultCustomAttachment  其它消息(没有用到)

CustomAnchorResumeAttachment  一对一聊天用到的消息类型  

CustomAttachmentType :接口 消息的类型

CustomAttachment 基类,上面的几种自定义消息都是继承它;它实现了MsgAttachment(网易im写的);

CustomAttachParser :这是一个解析类,可以将我们自定义的消息转成json

注意 这些自定义消息要想生效 得在application里面注册消息解析器(注册一次就行)

if(SystemUtil.inMainProcess(getApplicationContext())){ NIMClient.getService(MsgService.class).registerCustomAttachmentParser(new CustomAttachParser());//注册消息解析器 }

使用方法:

接收到的 

IMMessage message CustomTextAttachment attachment = (CustomTextAttachment) message.getAttachment();

强转消息后就可以得到里面的内容

发送的

CustomGiftAttachment giftAttachment = new CustomGiftAttachment(type, count, extStr); ChatRoomMessage message = ChatRoomMessageBuilder.createChatRoomCustomMessage(chatroomid, giftAttachment); 先构造一个attachment 对象 ,再发送;
转载请注明原文地址: https://www.6miu.com/read-71088.html

最新回复(0)