You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
shop-app/common/utils/im.js

41 lines
876 B

/*
* @Author: ch
* @Date: 2022-05-20 11:00:07
* @LastEditors: ch
* @LastEditTime: 2022-05-21 15:59:39
* @Description: file content
*/
import MsbIm from '@/common/plugins/msbIm' ;
3 years ago
import {ToAsyncAwait} from '@/common/utils' ;
import $store from '@/common/store';
const Im = new MsbIm({
reconnect: true,
});
3 years ago
const ImInit = async () => {
await ToAsyncAwait(Im.init({
url: `wss://k8s-horse-gateway.mashibing.cn/ws?client=${$store.state.token}&type=1`
3 years ago
}))
};
3 years ago
Im.interceptors.dataChangeAfter = () => {
3 years ago
$store.commit('SET_IM_DATA', Im.sessionData);
let msgCount = 0;
Im.sessionData.forEach(i => {
msgCount += i.unreadCount;
})
3 years ago
$store.commit('SET_IM_MSG_COUNT', msgCount);
}
Im.interceptors.onLogout = () => {
Im.setSessionData([]);
Im.setCurSessionId(null);
$store.commit('SET_IM_DATA', []);
$store.commit('SET_IM_MSG_COUNT', 0);
}
export {
Im,
ImInit
}