@@ -6,15 +6,13 @@ import { StreamChatClient } from './StreamChatClient';
66import { CallTokenPayload , UserTokenPayload } from './types' ;
77import { QueryBannedUsersPayload , UserRequest } from './gen/models' ;
88import { StreamModerationClient } from './StreamModerationClient' ;
9- import { Agent } from 'undici' ;
109
1110export interface StreamClientOptions {
1211 timeout ?: number ;
1312 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 ;
13+ // We use unknown here because RequestInit['dispatcher'] is different between Node versions
1614 /** The [HTTP Agent](https://undici.nodejs.org/#/docs/api/Agent.md) to use. */
17- agent ?: Agent ;
15+ agent ?: unknown ;
1816}
1917
2018export class StreamClient extends CommonApi {
@@ -24,7 +22,6 @@ export class StreamClient extends CommonApi {
2422 public readonly options : StreamClientOptions = { } ;
2523
2624 private static readonly DEFAULT_TIMEOUT = 3000 ;
27- private static readonly MAX_CONNECTIONS = 100 ;
2825
2926 /**
3027 *
@@ -39,39 +36,37 @@ export class StreamClient extends CommonApi {
3936 ) {
4037 const token = JWTServerToken ( secret ) ;
4138 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- } ) ;
5039 const chatBaseUrl = config ?. basePath ?? 'https://chat.stream-io-api.com' ;
5140 const videoBaseUrl = config ?. basePath ?? 'https://video.stream-io-api.com' ;
52- super ( { apiKey, token, timeout, baseUrl : chatBaseUrl , agent } ) ;
41+ super ( {
42+ apiKey,
43+ token,
44+ timeout,
45+ baseUrl : chatBaseUrl ,
46+ agent : config ?. agent as RequestInit [ 'dispatcher' ] ,
47+ } ) ;
5348
5449 this . video = new StreamVideoClient ( {
5550 streamClient : this ,
5651 apiKey,
5752 token,
5853 timeout,
5954 baseUrl : videoBaseUrl ,
60- agent,
55+ agent : config ?. agent as RequestInit [ 'dispatcher' ] ,
6156 } ) ;
6257 this . chat = new StreamChatClient ( {
6358 apiKey,
6459 token,
6560 timeout,
6661 baseUrl : chatBaseUrl ,
67- agent,
62+ agent : config ?. agent as RequestInit [ 'dispatcher' ] ,
6863 } ) ;
6964 this . moderation = new StreamModerationClient ( {
7065 apiKey,
7166 token,
7267 timeout,
7368 baseUrl : chatBaseUrl ,
74- agent,
69+ agent : config ?. agent as RequestInit [ 'dispatcher' ] ,
7570 } ) ;
7671 }
7772
0 commit comments