@stream-io/feeds-client 0.1.2 → 0.1.3

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.
@@ -3545,7 +3545,10 @@ class ApiClient {
3545
3545
  const encodedBody = requestContentType === 'multipart/form-data' ? new FormData() : body;
3546
3546
  if (requestContentType === 'multipart/form-data') {
3547
3547
  Object.keys(body).forEach((key) => {
3548
- encodedBody.append(key, body[key]);
3548
+ const value = body[key];
3549
+ if (value != null) {
3550
+ encodedBody.append(key, value);
3551
+ }
3549
3552
  });
3550
3553
  }
3551
3554
  try {
@@ -3554,8 +3557,11 @@ class ApiClient {
3554
3557
  method,
3555
3558
  headers,
3556
3559
  params: queryParams,
3557
- paramsSerializer: params => this.queryParamsStringify(params),
3560
+ paramsSerializer: (params) => this.queryParamsStringify(params),
3558
3561
  data: encodedBody,
3562
+ timeout:
3563
+ // multipart/form-data requests should not have a timeout allowing ample time for file uploads
3564
+ requestContentType === 'multipart/form-data' ? 0 : this.timeout,
3559
3565
  });
3560
3566
  const metadata = this.getRequestMetadata(client_request_id, response);
3561
3567
  return { body: response.data, metadata };
@@ -3619,9 +3625,9 @@ class ApiClient {
3619
3625
  };
3620
3626
  };
3621
3627
  this.baseUrl = options?.base_url ?? 'https://video.stream-io-api.com';
3628
+ this.timeout = options?.timeout ?? 3000;
3622
3629
  this.axiosInstance = axios.create({
3623
3630
  baseURL: this.baseUrl,
3624
- timeout: options?.timeout ?? 3000,
3625
3631
  });
3626
3632
  }
3627
3633
  get webSocketBaseUrl() {
@@ -4341,6 +4347,12 @@ class Feed extends FeedApi {
4341
4347
  };
4342
4348
  });
4343
4349
  }
4350
+ async synchronize() {
4351
+ const { last_get_or_create_request_config } = this.state.getLatestValue();
4352
+ if (last_get_or_create_request_config?.watch) {
4353
+ await this.getOrCreate(last_get_or_create_request_config);
4354
+ }
4355
+ }
4344
4356
  async getOrCreate(request) {
4345
4357
  if (this.currentState.is_loading_activities) {
4346
4358
  throw new Error('Only one getOrCreate call is allowed at a time');
@@ -4406,6 +4418,7 @@ class Feed extends FeedApi {
4406
4418
  if (!request?.following_pagination?.limit) {
4407
4419
  delete nextState.following;
4408
4420
  }
4421
+ nextState.last_get_or_create_request_config = request;
4409
4422
  return nextState;
4410
4423
  });
4411
4424
  }
@@ -4692,7 +4705,7 @@ class Feed extends FeedApi {
4692
4705
  }
4693
4706
  async getNextPage() {
4694
4707
  const currentState = this.currentState;
4695
- const response = await this.getOrCreate({
4708
+ return await this.getOrCreate({
4696
4709
  member_pagination: {
4697
4710
  limit: 0,
4698
4711
  },
@@ -4703,8 +4716,8 @@ class Feed extends FeedApi {
4703
4716
  limit: 0,
4704
4717
  },
4705
4718
  next: currentState.next,
4719
+ limit: currentState.last_get_or_create_request_config?.limit ?? 20,
4706
4720
  });
4707
- return response;
4708
4721
  }
4709
4722
  addActivity(request) {
4710
4723
  return this.feedsApi.addActivity({
@@ -5107,6 +5120,7 @@ class FeedsClient extends FeedsApi {
5107
5120
  super(apiClient);
5108
5121
  this.eventDispatcher = new EventDispatcher();
5109
5122
  this.activeFeeds = {};
5123
+ this.healthyConnectionChangedEventCount = 0;
5110
5124
  this.pollFromState = (id) => this.polls_by_id.get(id);
5111
5125
  this.connectUser = async (user, tokenProvider) => {
5112
5126
  if (this.state.getLatestValue().connectedUser !== undefined ||
@@ -5220,6 +5234,15 @@ class FeedsClient extends FeedsApi {
5220
5234
  case 'connection.changed': {
5221
5235
  const { online } = event;
5222
5236
  this.state.partialNext({ isWsConnectionHealthy: online });
5237
+ if (online) {
5238
+ this.healthyConnectionChangedEventCount++;
5239
+ // we skip the first event as we could potentially be querying twice
5240
+ if (this.healthyConnectionChangedEventCount > 1) {
5241
+ for (const activeFeed of Object.values(this.activeFeeds)) {
5242
+ activeFeed.synchronize();
5243
+ }
5244
+ }
5245
+ }
5223
5246
  break;
5224
5247
  }
5225
5248
  case 'feeds.feed.created': {