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.
48 lines
1.1 KiB
48 lines
1.1 KiB
/*
|
|
* @Author: ch
|
|
* @Date: 2022-05-20 11:00:07
|
|
* @LastEditors: ch
|
|
* @LastEditTime: 2022-05-21 19:47:08
|
|
* @Description: file content
|
|
*/
|
|
|
|
import MsbIm from '@/common/plugins/msbIm' ;
|
|
import { ToAsyncAwait } from '@/common/utils';
|
|
import { ApiGetCurrentUser } from '@/common/api/account';
|
|
import $store from '@/common/store';
|
|
|
|
const Im = new MsbIm({
|
|
reconnect: true,
|
|
});
|
|
const ImInit = async () => {
|
|
const { error } = await ApiGetCurrentUser();
|
|
if (error) {
|
|
return false;
|
|
}
|
|
await ToAsyncAwait(Im.init({
|
|
// url: `wss://k8s-horse-gateway.mashibing.cn/ws?client=${$store.state.token}&type=1`
|
|
url: `wss://you-gateway.mashibing.com/ws?client=${$store.state.token}&type=1`
|
|
}))
|
|
};
|
|
|
|
Im.interceptors.dataChangeAfter = () => {
|
|
$store.commit('SET_IM_DATA', Im.sessionData);
|
|
let msgCount = 0;
|
|
Im.sessionData.forEach(i => {
|
|
msgCount += i.unreadCount;
|
|
})
|
|
console.log(Im.sessionData)
|
|
$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
|
|
}
|