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,
|
TransportOption,
|
||||||
WebSocketResourceWithShadowing,
|
WebSocketResourceWithShadowing,
|
||||||
} from './WebsocketResources';
|
} from './WebsocketResources';
|
||||||
import { HTTPError } from './Errors';
|
import { ConnectTimeoutError, HTTPError } from './Errors';
|
||||||
import type { IRequestHandler, WebAPICredentials } from './Types.d';
|
import type { IRequestHandler, WebAPICredentials } from './Types.d';
|
||||||
import { connect as connectWebSocket } from './WebSocket';
|
import { connect as connectWebSocket } from './WebSocket';
|
||||||
import { isAlpha, isBeta, isStaging } from '../util/version';
|
import { isAlpha, isBeta, isStaging } from '../util/version';
|
||||||
|
@ -117,6 +117,13 @@ export class SocketManager extends EventListener {
|
||||||
return this.status;
|
return this.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private markOffline() {
|
||||||
|
if (this.privIsOnline !== false) {
|
||||||
|
this.privIsOnline = false;
|
||||||
|
this.emit('offline');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update WebAPICredentials and reconnect authenticated resource if
|
// Update WebAPICredentials and reconnect authenticated resource if
|
||||||
// credentials changed
|
// credentials changed
|
||||||
public async authenticate(credentials: WebAPICredentials): Promise<void> {
|
public async authenticate(credentials: WebAPICredentials): Promise<void> {
|
||||||
|
@ -257,10 +264,11 @@ export class SocketManager extends EventListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code === -1 && this.privIsOnline !== false) {
|
if (code === -1) {
|
||||||
this.privIsOnline = false;
|
this.markOffline();
|
||||||
this.emit('offline');
|
|
||||||
}
|
}
|
||||||
|
} else if (error instanceof ConnectTimeoutError) {
|
||||||
|
this.markOffline();
|
||||||
}
|
}
|
||||||
|
|
||||||
drop(reconnect());
|
drop(reconnect());
|
||||||
|
|
Loading…
Reference in a new issue