首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >小程序多次调登录和退出api会多次触发TIM.EVENT.MESSAGE_RECEIVED事件?

小程序多次调登录和退出api会多次触发TIM.EVENT.MESSAGE_RECEIVED事件?

提问于 2020-06-29 12:02:53
回答 2关注 0查看 1.1K

onLoad: function (options) {

this.logIn()

}

/**

* IM登录

*/

logIn(){

let onMessageReceived = function(event) {

console.log(event,'收消息') //会多次触发

let msg = that.data.msg

msg.messageList = [...that.data.msg.messageList,...event.data]

that.setData({msg},()=>{

that.data.jumpView&&wx.nextTick(() => {

that.setData({ toView:`roll${msg.messageList.length}` }) // 在当前同步流程结束后,下一个时间片执行

})

})

}

let onSdkReady = function(event) {

console.log(event,'实例加载')

that.isCancel()

}

tim.on(TIM.EVENT.SDK_READY, onSdkReady);

tim.on(TIM.EVENT.MESSAGE_RECEIVED, onMessageReceived)

let promise = tim.login({userID: this.data.userAccount , userSig:getApp().globalData.userSig})

promise.then(function(imResponse) {

console.log(imResponse.data,'登录'); // 登录成功

if (imResponse.data.repeatLogin === true) {

that.getList(null,null)

}

}).catch(function(imError) {

console.warn('login error:', imError); // 登录失败的相关信息

});

},

onUnload: function () {

let promise = tim.logout()

promise.then(function(imResponse) {

console.log(imResponse,'退出成功');

}).catch(function(imError) {

console.warn('logout error:', imError);

})

},

相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档