背景: im sdk内部进行mqtt断网后10次重连,10次重连失败后不进行任何处理,在10次重连过程中不断释放connecting、disconnected、connected(这个只有连接上才会emit)
由于不断进行重连会启用多个mqtt,一个平台一个用户mqtt账号唯一,如果在10次重连过程中出发 业务重连,会导致多个mqtt实例进行互相干扰,永远连不上的情况
- main
app.on('browser-window-focus', () => {
console.log('发生:browser-window-focus')
mainWindow.win?.webContents?.send('browser-window-focus')
})
- renderer
// 1、断网前提下,im: disconnected, 如网络重新连接时候,进行业务方触发im连接
useEffect(() => {
// 仅当用户imId存在时候进行im登录
if (currentUser.staffId && networkState.online && [SocketState.DISCONNECTED].includes(imStatus.current)) {
event$.emit({ msgType: 'user:getUserInfo' })
debounceGetAuth()
}
return () => {
// IM.logout()
isLogin.current = false
ImAuth.current = {}
}
}, [currentUser.staffId, networkState.online])
// 2、连网前提下,应用最小化,切至后台,im: disconnected时候进行业务方触发im连接
useEffect(() => {
window.electron.ipcRenderer.on('browser-window-focus', () => {
if (currentUser.staffId && networkState.online && [SocketState.DISCONNECTED].includes(imStatus.current)) {
event$.emit({ msgType: 'user:getUserInfo' })
debounceGetAuth()
}
})
}, [])