From c18559b6dac42699af8ad7f14112a600c6a09578 Mon Sep 17 00:00:00 2001 From: trevor-signal <131492920+trevor-signal@users.noreply.github.com> Date: Thu, 2 May 2024 16:53:53 -0400 Subject: [PATCH] Mark offline if websocket connection attempt times out --- ts/textsecure/SocketManager.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ts/textsecure/SocketManager.ts b/ts/textsecure/SocketManager.ts index 3eec4dd1a54f..07b059c1a5c2 100644 --- a/ts/textsecure/SocketManager.ts +++ b/ts/textsecure/SocketManager.ts @@ -36,7 +36,7 @@ import WebSocketResource, { TransportOption, WebSocketResourceWithShadowing, } from './WebsocketResources'; -import { HTTPError } from './Errors'; +import { ConnectTimeoutError, HTTPError } from './Errors'; import type { IRequestHandler, WebAPICredentials } from './Types.d'; import { connect as connectWebSocket } from './WebSocket'; import { isAlpha, isBeta, isStaging } from '../util/version'; @@ -117,6 +117,13 @@ export class SocketManager extends EventListener { return this.status; } + private markOffline() { + if (this.privIsOnline !== false) { + this.privIsOnline = false; + this.emit('offline'); + } + } + // Update WebAPICredentials and reconnect authenticated resource if // credentials changed public async authenticate(credentials: WebAPICredentials): Promise { @@ -257,10 +264,11 @@ export class SocketManager extends EventListener { return; } - if (code === -1 && this.privIsOnline !== false) { - this.privIsOnline = false; - this.emit('offline'); + if (code === -1) { + this.markOffline(); } + } else if (error instanceof ConnectTimeoutError) { + this.markOffline(); } drop(reconnect());