@stream-io/video-client 0.0.47 → 0.0.48

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.
@@ -103,7 +103,7 @@ export declare class Publisher {
103
103
  /**
104
104
  * Restarts the ICE connection and renegotiates with the SFU.
105
105
  */
106
- restartIce: () => void;
106
+ restartIce: () => Promise<void>;
107
107
  private onNegotiationNeeded;
108
108
  /**
109
109
  * Initiates a new offer/answer exchange with the currently connected SFU.
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "0.0.47";
1
+ export declare const version = "0.0.48";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stream-io/video-client",
3
- "version": "0.0.47",
3
+ "version": "0.0.48",
4
4
  "packageManager": "yarn@3.2.4",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
@@ -456,9 +456,9 @@ export class Publisher {
456
456
  /**
457
457
  * Restarts the ICE connection and renegotiates with the SFU.
458
458
  */
459
- restartIce = () => {
459
+ restartIce = async () => {
460
460
  this.logger('debug', 'Restarting ICE connection');
461
- this.pc.restartIce();
461
+ await this.negotiate({ iceRestart: true });
462
462
  };
463
463
 
464
464
  private onNegotiationNeeded = async () => {
@@ -644,13 +644,29 @@ export class Publisher {
644
644
 
645
645
  private onIceConnectionStateChange = () => {
646
646
  const state = this.pc.iceConnectionState;
647
- this.logger('debug', `ICE Connection state changed`, state);
648
- if (state === 'failed' || state === 'disconnected') {
649
- this.logger(
650
- 'warn',
651
- `ICE Connection state changed to ${state}. Attempting to restart ICE`,
652
- );
653
- this.restartIce();
647
+ this.logger('debug', `ICE Connection state changed to`, state);
648
+
649
+ if (state === 'failed') {
650
+ this.logger('warn', `Attempting to restart ICE`);
651
+ this.restartIce().catch((e) => {
652
+ this.logger('error', `ICE restart error`, e);
653
+ });
654
+ } else if (state === 'disconnected') {
655
+ // when in `disconnected` state, the browser may recover automatically,
656
+ // hence, we delay the ICE restart
657
+ this.logger('warn', `Scheduling ICE restart in 5 seconds`);
658
+ setTimeout(() => {
659
+ // check if the state is still `disconnected` or `failed`
660
+ // as the connection may have recovered (or failed) in the meantime
661
+ if (
662
+ this.pc.iceConnectionState === 'disconnected' ||
663
+ this.pc.iceConnectionState === 'failed'
664
+ ) {
665
+ this.restartIce().catch((e) => {
666
+ this.logger('error', `ICE restart error`, e);
667
+ });
668
+ }
669
+ }, 5000);
654
670
  }
655
671
  };
656
672