mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-17 02:01:31 +00:00
[ide-react] Avoid showing disconnected message if leaving page (#16263)
GitOrigin-RevId: bda7ed207a66b0f051d284cd9b31a20b2c93edca
This commit is contained in:
parent
731f071a4e
commit
56d70a18ae
1 changed files with 6 additions and 0 deletions
|
@ -41,6 +41,7 @@ export class ConnectionManager extends Emitter<Events> {
|
|||
private readonly idleDisconnectInterval: number
|
||||
private reconnectCountdownInterval = 0
|
||||
readonly socket: Socket
|
||||
private userIsLeavingPage = false
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
|
@ -51,6 +52,9 @@ export class ConnectionManager extends Emitter<Events> {
|
|||
}, ONE_HOUR_IN_MS)
|
||||
|
||||
window.addEventListener('online', () => this.onOnline())
|
||||
window.addEventListener('beforeunload', () => {
|
||||
this.userIsLeavingPage = true
|
||||
})
|
||||
|
||||
const socket = SocketIoShim.connect('', {
|
||||
'auto connect': false,
|
||||
|
@ -85,6 +89,7 @@ export class ConnectionManager extends Emitter<Events> {
|
|||
// Called when document is clicked or the editor cursor changes
|
||||
registerUserActivity() {
|
||||
this.lastUserActivity = performance.now()
|
||||
this.userIsLeavingPage = false
|
||||
this.ensureIsConnected()
|
||||
}
|
||||
|
||||
|
@ -273,6 +278,7 @@ export class ConnectionManager extends Emitter<Events> {
|
|||
}
|
||||
|
||||
private startAutoReconnectCountdown(backoff: number) {
|
||||
if (this.userIsLeavingPage) return
|
||||
if (!this.canReconnect()) return
|
||||
let countdown
|
||||
if (this.isUserInactiveSince(TWO_MINUTES_IN_MS)) {
|
||||
|
|
Loading…
Reference in a new issue