Web API 参考(Chatroom)

更新时间: 2024/04/01 16:04:55

云信聊天室基于云信实时通信网络,提供完整的聊天室服务。

Chatroom.getInstance

下面是 Chatroom.getInstance 的初始化参数。这里只例举部分回调函数,完整初始化参数见 chatroom/types.NIMChatroomGetInstanceOptions

参数 功能描述
appKey [必填]应用的 appKey
account [必填]帐号 ID
token [必填]帐号的登录凭证
chatroomId [必填]聊天室房间号
chatroomAddresses [必填]聊天室长连接地址
isAnonymous 是否匿名登录
tags 当前连接标签组
onconnect 钩子函数-连接建立后的回调
onwillreconnect 钩子函数-即将重连的回调
ondisconnect 钩子函数-断开链接的回调
onmsgs 钩子函数-(多端同步/在线)收到消息的回调
onTagsUpdate 钩子函数-当前用户标签被更新的回调

NIMChatroomInterface

Chatroom SDK 的入口,负责建立长连接,登录,断开长连接,销毁实例等功能,完整的 API 请参见 NIMChatroomInterface

方法 功能描述 对应 V10 API
logout 退出登录 V2NIMChatroomClient.exit
disconnect 断开连接 V2NIMChatroomClient.exit
connect 连接 V2NIMChatroomClient.enter
destroy 销毁实例 V2NIMChatroomClient.destroyInstance
updateTags 更新当前长连接的标签 V2NIMChatroomService.updateChatroomTags
getChatroom 获取当前聊天室的属性 V2NIMChatroomClient.getChatroomInfo
closeChatroom 关闭聊天室
updateChatroom 更新聊天室属性 V2NIMChatroomService.updateChatroomInfo

NIMChatroomMemberInterface

聊天室成员相关的 API,如设置管理员,设置禁言,更新自己在聊天室中的信息等,完整的 API 请参见 NIMChatroomMemberInterface

方法 功能描述 对应 V10 API
updateMyChatroomMemberInfo 更新自己在聊天室内的信息 V2NIMChatroomService.updateSelfMemberInfo
getChatroomMembers 获取聊天室成员列表 V2NIMChatroomService.getMemberByIds
getChatroomMembersByTag 获取带有某标签的聊天室成员列表 V2NIMChatroomService.getMemberListByTag
getChatroomMemberCountByTag 获取带有某标签的聊天室成员列表 V2NIMChatroomService.getMemberCountByTag
markChatroomIdentity 设置聊天室成员身份 V2NIMChatroomService.updateMemberRole
markChatroomManager 设置聊天室管理员 V2NIMChatroomService.updateMemberRole
markChatroomCommonMember 设置聊天室普通成员 V2NIMChatroomService.updateMemberRole
markChatroomBlacklist 设置聊天室黑名单 V2NIMChatroomService.setMemberBlockedStatus
markChatroomGaglist 设置聊天室禁言名单 V2NIMChatroomService.setMemberChatBannedStatus
kickChatroomMember 踢聊天室成员 V2NIMChatroomService.kickMember
updateChatroomMemberTempMute 设置聊天室临时禁言 V2NIMChatroomService.setMemberChatBannedStatus
updateTagMembersTempMute 根据标签设置聊天室临时禁言 V2NIMChatroomService.setTempChatBannedByTag
updateCoordinate 更新坐标 V2NIMChatroomService.updateChatroomLocationInfo

ChatroomMessageInterface

聊天室消息相关的 API,如发送消息,查询历史消息,完整的 API 请参见 NIMChatroomMessageInterface

方法 功能描述 对应 V10 API
sendText 发送文本消息
  • V2NIMChatroomMessageCreator.createTextMessage
  • V2NIMChatroomService.sendMessage
  • sendFile 发送文件消息
  • V2NIMChatroomMessageCreator.createFileMessage
  • V2NIMChatroomService.sendMessage
  • sendCustomMsg 发送自定义消息
  • V2NIMChatroomMessageCreator.createCustomMessage
  • V2NIMChatroomService.sendMessage
  • sendTipMsg 发送 tip 消息
  • V2NIMChatroomMessageCreator.createTipsMessage
  • V2NIMChatroomService.sendMessage
  • sendGeo 发送地理位置消息
  • V2NIMChatroomMessageCreator.createLocationMessage
  • V2NIMChatroomService.sendMessage
  • getHistoryMsgs 获取聊天室历史消息 V2NIMChatroomService.getMessageList
    getHistoryMsgsByTags 根据标签获取聊天室历史消息 V2NIMChatroomService.getMessageListByTag
    resendMsg 重发消息

    NIMChatroomQueueInterface

    • 聊天室队列指聊天室(房间)中由多个元素(key-value 键值对)构成的队列,应用于直播间中的连麦场景和礼物队列展示等场景。
    • 下面是聊天室队列相关的 API,如更新队列、获取聊天室队列列表,完整的 API 请参见 [`NIMChatroomQueueInterface`](https://doc.yunxin.163.com/messaging/api-refer/web/typedoc/Latest/zh/Chatroom/interfaces/chatroom_NIMChatroomQueueInterface.NIMChatroomQueueInterface.html)。
    方法 功能描述 对应 V10 API
    queueOffer 新加(更新)队列元素
    queuePoll 删除队列元素
    queueList 获取聊天室队列列表
    peak 获取聊天室队列中第一个元素
    queueDrop 清除聊天室队列
    queueChange 批量更新聊天室队列

    CloudStorageInterface

    云端会话服务相关的 API,如查询云端会话列表,查询某个云端会话,完整的 API 请参见 CloudStorageInterface

    方法 功能描述 对应 V10 API
    previewFile 上传并且预览文件 V2NIMStorageService.uploadFile
    getNosOriginUrl 短链接转长链接 V2NIMChatroomService.shortUrlToLong
    audioToText 音频转文字
    stripImageMeta 去除图片元信息
    qualityImage 修改图片质量
    interlaceImage interlace 图片
    rotateImage 旋转图片
    blurImage 模糊图片
    cropImage 剪裁图片
    thumbnailImage 生成图片的略缩图
    processImage 处理图片
    此文档是否对你有帮助?
    有帮助
    去反馈
    • Chatroom.getInstance
    • NIMChatroomInterface
    • NIMChatroomMemberInterface
    • ChatroomMessageInterface
    • NIMChatroomQueueInterface
    • CloudStorageInterface