MCPcopy Create free account
hub / github.com/Noumena-Network/code / close

Method close

src/remote/SessionsWebSocket.ts:368–386  ·  view source on GitHub ↗

* Close the WebSocket connection

()

Source from the content-addressed store, hash-verified

366 * Close the WebSocket connection
367 */
368 close(): void {
369 logForDebugging('[SessionsWebSocket] Closing connection')
370 this.state = 'closed'
371 this.stopPingInterval()
372
373 if (this.reconnectTimer) {
374 clearTimeout(this.reconnectTimer)
375 this.reconnectTimer = null
376 }
377
378 if (this.ws) {
379 // Null out event handlers to prevent race conditions during reconnect.
380 // Under Bun (native WebSocket), onX handlers are the clean way to detach.
381 // Under Node (ws package), the listeners were attached with .on() in connect(),
382 // but since we're about to close and null out this.ws, no cleanup is needed.
383 this.ws.close()
384 this.ws = null
385 }
386 }
387
388 /**
389 * Force reconnect - closes existing connection and establishes a new one.

Callers 1

reconnectMethod · 0.95

Calls 2

stopPingIntervalMethod · 0.95
logForDebuggingFunction · 0.50

Tested by

no test coverage detected