fix(realtime): proper reconnect handling for socket.io
Socket.IO seems to include an own reconnect mechanism for some time. HedgeDoc however built an own reconnect mechanism on top of that. Since the 'reconnect' event was dropped for socket.io 4.x, the reconnect-cleanup code didn't run anymore. This commit fixes this by: - removing the manual reconnect interval, - putting the reconnect handler into the correct place, - setting reconnection options on the server side Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
committed by
Philip Molares
parent
d1ad8d71fe
commit
766d00c4d9
@@ -2233,7 +2233,6 @@ socket.on('delete', function () {
|
||||
})
|
||||
}
|
||||
})
|
||||
let retryTimer = null
|
||||
socket.on('maintenance', function () {
|
||||
cmClient.revision = -1
|
||||
})
|
||||
@@ -2246,21 +2245,17 @@ socket.on('disconnect', function (data) {
|
||||
if (!editor.getOption('readOnly')) {
|
||||
editor.setOption('readOnly', true)
|
||||
}
|
||||
if (!retryTimer) {
|
||||
retryTimer = setInterval(function () {
|
||||
if (!needRefresh) socket.connect()
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
socket.on('reconnect', function (data) {
|
||||
// sync back any change in offline
|
||||
emitUserStatus(true)
|
||||
cursorActivity(editor)
|
||||
socket.emit('online users')
|
||||
})
|
||||
socket.on('connect', function (data) {
|
||||
clearInterval(retryTimer)
|
||||
retryTimer = null
|
||||
if (socket.recovered) {
|
||||
// sync back any change in offline
|
||||
console.debug('Reconnected client')
|
||||
emitUserStatus(true)
|
||||
cursorActivity(editor)
|
||||
socket.emit('online users')
|
||||
return
|
||||
}
|
||||
console.debug('Client connected (no reconnect)')
|
||||
personalInfo.id = socket.id
|
||||
showStatus(statusType.connected)
|
||||
socket.emit('version')
|
||||
|
||||
Reference in New Issue
Block a user