1.0.0 • Published 1 year ago
ljb-im v1.0.0
介绍
ljb_im
是一个针对立吉报go_IM对接的SDK依赖,综合使用protobufjs进行压缩和解压数据,可以直接引入使用
安装
npm install [--save] ljb_im
使用
1.首先在main.js 文件中已入依赖并使用
import ljbIm from 'ljb_im';
Vue.use(ljbIm);
2、首先需要初始化依赖
//调用init 方法 ,依次传入 用户ID,用户名称,房间号码
this.$IMSDK.int(userId, userName, roomID)
3、推送信息压缩
3.1、用户登录信息推送
//调用 clientLoginSend 方法 ,传入立吉报生成的返回的token
this.$IMSDK.clientLoginSend(token)
3.2、用户心跳信息推送
//调用 heartBeatSend 方法
this.$IMSDK.heartBeatSend()
3.3、用户在线人数信息推送
//调用 onlineUserNumSend 方法
this.$IMSDK.onlineUserNumSend()
3.4、普通消息推送
//调用 clientMessageSend 方法,依次发送内容、时间
this.$IMSDK.clientMessageSend(content,sendTime)
-注意:以上压缩信息函数均返回已处理好合适请求后端ws的数据
4、接收数据解析
//调用 transformResponse 方法,依次传入系统返回数据 rawResponse(arrayBuffer类型)
this.$IMSDK.transformResponse(rawResponse)
4.1 解析后数据分析
-解析后数据返回格式json
barrageDecode = {
type:
data:{
}
}
barrageDecode.type = 0 || 2 || 3 || 4
4.2 barrageDecode.type = 0; 登录、成功、错误信息
错误信息,或者登录成功信息
barrageDecode.data = {
code:0,
msg:'',
}
barrageDecode.data.code = 100; // 登录失效,重新登录
barrageDecode.data.code = 0 ; // 登录成功,返回成功信息
barrageDecode.data.code !=0 ; // 返回错误信息
4.3 barrageDecode.type = 2; 心跳信息返回
barrageDecode.data = {
'pong'
}
4.4 barrageDecode.type = 3; ws聊天信息
barrageDecode.data = {
msgLv = 1,
data = [{
content:'内容',
sendTime:'发送时间',
userId:'发送用户ID',
userName:'发送用户名称',
}]
}
// 当时重要消息推送时 barrageDecode.data.type = 1
// 当时普通推送时 barrageDecode.data.type 不存在
详细例子查看 /example/webSocket.vue
1.0.0
1 year ago