Lazy import proxy-agent

This commit is contained in:
Fedor Indutny 2024-03-20 11:05:10 -07:00 committed by GitHub
parent 83e8f4b59d
commit 091b50c414
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 60 additions and 39 deletions

View file

@ -19,6 +19,7 @@ import * as durations from '../util/durations';
import { sleep } from '../util/sleep';
import { drop } from '../util/drop';
import { createProxyAgent } from '../util/createProxyAgent';
import type { ProxyAgent } from '../util/createProxyAgent';
import { SocketStatus } from '../types/SocketStatus';
import * as Errors from '../types/errors';
import * as Bytes from '../Bytes';
@ -84,7 +85,7 @@ export class SocketManager extends EventListener {
private credentials?: WebAPICredentials;
private readonly proxyAgent?: ReturnType<typeof createProxyAgent>;
private proxyAgent?: ProxyAgent;
private status = SocketStatus.CLOSED;
@ -105,10 +106,6 @@ export class SocketManager extends EventListener {
constructor(private readonly options: SocketManagerOptions) {
super();
if (options.proxyUrl) {
this.proxyAgent = createProxyAgent(options.proxyUrl);
}
this.hasStoriesDisabled = options.hasStoriesDisabled;
}
@ -338,6 +335,11 @@ export class SocketManager extends EventListener {
url: string;
extraHeaders?: Record<string, string>;
}): Promise<WebSocket> {
// Create proxy agent lazily
if (this.options.proxyUrl && !this.proxyAgent) {
this.proxyAgent = await createProxyAgent(this.options.proxyUrl);
}
return connectWebSocket({
name: 'art-creator-provisioning',
url,