集成融云即时通讯碰到的一些问题

本文记录了集成融云即时通讯过程中遇到的问题,包括获取历史消息、删除会话后残留、群组历史消息获取、消息ID相同、删除消息错误码以及接收表情显示问题,提供了相应的解决方案。
摘要由CSDN通过智能技术生成

集成融云即时通讯碰到的一些问题

前言

公司产品需要新增即时通讯的模块,经过调研后使用融云的即时通讯 SDK 由于以前没有做过相关聊天类的项目,在开发的时候碰到了很多坑,下面会将碰到的问题和解决方案记录下来以做备份和学习交流

融云官网:https://www.rongcloud.cn/
开发文档:https://docs.rongcloud.cn/v4/

问题列表

1、如何获取历史消息

解决方案:
因为 Web 端没有本地存储,不提供本地获取方法,只能从远端获取
使用获取历史消息方法需要在开发者后台开启 IM 商用版 - 单群聊云存储  服务,服务开通后 30 分钟左右生效
每次最多只能获取 20 条历史消息,通过改变参数 timestrap 来获取其他时间段的历史消息

2、删除会话后还有会话

解决方案:
1、删除会话. 正常来说只要没有收发消息, 会话就不会再生成了
2、如果您有清除 localStorage 的操作, 则 SDK 内部会重新拉取离线消息. 而会话列表是根据收发消息生成的. 则会再次产生会话. 所以建议您检查下是否有清除 localStorage 的操作. 如果有, 建议您只清除自己业务相关的

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是ElementUI集成融云即时通讯版本5.x的详细代码: 1. 首先需要在项目中引入融云WebIM SDK,可以使用npm或者直接引入CDN。 2. 在main.js中全局引入ElementUI和融云WebIM SDK: ``` import Vue from 'vue' import App from './App.vue' import ElementUI from 'element-ui' import 'element-ui/lib/theme-chalk/index.css' import RongIMLib from 'rong-imlib-web-sdk' Vue.config.productionTip = false Vue.use(ElementUI) Vue.prototype.RongIMLib = RongIMLib new Vue({ render: h => h(App), }).$mount('#app') ``` 3. 在需要使用即时通讯的组件中,实现登录和聊天功能: ``` <template> <div class="chat-container"> <!-- 聊天列表 --> <div class="chat-list"> <div v-for="(item, index) in chatList" :key="index">{{ item }}</div> </div> <!-- 聊天输入框 --> <div class="chat-input"> <el-input v-model="inputMsg" placeholder="请输入消息"></el-input> <el-button @click="sendMsg">发送</el-button> </div> </div> </template> <script> export default { data() { return { inputMsg: '', // 输入框内容 chatList: [], // 聊天列表 targetId: 'targetId', // 目标用户ID conversationType: RongIMLib.CONVERSATION_TYPE.PRIVATE, // 会话类型 chatRoomId: null // 聊天室ID } }, methods: { // 登录融云 loginRongIM() { // 获取token,此处省略获取过程 let token = 'token' // 连接融云服务器 this.RongIMLib.RongIMClient.init('appKey') this.RongIMLib.RongIMClient.setConnectionStatusListener({ onChanged: (status) => { console.log('RongIM connect status: ' + status) } }) this.RongIMLib.RongIMClient.connect(token, { onSuccess: (userId) => { console.log('RongIM login success: ' + userId) // 设置当前用户信息 let userInfo = { id: userId, name: 'userName', avatar: 'avatarUrl' } this.RongIMLib.RongIMClient.getInstance().setCurrentUserInfo(userInfo) this.RongIMLib.RongIMClient.getInstance().setConversationNotificationStatus({ conversationType: this.conversationType, targetId: this.targetId, isBlocked: false, notificationStatus: RongIMLib.NOTIFY_STK_NOTIFY }) // 接收消息监听 this.RongIMLib.RongIMClient.getInstance().setOnReceiveMessageListener({ onReceived: (message) => { console.log('RongIM receive message: ' + message.content.content) // 将消息添加到聊天列表 this.chatList.push(message.content.content) } }) }, onError: (errorCode) => { console.log('RongIM login error: ' + errorCode) } }) }, // 发送消息 sendMsg() { let content = this.inputMsg if (!content) { return } let msg = new this.RongIMLib.TextMessage({content: content}) let conversationType = this.conversationType let targetId = this.targetId this.RongIMLib.RongIMClient.getInstance().sendMessage(conversationType, targetId, msg, { onSuccess: (message) => { console.log('RongIM send message success: ' + message.content.content) // 将消息添加到聊天列表 this.chatList.push(message.content.content) // 清空输入框 this.inputMsg = '' }, onError: (errorCode, message) => { console.log('RongIM send message error: ' + errorCode + ', ' + message) } }) } }, mounted() { // 登录融云 this.loginRongIM() } } </script> ``` 以上是ElementUI集成融云即时通讯版本5.x的详细代码,需要注意的是,此处省略了获取token的过程,需要根据实际情况获取。另外,需要将appKey、targetId、conversationType等参数设置为正确的值,以保证功能正常运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值