Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: emit an event on initial connection failed (#45) #46

Merged
merged 1 commit into from
Jun 14, 2023

Conversation

nigelsim
Copy link
Contributor

This addresses the issue raised in #45 by emitting an initial-connection-failed event if the WHEP request fails. It also properly cleans up the peer in this situation.

This allows you to do something like the following in your client code, giving good control over when to retry, and when to alert the user:

class SomeAngularComponent {
  connectionAttemptsRemaining = 3;

  private whepUrl?: string;

  async ngOnInit() {
    this.client = new WebRTCPlayer({
      video: this.video.nativeElement,
      type: 'whep',
    });

    this.client.on('initial-connection-failed', () => this.maybeRetryConnection());
    await this.client.load(new URL(this.whepUrl));
  }

  private maybeRetryConnection() {
    if (this.connectionAttemptsRemaining > 0) {
      this.client!.load(new URL(this.whepUrl!));
      this.connectionAttemptsRemaining--;
    } else {
      // Alert the user
    }
  }
}

Copy link
Contributor

@birme birme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good. Many thanks for the contribution!

@birme birme linked an issue Jun 14, 2023 that may be closed by this pull request
@birme birme merged commit cdaa029 into Eyevinn:main Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detecting failed initial connection
2 participants