Mark offline if websocket connection attempt times out
This commit is contained in:
parent
80bc63bb90
commit
c18559b6da
1 changed files with 12 additions and 4 deletions
|
@ -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<void> {
|
||||
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue