Options
All
  • Public
  • Public/Protected
  • All
Menu

Chatroom

聊天室 Web SDK

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

完整的聊天室 SDK 由 ChatroomInterface, ChatroomServiceInterface 组成。

ChatroomInterfaceStatic 对象

类的静态方法见 ChatroomInterfaceStatic

方法 功能描述
ChatroomInterfaceStatic.getInstance 单例模式获取实例
ChatroomInterfaceStatic.setAdapters 设置适配器

Chatroom.getInstance

下面是ChatroomInterfaceStatic.getInstance的初始化参数。这里只例举部分参数,完整初始化参数见 ChatroomInitializeOptions,以及ChatroomOtherOptions

注意,初始化有两个参数,调用方式为: Chatroom.getInstance(param1, param2)。param1 为 ChatroomInitializeOptions, param2 为 ChatroomOtherOptions

// 0.11.0 版开始支持单例模式获取实例, 在此之前通过 new 创建实例
const chatroom = Chatroom.getInstance(
/**
* param1: ChatroomInitializeOptions
*/
{
appkey: 'YOUR_APPKEY',
token: 'YOUR_TOKEN',
account: 'YOUR_ACCOUNT',
isAnonymous: false,
chatroomId: 'YOUR_CHATROOM_ID',
chatroomAddresses: ['YOUR_ADDR']
},
/**
* param2: ChatroomOtherOptions
*/
{
/**
* 存储模块初始化设置
*/
cloudStorageConfig: {
/**
* NOS上传地址(分片)
*/
chunkUploadHost: 'https://www.example.com'
}
}
)

ChatroomInitializeOptions

提供最为基础的初始化参数。该参数的完整属性列表请参考ChatroomInitializeOptions

属性 功能描述
ChatroomInitializeOptions.appkey 应用 appkey
ChatroomInitializeOptions.account IM 账户
ChatroomInitializeOptions.token IM 账户 token
ChatroomInitializeOptions.authType token 的认证模式
ChatroomInitializeOptions.debugLevel 日志分级
ChatroomInitializeOptions.chatroomAddresses 聊天室地址列表
ChatroomInitializeOptions.chatroomId 聊天室 id

ChatroomOtherOptions

提供一些扩展初始化参数。该参数的完整属性列表请参考ChatroomOtherOptions

属性 功能描述
ChatroomOtherOptions.cloudStorageConfig cloud storage 模块配置

Chatroom 事件

调用chatroom.on(eventName),监听 chatroom 事件,注册事件相关的回调函数。下面是一些回调事件的定义,完整 API 请参见ChatroomEventInterface

事件名称 功能描述
ChatroomEventInterface.logined 初始化成功登陆
ChatroomEventInterface.kicked 被踢下线
ChatroomEventInterface.willReconnect 开始自动重连
ChatroomEventInterface.disconnect 连接断开
ChatroomEventInterface.chatroomMsg 收到消息
ChatroomEventInterface.tagsUpdate 当前用户标签变更

ChatroomInterface 对象

chatroom 连接管理相关函数。调用方式为chatroom.connect, chatroom.destroy

方法/属性 功能描述
ChatroomInterface.status 实例状态
ChatroomInterface.connect 建立长连接,并且登录
ChatroomInterface.disconnect 断开连接。
ChatroomInterface.destroy 销毁实例

ChatroomServiceInterface

挂载了聊天室相关的 API,如获取本聊天室的信息,更新聊天室信息。调用示例chatroom.chatroom.updateInfo。完整的 API 请参见 ChatroomServiceInterface

方法 功能描述
ChatroomServiceInterface.getInfo 获取本聊天室的信息
ChatroomServiceInterface.updateInfo 更新自己在聊天室中的信息

ChatroomMsgServiceInterface

挂载了聊天室消息相关的 API,如发送消息,查询历史消息。调用示例chatroom.chatroomMsg.sendTextMsg。完整的 API 请参见 ChatroomMsgServiceInterface

方法 功能描述
ChatroomMsgServiceInterface.sendTextMsg 发送文本消息
ChatroomMsgServiceInterface.queryMessageHistory 获取聊天室历史消息

ChatroomMemberServiceInterface

挂载了聊天室成员相关的 API,如设置管理员,设置禁言,更新自己在聊天室中的信息等。调用示例chatroom.chatroomMember.queryMembers。完整的 API 请参见 ChatroomMemberServiceInterface

方法 功能描述
ChatroomMemberServiceInterface.queryMembers 获取聊天室成员列表
ChatroomMemberServiceInterface.queryMembersByAccounts 获取聊天室成员
ChatroomMemberServiceInterface.kickMember 踢聊天室成员
ChatroomMemberServiceInterface.updateMyRoomRole 更新自己在聊天室中的信息

CloudStorageServiceInterface

挂载了文件上传逻辑。调用示例chatroom.cloudStorage.uploadFile。完整的 API 请参见 CloudStorageServiceInterface

方法 功能描述
CloudStorageServiceInterface.uploadFile 上传文件
CloudStorageServiceInterface.getOriginUrl 短链转长链
CloudStorageServiceInterface.getFileToken 获取文件鉴权的 token