Options
All
  • Public
  • Public/Protected
  • All
Menu

chatroom

聊天室 Web SDK

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

完整的聊天室 SDK 由 V2NIMChatroomClient 组成。

V2NIMChatroomClient

聊天室 SDK 的入口类。包含实例管理的静态方法,以及进出聊天室的实例方法等。详情请参见 V2NIMChatroomClient

方法 功能描述
V2NIMChatroomClient.newInstance (staic)创建聊天室实例
V2NIMChatroomClient.destroyInstance (staic)销毁聊天室实例
V2NIMChatroomClient.getInstance (staic)根据 instanceId 获取聊天室实例
V2NIMChatroomClient.getInstanceList (staic)获取实例列表
V2NIMChatroomClient.destroyAll (staic)销毁所有实例
V2NIMChatroomClient.enter 进入聊天室
V2NIMChatroomClient.exit 退出聊天室
V2NIMChatroomClient.getChatroomInfo 获取聊天室基本信息
V2NIMChatroomClient.on 监听聊天室基础事件
V2NIMChatroomClient.off 监听聊天室基础事件

下面是新建聊天室实例,并进入聊天室的基本代码:

const chatroom = V2NIMChatroomClient.newInstance({
appkey: 'YOUR_APPKEY',
debugLevel: 'debug'
})

const res = await chatroom.enter(roomId, {
accountId: 'ACCID',
token: 'TOKEN',
roomNick: 'YOUR_NICK',
roomAvatar: 'YOUR_IMG_URL',
linkProvider: function () {
return 'chatweblink12.netease.im'
}
})

V2NIMChatroomClientListener

聊天室实例上挂载的事件。调用示例: chatroom.on('onChatroomStatus', function(status, error) {})。完整的 API 请参见 V2NIMChatroomClientListener

事件 功能描述
V2NIMChatroomClientListener.onChatroomStatus 聊天室连接、登录状态变化
V2NIMChatroomClientListener.onChatroomEntered 聊天室登录成功
V2NIMChatroomClientListener.onChatroomExited 退出聊天室
V2NIMChatroomClientListener.onChatroomKicked 被踢出聊天室

V2NIMChatroomMessageCreator

挂载了构造消息相关 API。调用示例: chatroom.V2NIMChatroomMessageCreator.createTextMessage。完整的 API 请参见 V2NIMChatroomMessageCreator

方法 功能描述
V2NIMChatroomMessageCreator.createTextMessage 构造文本消息
V2NIMChatroomMessageCreator.createImageMessage 构造图片消息
V2NIMChatroomMessageCreator.createAudioMessage 构造音频消息
V2NIMChatroomMessageCreator.createVideoMessage 构造视频消息
V2NIMChatroomMessageCreator.createFileMessage 构造文件消息
V2NIMChatroomMessageCreator.createLocationMessage 构造位置消息
V2NIMChatroomMessageCreator.createCustomMessage 构造自定义消息
V2NIMChatroomMessageCreator.createForwardMessage 构造提示消息

V2NIMChatroomService

聊天室的主要接口集合。调用示例: chatroom.V2NIMChatroomService.cancelMessageAttachmentUpload。完整的 API 请参见 V2NIMChatroomService

方法 功能描述
V2NIMChatroomService.cancelMessageAttachmentUpload 取消文件类消息的附件上传
V2NIMChatroomService.getMemberByIds 根据账号列表查询成员信息
V2NIMChatroomService.getMemberCountByTag 查询某个标签下的成员人数
V2NIMChatroomService.getMemberListByOption 分页获取聊天室成员列表
V2NIMChatroomService.getMemberListByTag 根据 tag 查询群成员列表
V2NIMChatroomService.getMessageList 查询历史消息
V2NIMChatroomService.getMessageListByTag 根据标签查询消息列表
V2NIMChatroomService.kickMember 踢出聊天室成员
V2NIMChatroomService.sendMessage 发送消息接口
V2NIMChatroomService.setMemberBlockedStatus 设置聊天室成员黑名单状态
V2NIMChatroomService.setMemberChatBannedStatus 设置聊天室成员禁言状态
V2NIMChatroomService.setMemberTempChatBanned 设置成员临时禁言状态
V2NIMChatroomService.setTempChatBannedByTag 按聊天室标签临时禁言
V2NIMChatroomService.updateChatroomInfo 更新聊天室信息
V2NIMChatroomService.updateChatroomLocationInfo 更新聊天室位置信息
V2NIMChatroomService.updateChatroomTags 更新聊天室标签
V2NIMChatroomService.updateMemberRole 更新聊天室成员角色
V2NIMChatroomService.updateSelfMemberInfo 更新自己在聊天室的成员信息

V2NIMChatroomListener

聊天室主要接口上监听的事件类型。调用示例: chatroom.V2NIMChatroomListener.onChatroomChatBannedUpdated。完整的 API 请参见 V2NIMChatroomListener

方法 功能描述
V2NIMChatroomListener.onChatroomChatBannedUpdated 聊天室整体禁言状态更新
V2NIMChatroomListener.onChatroomInfoUpdated 聊天室信息更新
V2NIMChatroomListener.onChatroomMemberEnter 聊天室成员进入
V2NIMChatroomListener.onChatroomMemberExit 聊天室成员离开
V2NIMChatroomListener.onChatroomMemberInfoUpdated 成员信息更新
V2NIMChatroomListener.onChatroomMemberRoleUpdated 成员角色更新
V2NIMChatroomListener.onChatroomTagsUpdated 更新角色标签
V2NIMChatroomListener.onMessageRevokedNotification 消息撤回回调
V2NIMChatroomListener.onReceiveMessages 收到新消息
V2NIMChatroomListener.onSelfChatBannedUpdated 自己禁言状态变更
V2NIMChatroomListener.onSelfTempChatBannedUpdated 自己的临时禁言状态变更
V2NIMChatroomListener.onSendMessage 本端发送消息状态回调

V2NIMStorageService

挂载了聊天室云端存储接口。调用示例: chatroom.V2NIMStorageService.uploadFile。完整的 API 请参见 V2NIMStorageService

方法 功能描述
V2NIMStorageService.addCustomStorageScene 添加自定义存储场景
V2NIMStorageService.createUploadFileTask 创建文件上传任务
V2NIMStorageService.uploadFile 文件上传
V2NIMStorageService.cancelUploadFile 取消文件上传
V2NIMStorageService.getStorageSceneList 查询存储场景列表
V2NIMStorageService.shortUrlToLong 短链转长链