File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments