stream-chat 7.1.0 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/client.ts CHANGED
@@ -179,9 +179,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
179
179
  clientID?: string;
180
180
  configs: Configs<StreamChatGenerics>;
181
181
  key: string;
182
- listeners: {
183
- [key: string]: Array<(event: Event<StreamChatGenerics>) => void>;
184
- };
182
+ listeners: Record<string, Array<(event: Event<StreamChatGenerics>) => void>>;
185
183
  logger: Logger;
186
184
  /**
187
185
  * When network is recovered, we re-query the active channels on client. But in single query, you can recover
@@ -212,6 +210,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
212
210
  insightMetrics: InsightMetrics;
213
211
  defaultWSTimeoutWithFallback: number;
214
212
  defaultWSTimeout: number;
213
+ private nextRequestAbortController: AbortController | null = null;
215
214
 
216
215
  /**
217
216
  * Initialize a client
@@ -1196,7 +1195,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
1196
1195
  }
1197
1196
 
1198
1197
  if (event.channel && event.type === 'notification.message_new') {
1199
- this.configs[event.channel.type] = event.channel.config;
1198
+ this._addChannelConfig(event.channel);
1200
1199
  }
1201
1200
 
1202
1201
  if (event.type === 'notification.channel_mutes_updated' && event.me?.channel_mutes) {
@@ -1513,7 +1512,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
1513
1512
  const { skipInitialization, offlineMode = false } = stateOptions;
1514
1513
 
1515
1514
  for (const channelState of channelsFromApi) {
1516
- this._addChannelConfig(channelState);
1515
+ this._addChannelConfig(channelState.channel);
1517
1516
  }
1518
1517
 
1519
1518
  const channels: Channel<StreamChatGenerics>[] = [];
@@ -1670,8 +1669,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
1670
1669
  });
1671
1670
  }
1672
1671
 
1673
- _addChannelConfig(channelState: ChannelAPIResponse<StreamChatGenerics>) {
1674
- this.configs[channelState.channel.type] = channelState.channel.config;
1672
+ _addChannelConfig({ cid, config }: ChannelResponse<StreamChatGenerics>) {
1673
+ this.configs[cid] = config;
1675
1674
  }
1676
1675
 
1677
1676
  /**
@@ -2480,6 +2479,11 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2480
2479
  ): AxiosRequestConfig {
2481
2480
  const token = this._getToken();
2482
2481
  const authorization = token ? { Authorization: token } : undefined;
2482
+ let signal: AbortSignal | null = null;
2483
+ if (this.nextRequestAbortController !== null) {
2484
+ signal = this.nextRequestAbortController.signal;
2485
+ this.nextRequestAbortController = null;
2486
+ }
2483
2487
 
2484
2488
  if (!options.headers?.['x-client-request-id']) {
2485
2489
  options.headers = {
@@ -2501,6 +2505,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2501
2505
  'X-Stream-Client': this.getUserAgent(),
2502
2506
  ...options.headers,
2503
2507
  },
2508
+ ...(signal ? { signal } : {}),
2504
2509
  ...options.config,
2505
2510
  };
2506
2511
  }
@@ -3030,4 +3035,11 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3030
3035
  async listPushProviders() {
3031
3036
  return await this.get<APIResponse & PushProviderListResponse>(this.baseURL + `/push_providers`);
3032
3037
  }
3038
+
3039
+ /**
3040
+ * creates an abort controller that will be used by the next HTTP Request.
3041
+ */
3042
+ createAbortControllerForNextRequest() {
3043
+ return (this.nextRequestAbortController = new AbortController());
3044
+ }
3033
3045
  }
package/src/types.ts CHANGED
@@ -1773,9 +1773,10 @@ export type CommandVariants<StreamChatGenerics extends ExtendableGenerics = Defa
1773
1773
  | 'unmute'
1774
1774
  | StreamChatGenerics['commandType'];
1775
1775
 
1776
- export type Configs<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
1777
- [channel_type: string]: ChannelConfigWithInfo<StreamChatGenerics> | undefined;
1778
- };
1776
+ export type Configs<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = Record<
1777
+ string,
1778
+ ChannelConfigWithInfo<StreamChatGenerics> | undefined
1779
+ >;
1779
1780
 
1780
1781
  export type ConnectionOpen<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
1781
1782
  connection_id: string;
@@ -2455,38 +2456,38 @@ export type PushProviderListResponse = {
2455
2456
  };
2456
2457
 
2457
2458
  export type CreateCallOptions<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
2458
- id: String;
2459
- type: String;
2460
- options?: Object;
2459
+ id: string;
2460
+ type: string;
2461
+ options?: UR;
2461
2462
  user?: UserResponse<StreamChatGenerics> | null;
2462
2463
  user_id?: string;
2463
2464
  };
2464
2465
 
2465
2466
  export type HMSCall = {
2466
- room: String;
2467
+ room: string;
2467
2468
  };
2468
2469
 
2469
2470
  export type AgoraCall = {
2470
- channel: String;
2471
+ channel: string;
2471
2472
  };
2472
2473
 
2473
2474
  export type Call = {
2474
- id: String;
2475
- provider: String;
2475
+ id: string;
2476
+ provider: string;
2476
2477
  agora?: AgoraCall;
2477
2478
  hms?: HMSCall;
2478
2479
  };
2479
2480
 
2480
2481
  export type CreateCallResponse = APIResponse & {
2481
2482
  call: Call;
2482
- token: String;
2483
- agora_app_id?: String;
2483
+ token: string;
2484
+ agora_app_id?: string;
2484
2485
  agora_uid?: number;
2485
2486
  };
2486
2487
 
2487
2488
  export type GetCallTokenResponse = APIResponse & {
2488
- token: String;
2489
- agora_app_id?: String;
2489
+ token: string;
2490
+ agora_app_id?: string;
2490
2491
  agora_uid?: number;
2491
2492
  };
2492
2493