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

Ensure publisher connection is reconnected if needed #874

Closed
wants to merge 6 commits into from

Conversation

lukasIO
Copy link
Contributor

@lukasIO lukasIO commented Sep 14, 2023

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Sep 14, 2023

⚠️ No Changeset found

Latest commit: 67013ee

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 76.55 KB (+0.07% 🔺)
dist/livekit-client.umd.js 82.01 KB (+0.08% 🔺)

@lukasIO lukasIO requested a review from davidzhao September 14, 2023 15:50
this.subscriberPrimary = joinResponse.subscriberPrimary;
if (!this.publisher) {
this.configure(joinResponse);
}

// create offer
if (!this.subscriberPrimary) {
if (!this.subscriberPrimary || this.hasPublished) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is needed to re-establish publisher connection on full reconnects

@@ -1092,11 +1105,10 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
// this means we'd have to check its status manually and update address
// manually
now - startTime > minReconnectWait &&
this.primaryPC?.connectionState === 'connected'
this.primaryPC?.connectionState === 'connected' &&
(!this.hasPublished || this.publisher?.pc.connectionState === 'connected')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we only set it to connected if - in case we need it - the publisher connection is also connected

if (shouldEmit) {
const initialFullConnection =
(this.pcState === PCState.New && !this.hasPublished) ||
this.publisher?.pc.connectionState === 'connected';
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this is right.. if publisher is connected before the subscriber in the reconnect case.. it should not emit this event.

I think the idea is that this would only emit event in case it's the initial connection, and reconnect would be checking its state/events in either the resume or full reconnect paths.

Copy link
Member

Choose a reason for hiding this comment

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

what is this change attempting to fix? it seems to increase complexity as we try to coordinate both peer connection states.

Copy link
Contributor Author

@lukasIO lukasIO Sep 15, 2023

Choose a reason for hiding this comment

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

you're right, we'd have to make sure not to emit this in the reconnect case.

the idea is to have a single understanding of what a connected state is. If subscriberPrimary but we also publish something, the connected state only happens if both peer connections are connected

this.setAndEmitConnectionState(ConnectionState.Connected);
this.emit(RoomEvent.Reconnected);
this.registerConnectionReconcile();
// only set as connected if _only_ the signal connection had been severed
Copy link
Member

Choose a reason for hiding this comment

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

not understanding the comment. it seems to be flipping it back only when PC transport have been restored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe bad wording.
At this point we would only want to emit Reconnected if the transports still work. In case the transport don't we would wait for them to re-establish until a Reconnected event is fired.

@lukasIO
Copy link
Contributor Author

lukasIO commented Sep 15, 2023

closing in favor of #875

@lukasIO lukasIO closed this Sep 15, 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.

2 participants