背景: im sdk內(nèi)部進(jìn)行mqtt斷網(wǎng)后10次重連,10次重連失敗后不進(jìn)行任何處理,在10次重連過程中不斷釋放connecting、disconnected、connected(這個(gè)只有連接上才會(huì)emit)
由于不斷進(jìn)行重連會(huì)啟用多個(gè)mqtt,一個(gè)平臺(tái)一個(gè)用戶mqtt賬號(hào)唯一,如果在10次重連過程中出發(fā) 業(yè)務(wù)重連,會(huì)導(dǎo)致多個(gè)mqtt實(shí)例進(jìn)行互相干擾,永遠(yuǎn)連不上的情況
- main
app.on('browser-window-focus', () => {
console.log('發(fā)生:browser-window-focus')
mainWindow.win?.webContents?.send('browser-window-focus')
})
- renderer
// 1、斷網(wǎng)前提下,im: disconnected, 如網(wǎng)絡(luò)重新連接時(shí)候,進(jìn)行業(yè)務(wù)方觸發(fā)im連接
useEffect(() => {
// 僅當(dāng)用戶imId存在時(shí)候進(jìn)行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、連網(wǎng)前提下,應(yīng)用最小化,切至后臺(tái),im: disconnected時(shí)候進(jìn)行業(yè)務(wù)方觸發(fā)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()
}
})
}, [])