const LeanRT = {}
const AV = require(‘leancloud-storage’)
const IM = require(‘leancloud-realtime’)
var { Event } = require(‘leancloud-realtime’)
const initPlugin = require(‘leancloud-realtime-plugin-typed-messages’)
const { Realtime } = IM
const { TypedMessagesPlugin } = initPlugin(AV, IM)
const realtime = new Realtime({
appId: ‘**’,
appKey: 'mb’,
server: '’,
plugins: TypedMessagesPlugin
})
AV.init({
appId: '’,
appKey: '’,
serverURL: '’
})
LeanRT.realtime = realtime
LeanRT.imClient = realtime.createIMClient(
store.getters.userInfo.Telephone
)
LeanRT.currentConversation = null
LeanRT.imClient.then(res => {
res.on(Event.MESSAGE, function messageEventHandler(
message,
conversation
) {
var aa = store.getters.PendingCount
store.dispatch(‘user/setPendingCount’, aa + 1).then(re => {
console.log(re)
})
console.log(‘收到新消息’)
})
})
store.dispatch('user/loginLean', LeanRT).then(res => {
console.log('leancould登录成功')
})