ola-im
v1.0.42
Published
ola IM
Downloads
7
Readme
@ola/im
Ola IM SDK
对接文档: https://docs.qq.com/doc/DQXRTbWliRnNqc2ZE?u=acdde7ff386045bc9b08e97e85fbddb5
DEMO
[packages/im/demo/index.html]
ToDoList
- [x] 关注用户会话隔离 / 关注 / 取关通知
- [x] finish状态更新
- [x] 聊天消息记录,通过接口拉取
- [x] withoutUserIds
- [x] 手动拉取关注用户 / 非关注列表
- [x] IM Websocket状态丢失时,自动重新连接
- [x] 删除会话接口
- [] 删除会话接口 - 对接新IM
- [] ts改造
usage
import IM, { ConversationType, IMEvent } from '@ola/im'
//连接IM //Step1. 登录,获取IM Token (api接口校验登录态,请求IM token接口,返回给前端)
//前端测试
curl --location --request POST 'http://115.29.215.193:6080/imapi/user/add' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-raw 'userId=100020126&name=moli&portraitUri=http://apc-admin-test.oss-cn-hangzhou.aliyuncs.com/mini/whisper/24051114250163.jpg&appId=50'
//Step2. 初始化IM SDK
IM.init({
//项目appid
appId: '50',
imToken: '5ff10ilXcwP9RPBVCGSpqK81oNaX4wFRepk8L5MlHSW__2BOCD5TtRQl6KsB9Dd8__2BSZptLGv5YuHbg9Ia4dY__2FQPsFaAdYix7YGa__2BY__2B8Zuo__2FwaaSPaq1z9VM0w',
uid: '100020126',
icon: 'http://apc-admin-test.oss-cn-hangzhou.aliyuncs.com/mini/whisper/24051114250163.jpg',
name: 'moli',
pkg: 'com.mixer.web',
// clientType: 7,
//关注用户列表
followUids: ['111329177', '111836614', '111329177'],
//可选,默认值:奥帕云国内线上
socketAddress: 'ws://115.29.215.193:6080/imgate/ws/connect',
//可选,默认值:15
heartBeat: 15
})
.then((res) => {
console.log('IM init done', res)
})
.catch((e) => {
console.log('IM error done', res)
})
//监听IM事件,dispose时取消监听
IM.mitt.on(IMEvent.MESSAGE_NOTIFY, function (res) {
console.log('IMEvent.MESSAGE_NOTIFY', res)
})
IM.mitt.on(IMEvent.MESSAGE_CMD, function (res) {
console.log('IMEvent.MESSAGE_CMD', res)
})
IM.mitt.on(IMEvent.MESSAGE_RECEIPT, function (res) {
console.log('IMEvent.MESSAGE_RECEIPT', res)
})
IM.mitt.on(IMEvent.MESSAGE_GLOBAL, function (res) {
console.log('IMEvent.MESSAGE_GLOBAL', res)
})
IM.mitt.on(IMEvent.CONVERSATION_NOTIFY, function (res) {
console.log('IMEvent.CONVERSATION_NOTIFY', res)
})
IM.mitt.on(IMEvent.KICK_OUT, function (res) {
console.log('IMEvent.KICK_OUT', res)
})
IM.mitt.on(IMEvent.ERROR, function (res) {
console.log('IMEvent.ERROR', res)
})