@stream-io/video-client 1.40.1 → 1.40.2

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.
@@ -1,5 +1,5 @@
1
1
  import { Dispatcher, IceTrickleBuffer } from './rtc';
2
- import { JoinRequest, JoinResponse } from './gen/video/sfu/event/events';
2
+ import { Error as SfuErrorEvent, JoinRequest, JoinResponse } from './gen/video/sfu/event/events';
3
3
  import { ICERestartRequest, SendAnswerRequest, SendStatsRequest, SetPublisherRequest, TrackMuteState, TrackSubscriptionDetails } from './gen/video/sfu/signal_rpc/signal';
4
4
  import { ICETrickle } from './gen/video/sfu/models/models';
5
5
  import { StreamClient } from './coordinator/connection/client';
@@ -170,3 +170,8 @@ export declare class StreamSfuClient {
170
170
  private keepAlive;
171
171
  private scheduleConnectionCheck;
172
172
  }
173
+ export declare class SfuJoinError extends Error {
174
+ errorEvent: SfuErrorEvent;
175
+ unrecoverable: boolean;
176
+ constructor(event: SfuErrorEvent);
177
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stream-io/video-client",
3
- "version": "1.40.1",
3
+ "version": "1.40.2",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.es.js",
6
6
  "browser": "dist/index.browser.es.js",
package/src/Call.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { StreamSfuClient } from './StreamSfuClient';
1
+ import { SfuJoinError, StreamSfuClient } from './StreamSfuClient';
2
2
  import {
3
3
  BasePeerConnectionOpts,
4
4
  Dispatcher,
@@ -908,7 +908,10 @@ export class Call {
908
908
  break;
909
909
  } catch (err) {
910
910
  this.logger.warn(`Failed to join call (${attempt})`, this.cid);
911
- if (err instanceof ErrorFromResponse && err.unrecoverable) {
911
+ if (
912
+ (err instanceof ErrorFromResponse && err.unrecoverable) ||
913
+ (err instanceof SfuJoinError && err.unrecoverable)
914
+ ) {
912
915
  // if the error is unrecoverable, we should not retry as that signals
913
916
  // that connectivity is good, but the coordinator doesn't allow the user
914
917
  // to join the call due to some reason (e.g., ended call, expired token...)
@@ -14,6 +14,7 @@ import {
14
14
  SfuEventKinds,
15
15
  } from './rtc';
16
16
  import {
17
+ Error as SfuErrorEvent,
17
18
  JoinRequest,
18
19
  JoinResponse,
19
20
  SfuRequest,
@@ -26,7 +27,10 @@ import {
26
27
  TrackMuteState,
27
28
  TrackSubscriptionDetails,
28
29
  } from './gen/video/sfu/signal_rpc/signal';
29
- import { ICETrickle } from './gen/video/sfu/models/models';
30
+ import {
31
+ ICETrickle,
32
+ WebsocketReconnectStrategy,
33
+ } from './gen/video/sfu/models/models';
30
34
  import { StreamClient } from './coordinator/connection/client';
31
35
  import { generateUUIDv4 } from './coordinator/connection/utils';
32
36
  import { Credentials } from './gen/coordinator';
@@ -537,15 +541,27 @@ export class StreamSfuClient {
537
541
  const current = this.joinResponseTask;
538
542
 
539
543
  let timeoutId: NodeJS.Timeout | undefined = undefined;
544
+ const unsubscribeJoinErrorEvents = this.dispatcher.on('error', (event) => {
545
+ const { error, reconnectStrategy } = event;
546
+ if (!error) return;
547
+ if (reconnectStrategy === WebsocketReconnectStrategy.DISCONNECT) {
548
+ clearTimeout(timeoutId);
549
+ unsubscribe?.();
550
+ unsubscribeJoinErrorEvents();
551
+ current.reject(new SfuJoinError(event));
552
+ }
553
+ });
540
554
  const unsubscribe = this.dispatcher.on('joinResponse', (joinResponse) => {
541
555
  clearTimeout(timeoutId);
542
556
  unsubscribe();
557
+ unsubscribeJoinErrorEvents();
543
558
  this.keepAlive();
544
559
  current.resolve(joinResponse);
545
560
  });
546
561
 
547
562
  timeoutId = setTimeout(() => {
548
563
  unsubscribe();
564
+ unsubscribeJoinErrorEvents();
549
565
  const message = `Waiting for "joinResponse" has timed out after ${this.joinResponseTimeout}ms`;
550
566
  this.tracer?.trace('joinRequestTimeout', message);
551
567
  current.reject(new Error(message));
@@ -631,3 +647,15 @@ export class StreamSfuClient {
631
647
  }, this.unhealthyTimeoutInMs);
632
648
  };
633
649
  }
650
+
651
+ export class SfuJoinError extends Error {
652
+ errorEvent: SfuErrorEvent;
653
+ unrecoverable: boolean;
654
+
655
+ constructor(event: SfuErrorEvent) {
656
+ super(event.error?.message || 'Join Error');
657
+ this.errorEvent = event;
658
+ this.unrecoverable =
659
+ event.reconnectStrategy === WebsocketReconnectStrategy.DISCONNECT;
660
+ }
661
+ }