Show critical-idle-primary-device banner in response to WS upgrade response headers

This commit is contained in:
trevor-signal 2025-03-06 12:58:57 -05:00 committed by GitHub
commit f5fe787ed7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 337 additions and 14 deletions

View file

@ -3,6 +3,7 @@
import { client as WebSocketClient } from 'websocket';
import type { connection as WebSocket } from 'websocket';
import type { IncomingMessage } from 'http';
import { AbortableProcess } from '../util/AbortableProcess';
import { strictAssert } from '../util/assert';
@ -32,6 +33,7 @@ export type ConnectOptionsType<Resource extends IResource> = Readonly<{
proxyAgent?: ProxyAgent;
timeout?: number;
extraHeaders?: Record<string, string>;
onUpgradeResponse?: (response: IncomingMessage) => void;
createResource(socket: WebSocket): Resource;
}>;
@ -44,6 +46,7 @@ export function connect<Resource extends IResource>({
proxyAgent,
extraHeaders = {},
timeout = WEBSOCKET_CONNECT_TIMEOUT,
onUpgradeResponse,
createResource,
}: ConnectOptionsType<Resource>): AbortableProcess<Resource> {
const fixedScheme = url
@ -84,6 +87,10 @@ export function connect<Resource extends IResource>({
resolve(resource);
});
client.on('upgradeResponse', response => {
onUpgradeResponse?.(response);
});
client.on('httpResponse', async response => {
Timers.clearTimeout(timer);