// 本地聊天缓存 const messageList = [] // 聊天通道打开,在此事件之后做聊天的相关操作 client.on(BRTM.Events.Room.MESSAGE_CHANNEL_OPENED, () => { client.chat.pull(channel: string, next: number = -1, count: number = 10).then((data) => { const { next, channel, hasMore, messageList } = data // messageList 加入缓存 if (hasMore) { // 根据业务逻辑判断是否需要继续拉取历史消息 // 如 UI 向上滚动查看 // 使用 next 作为下一次的 pull 的 next 参数 } }) // 收到新消息 client.chat.on(BRTM.Events.Chat.MESSAGE_RECEIVED, (message) => { // message 加入缓存 }) // 收到新的私聊消息 .on(BRTM.Events.Chat.MESSAGE_WHISPER_RECEIVED, (message) => { // message 加入缓存 }) // 收到撤回消息 .on(BRTM.Events.Chat.MESSAGE_REVOKED, (message) => { // 将撤回的消息从本地缓存删除 }) })
Web
聊天处理流程