Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(repeater): stop sending ping event #217

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions packages/repeater/src/lib/DefaultRepeaterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,17 @@ interface SocketListeningEventMap {
interface SocketEmitEventMap {
[SocketEvents.DEPLOY]: (options: DeployCommandOptions) => void;
[SocketEvents.UNDEPLOY]: () => void;
[SocketEvents.PING]: () => void;
}

@scoped(Lifecycle.ContainerScoped)
@injectable()
export class DefaultRepeaterServer implements RepeaterServer {
private readonly MAX_DEPLOYMENT_TIMEOUT = 60_000;
private readonly MAX_PING_INTERVAL = 10_000;
private readonly MAX_RECONNECTION_ATTEMPTS = 20;
private readonly MIN_RECONNECTION_DELAY = 1000;
private readonly MAX_RECONNECTION_DELAY = 86_400_000;

private latestReconnectionError?: Error;
private pingTimer?: Timer;
private connectionTimer?: Timer;
private _socket?: Socket<SocketListeningEventMap, SocketEmitEventMap>;
private connectionAttempts = 0;
Expand Down Expand Up @@ -104,7 +101,6 @@ export class DefaultRepeaterServer implements RepeaterServer {

public disconnect() {
this.events.removeAllListeners();
this.clearPingTimer();
this.clearConnectionTimer();

this._socket?.disconnect();
Expand All @@ -128,8 +124,6 @@ export class DefaultRepeaterServer implements RepeaterServer {
)
]);

this.createPingTimer();

return result;
}

Expand Down Expand Up @@ -336,8 +330,6 @@ export class DefaultRepeaterServer implements RepeaterServer {
};

private handleDisconnect = (reason: string): void => {
this.clearPingTimer();

if (reason !== 'io client disconnect') {
this.events.emit(RepeaterServerEvents.DISCONNECTED);
}
Expand All @@ -356,19 +348,4 @@ export class DefaultRepeaterServer implements RepeaterServer {
);
this.logger.error('An error occurred', error);
}

private createPingTimer() {
this.clearPingTimer();

this.pingTimer = setInterval(
() => this.socket.volatile.emit(SocketEvents.PING),
this.MAX_PING_INTERVAL
).unref();
}

private clearPingTimer() {
if (this.pingTimer) {
clearInterval(this.pingTimer);
}
}
}
Loading