Skip to content

Commit 661cbfa

Browse files
committed
fix websocket cleanup
1 parent 3b2e5a4 commit 661cbfa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/services/Server/WebSocketClient.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,41 @@ export default class WebSocketClient {
153153
this.sendMessage(pingMessage, true);
154154
}
155155

156+
/**
157+
* Cleanup websocket connection and intervals
158+
*/
159+
cleanup() {
160+
if (this.websocket) {
161+
this.websocket.close();
162+
this.websocket = null;
163+
}
164+
165+
if (this.pingHandle) {
166+
clearInterval(this.pingHandle);
167+
this.pingHandle = null;
168+
}
169+
170+
if (this.reconnectionHandle) {
171+
clearTimeout(this.reconnectionHandle);
172+
this.reconnectionHandle = null;
173+
}
174+
175+
this.reconnectionAttempts = 0;
176+
this.queuedMessages = [];
177+
}
178+
156179
/**
157180
* Handles websocket close events, attempting to reconnect
158181
*
159182
* @private
160183
*/
161184
handleClose() {
185+
// Clear ping interval on close
186+
if (this.pingHandle) {
187+
clearInterval(this.pingHandle);
188+
this.pingHandle = null;
189+
}
190+
162191
this.connect();
163192
}
164193

0 commit comments

Comments
 (0)