IM的链接和断开时机调整,APP打开自动判断登录,链接。退出登录后断开链接
新朋友数量提醒
This commit is contained in:
@@ -3,13 +3,20 @@ import * as CallLib from '@/uni_modules/RongCloud-CallWrapper/lib/index'
|
||||
import store from '@/store/index.js'
|
||||
import {
|
||||
getFriends,
|
||||
getUserInfo
|
||||
getUserInfo,
|
||||
getImToken
|
||||
} from '@/apis/interfaces/im.js'
|
||||
|
||||
const initIm = (KEY) => {
|
||||
RongIMLib.init(KEY)
|
||||
CallLib.init()
|
||||
addListeners()
|
||||
// 初始化的时候 自动链接
|
||||
if (store.getters.getToken !== '') {
|
||||
getImToken().then(res => {
|
||||
connect(res.token, res.userInfo, () => {})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const setNotifyBadge = () => {
|
||||
@@ -19,6 +26,9 @@ const setNotifyBadge = () => {
|
||||
count
|
||||
}) => {
|
||||
if (code === 0) {
|
||||
// #ifdef APP-PLUS
|
||||
plus.runtime.setBadgeNumber(count)
|
||||
// #endif
|
||||
if (count > 0) {
|
||||
uni.setTabBarBadge({
|
||||
index: 3,
|
||||
@@ -31,6 +41,7 @@ const setNotifyBadge = () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,6 +71,13 @@ const connect = (token, userInfo, callback) => {
|
||||
|
||||
const disconnect = () => {
|
||||
RongIMLib.disconnect()
|
||||
// 移除提醒数量
|
||||
// #ifdef APP-PLUS
|
||||
plus.runtime.setBadgeNumber(0)
|
||||
// #endif
|
||||
uni.removeTabBarBadge({
|
||||
index: 3
|
||||
})
|
||||
}
|
||||
|
||||
// 允许通知的消息类型,触发更新消息列表操作
|
||||
@@ -103,9 +121,9 @@ const addListeners = () => {
|
||||
// 监听通话呼入
|
||||
CallLib.onCallReceived(({
|
||||
data
|
||||
}) => {
|
||||
console.log('onCallReceived', data)
|
||||
|
||||
}) => {
|
||||
console.log('onCallReceived', data)
|
||||
|
||||
uni.navigateTo({
|
||||
url: '/pages/im/private/call?targetId=' + data.targetId + '&mediaType=' +
|
||||
data.mediaType
|
||||
@@ -113,7 +131,7 @@ const addListeners = () => {
|
||||
})
|
||||
|
||||
// 通话建立成功
|
||||
CallLib.onCallConnected(() => {
|
||||
CallLib.onCallConnected(() => {
|
||||
uni.$emit('onCallConnected');
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user