@@ -6,10 +6,15 @@ import { StreamChatClient } from './StreamChatClient';
66import { CallTokenPayload , UserTokenPayload } from './types' ;
77import { QueryBannedUsersPayload , UserRequest } from './gen/models' ;
88import { StreamModerationClient } from './StreamModerationClient' ;
9+ import { Agent } from 'undici' ;
910
1011export interface StreamClientOptions {
1112 timeout ?: number ;
1213 basePath ?: string ;
14+ /** The max number of clients to create. `null` if no limit. Default is 100. Has no effect if `agent` is provided. */
15+ maxConnections ?: number | null ;
16+ /** The [Agent](https://undici.nodejs.org/#/docs/api/Agent.md) to use. */
17+ agent ?: Agent ;
1318}
1419
1520export class StreamClient extends CommonApi {
@@ -19,6 +24,7 @@ export class StreamClient extends CommonApi {
1924 public readonly options : StreamClientOptions = { } ;
2025
2126 private static readonly DEFAULT_TIMEOUT = 3000 ;
27+ private static readonly MAX_CONNECTIONS = 100 ;
2228
2329 /**
2430 *
@@ -33,28 +39,39 @@ export class StreamClient extends CommonApi {
3339 ) {
3440 const token = JWTServerToken ( secret ) ;
3541 const timeout = config ?. timeout ?? StreamClient . DEFAULT_TIMEOUT ;
42+ const agent =
43+ config ?. agent ??
44+ new Agent ( {
45+ connections :
46+ config ?. maxConnections === undefined
47+ ? StreamClient . MAX_CONNECTIONS
48+ : config . maxConnections ,
49+ } ) ;
3650 const chatBaseUrl = config ?. basePath ?? 'https://chat.stream-io-api.com' ;
3751 const videoBaseUrl = config ?. basePath ?? 'https://video.stream-io-api.com' ;
38- super ( { apiKey, token, timeout, baseUrl : chatBaseUrl } ) ;
52+ super ( { apiKey, token, timeout, baseUrl : chatBaseUrl , agent } ) ;
3953
4054 this . video = new StreamVideoClient ( {
4155 streamClient : this ,
4256 apiKey,
4357 token,
4458 timeout,
4559 baseUrl : videoBaseUrl ,
60+ agent,
4661 } ) ;
4762 this . chat = new StreamChatClient ( {
4863 apiKey,
4964 token,
5065 timeout,
5166 baseUrl : chatBaseUrl ,
67+ agent,
5268 } ) ;
5369 this . moderation = new StreamModerationClient ( {
5470 apiKey,
5571 token,
5672 timeout,
5773 baseUrl : chatBaseUrl ,
74+ agent,
5875 } ) ;
5976 }
6077
0 commit comments