|
|
|
@ -62,6 +62,49 @@ function getTotalUnreadCount() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mineReadfile().then(value => {
|
|
|
|
|
|
|
|
|
|
RongIMClient = RongIMLib.init({
|
|
|
|
|
appkey: value.key,
|
|
|
|
|
});
|
|
|
|
|
RongIMClient.connect({ token: value.token })
|
|
|
|
|
.then((user) => {
|
|
|
|
|
console.log("连接成功, 用户 id 为:", user.id);
|
|
|
|
|
localStorage.setItem("user_info", JSON.stringify({ id: user.id }));
|
|
|
|
|
// 获取消息数量
|
|
|
|
|
getTotalUnreadCount()
|
|
|
|
|
|
|
|
|
|
// 添加事件监听
|
|
|
|
|
RongIMClient.watch({
|
|
|
|
|
// 监听消息通知
|
|
|
|
|
message(event) {
|
|
|
|
|
// 新接收到的消息内容
|
|
|
|
|
const message = event.message;
|
|
|
|
|
console.log("event", event);
|
|
|
|
|
|
|
|
|
|
getTotalUnreadCount()
|
|
|
|
|
if (event.message.type === 1) {
|
|
|
|
|
vueCom.$bus.emit("handelSendMessage", 1, event.message);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 监听 IM 连接状态变化
|
|
|
|
|
status(event) {
|
|
|
|
|
// 链接监听失败回调
|
|
|
|
|
console.log('connection status:', event.status);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 发送全局融云以便其他地方调取融云方法
|
|
|
|
|
Vue.prototype.RongIMClient = RongIMClient
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
|
|
|
|
|
console.log("连接失败: ", error.code, error.msg);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}, reason => {
|
|
|
|
|
console.log(reason, 222)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -116,49 +159,6 @@ function testPersonInfo(to, from, next) {
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mineReadfile().then(value => {
|
|
|
|
|
|
|
|
|
|
RongIMClient = RongIMLib.init({
|
|
|
|
|
appkey: value.key,
|
|
|
|
|
});
|
|
|
|
|
RongIMClient.connect({ token: value.token })
|
|
|
|
|
.then((user) => {
|
|
|
|
|
console.log("连接成功, 用户 id 为:", user.id);
|
|
|
|
|
localStorage.setItem("user_info", JSON.stringify({ id: user.id }));
|
|
|
|
|
// 获取消息数量
|
|
|
|
|
getTotalUnreadCount()
|
|
|
|
|
|
|
|
|
|
// 添加事件监听
|
|
|
|
|
RongIMClient.watch({
|
|
|
|
|
// 监听消息通知
|
|
|
|
|
message(event) {
|
|
|
|
|
// 新接收到的消息内容
|
|
|
|
|
const message = event.message;
|
|
|
|
|
console.log("event", event);
|
|
|
|
|
|
|
|
|
|
getTotalUnreadCount()
|
|
|
|
|
if (event.message.type === 1) {
|
|
|
|
|
vueCom.$bus.emit("handelSendMessage", 1, event.message);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 监听 IM 连接状态变化
|
|
|
|
|
status(event) {
|
|
|
|
|
// 链接监听失败回调
|
|
|
|
|
console.log('connection status:', event.status);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 发送全局融云以便其他地方调取融云方法
|
|
|
|
|
Vue.prototype.RongIMClient = RongIMClient
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
|
|
|
|
|
console.log("连接失败: ", error.code, error.msg);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}, reason => {
|
|
|
|
|
console.log(reason, 222)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gotoPage(to, from, next);
|
|
|
|
|