Skip to content

Commit

Permalink
review fix to simplify change
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcallister-cll committed Oct 6, 2023
1 parent c48ed0d commit 123107f
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/transports/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,19 @@ export class WebSocketTransport<

// Check if we should close the current connection
if (!connectionClosed && (urlChanged || connectionUnresponsive)) {
const reason = urlChanged
? `Websocket url has changed from ${this.currentUrl} to ${urlFromConfig}, closing connection...`
: `Last message was received ${timeSinceLastMessage} ago, exceeding the threshold of ${context.adapterSettings.WS_SUBSCRIPTION_UNRESPONSIVE_TTL}ms, closing connection...`
const logfn = urlChanged && this.isUrlSubscriptionWebsocket ? logger.debug : logger.info
censorLogs(() => logfn(reason))
if (urlChanged) {
censorLogs(() =>
logger.debug(
`Websocket url has changed from ${this.currentUrl} to ${urlFromConfig}, closing connection...`,
),
)
} else {
censorLogs(() =>
logger.info(
`Last message was received ${timeSinceLastMessage} ago, exceeding the threshold of ${context.adapterSettings.WS_SUBSCRIPTION_UNRESPONSIVE_TTL}ms, closing connection...`,
),
)
}

// Check if connection was opened very recently; if so, wait a bit before continuing.
// This is so if we just opened the connection and are waiting to receive some messages,
Expand Down Expand Up @@ -468,12 +476,3 @@ export class WebsocketReverseMappingTransport<
return this.requestMapping.get(value)
}
}

export class UrlSubscriptionWebsocketTransport<
T extends WebsocketTransportGenerics,
> extends WebSocketTransport<T> {
constructor(config: WebSocketTransportConfig<T>) {
super(config)
this.isUrlSubscriptionWebsocket = true
}
}

0 comments on commit 123107f

Please sign in to comment.