MCPcopy Create free account
hub / github.com/block/buzz / resetConnection

Method resetConnection

desktop/src/shared/api/relayClientSession.ts:951–1015  ·  view source on GitHub ↗
(
    error: Error,
    options?: {
      reconnect?: boolean;
    },
  )

Source from the content-addressed store, hash-verified

949 }
950
951 private resetConnection(
952 error: Error,
953 options?: {
954 reconnect?: boolean;
955 },
956 ) {
957 this.onMessageChannel = null;
958 this.stallWatchdog.stop();
959 this.connectionGeneration++;
960 if (this.flushTimeout !== null) window.clearTimeout(this.flushTimeout);
961 this.flushTimeout = null;
962 this.eventBuffer = [];
963
964 if (options?.reconnect === false) {
965 this.terminal = true;
966 this.connectionStateEmitter.set("disconnected");
967 } else if (this.connectionStateEmitter.get() !== "stalled") {
968 // Stall is a stronger signal than a generic drop; keep it until the
969 // reconnect timer transitions us back to "reconnecting" in connect().
970 this.connectionStateEmitter.set("reconnecting");
971 }
972
973 if (options?.reconnect !== false && this.hasConnectedOnce) {
974 this.notifyReconnectListeners = true;
975 }
976
977 if (options?.reconnect === false && this.reconnectTimeout) {
978 window.clearTimeout(this.reconnectTimeout);
979 this.reconnectTimeout = null;
980 }
981
982 if (this.wsId !== null) {
983 void closeWebSocket(this.wsId, "connection reset");
984 }
985
986 this.wsId = null;
987
988 if (this.authRequest) {
989 window.clearTimeout(this.authRequest.timeout);
990 this.authRequest.reject(error);
991 this.authRequest = null;
992 }
993
994 for (const [subId, subscription] of this.subscriptions) {
995 if (subscription.mode === "history") {
996 window.clearTimeout(subscription.timeout);
997 subscription.reject(error);
998 this.subscriptions.delete(subId);
999 continue;
1000 }
1001
1002 subscription.resolveReady?.();
1003 subscription.resolveReady = undefined;
1004 }
1005
1006 for (const [eventId, pendingEvent] of this.pendingEvents) {
1007 window.clearTimeout(pendingEvent.timeout);
1008 pendingEvent.reject(error);

Callers 6

RelayClientClass · 0.95
connectMethod · 0.95
handleWsMessageMethod · 0.95
handleOkMethod · 0.95

Calls 7

scheduleReconnectMethod · 0.95
closeWebSocketFunction · 0.90
setMethod · 0.80
resolveReadyMethod · 0.80
stopMethod · 0.45
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected