Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Reconnect on network change #53

Merged
merged 4 commits into from
Jun 26, 2024
Merged

Conversation

kamil-stasiak
Copy link
Contributor

Description

This PR:

  • Introduces new events: reconnectionStarted, reconnected, reconnectionFailed
  • Exposes the ongoingReconnection status
  • Waits for all tracks to be added to RTCPeerConnection after successful reconnection
  • Removes the outdated peer already connected auth join reason

Motivation and Context

It fixes the reconnection mechanism when the user changes the network (e.g., from Wi-Fi to a hotspot).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

@kamil-stasiak kamil-stasiak marked this pull request as ready for review June 19, 2024 09:59
@@ -49,6 +49,7 @@ export class ReconnectManager<PeerMetadata, TrackMetadata> {
private reconnectTimeoutId: NodeJS.Timeout | null = null;
private reconnectFailedNotificationSend: boolean = false;
private ongoingReconnection: boolean = false;
private reconnectionStartedNotificationSend: boolean = false;

Choose a reason for hiding this comment

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

Suggested change
private reconnectionStartedNotificationSend: boolean = false;
private reconnectionStartedNotificationSent: boolean = false;

Choose a reason for hiding this comment

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

Also there are now three boolean variables like this: reconnectFailedNotificationSend and reconnectionStartedNotificationSend and ongoingReconnection
I wonder if we can merge them into one variable that keeps the current state of reconnection?

Copy link
Contributor Author

@kamil-stasiak kamil-stasiak Jun 19, 2024

Choose a reason for hiding this comment

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

I've removed these variables and introduced a simple state machine

export type ReconnectionStatus = 'reconnecting' | 'idle' | 'error';

/** Emitted when the process of reconnection starts */
reconnectionStarted: () => void;

/** Emitted when on successful reconnection */

Choose a reason for hiding this comment

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

broken english

@kamil-stasiak kamil-stasiak requested a review from graszka22 June 19, 2024 15:05
reconnected: () => void;

/** Emitted when the maximum number of reconnection retries is reached */
reconnectionFailed: () => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe sth like reconnectionRetriesLimitReached? 🤔

if (this.status === 'initialized') {
this.disconnect();
await this.disconnect();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be worth to investigate if this rule can be used to detect issues like this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general, I absolutely agree with you; we should add this rule. What's more, we should make more functions async, like connect, but I don't want to introduce such changes in this PR.

In this particular line, it's a relic of my previous attempts. The disconnect() function is not async.

};
}

public getOngoingReconnectionStatus(): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT

Suggested change
public getOngoingReconnectionStatus(): boolean {
public isReconnecting(): boolean {

Comment on lines +158 to +159
for await (const element of this.lastLocalEndpoint.tracks) {
const [_, track] = element;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to discuss this part of code, as I would like to understand something.

@kamil-stasiak kamil-stasiak requested a review from mironiasty June 20, 2024 08:51
mironiasty pushed a commit that referenced this pull request Jun 20, 2024
@kamil-stasiak kamil-stasiak merged commit e71e738 into main Jun 26, 2024
4 checks passed
@kamil-stasiak kamil-stasiak deleted the reconnect-on-network-change branch June 26, 2024 12:51
kamil-stasiak added a commit to fishjam-dev/react-client-sdk that referenced this pull request Jun 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants