Skip to content

Joao/fix reconnection after verto invite only #1227

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

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

jpsantosbh
Copy link
Collaborator

Description

This is a slip from #1216 to simplify the revision
image

This is handle case 2

Type of change

  • Internal refactoring
  • Bug fix (bugfix - non-breaking)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Code snippets

In case of new feature or breaking changes, please include code snippets.

Copy link

changeset-bot bot commented May 30, 2025

🦋 Changeset detected

Latest commit: 9519fc2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@signalwire/webrtc Minor
@signalwire/core Minor
@signalwire/js Minor
@sw-internal/e2e-js Patch
@signalwire/realtime-api Patch
@signalwire/web-api Patch

Not sure what this means? Click here to learn what changesets are.

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

@jpsantosbh jpsantosbh requested a review from iAmmar7 May 30, 2025 12:32
@iAmmar7
Copy link
Member

iAmmar7 commented Jun 3, 2025

Does this PR need to target the base branch or the main branch?

Copy link
Member

@iAmmar7 iAmmar7 left a comment

Choose a reason for hiding this comment

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

I would look into the flow of not attaching any workers before receiving the verto.invite response. It might help us reducing all these complexities.

However, since this is urgent, I would suggest fixing the CI problems so that we can merge the PR.

Please look into my double retry logic comment for the verto invite.

video = true
negotiateVideo = true
}
const queryParams = new URLSearchParams(query)
Copy link
Member

Choose a reason for hiding this comment

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

Please run the prettier

this.logger.error('Invite error', error)
reject(error)
}
return asyncRetry({
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the retry logic should be touching the internal methods/or API calls. This will make the SDK inconsistent, and it also does not care about developer-passed params, which means the developer can not control the retry specifically for the verto.invite.

Copy link
Member

Choose a reason for hiding this comment

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

Also, I am confused. The global retry will also retry this API? Because this will in the end call the verto.invite, which will trigger the execute, and execute has a global retry logic. So, is this API nested under two retry methods?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The global retry doesn't retry verto.invites anymore, let it be handled here...
The verto.invite is a special case, and this is the main reason users are being disconnected from calls ATM.

In a nutshell, the SDK can't replay a verto.invite, it's to "execute" a new one using a new RTCPeer, or just after connecting, the call will disconnect for various reasons.

We may find other RPC with the same characteristics, but this PR only focuses on the verto.invite request.

return asyncRetry({
asyncCallable: async () => {
return new Promise(async (resolve, reject) => {
await this._waitUntilSessionAuthorized()
Copy link
Member

Choose a reason for hiding this comment

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

How do you think the user can call this API if the session is not authorized? This is already a part of the connect logic. If that does not happen, the user can't call this API. If that happens, then do we need to wait here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not the user calling it, but he next scheduled retry, which is normally faster than the authentication.
So this Retry usage/implementation needs to handle that, or it's going to fail again.

@@ -794,7 +844,7 @@ export class BaseConnection<
}

/** @internal */
onLocalSDPReady(rtcPeer: RTCPeer<EventTypes>) {
async onLocalSDPReady(rtcPeer: RTCPeer<EventTypes>) {
Copy link
Member

Choose a reason for hiding this comment

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

This is not an async method

Suggested change
async onLocalSDPReady(rtcPeer: RTCPeer<EventTypes>) {
onLocalSDPReady(rtcPeer: RTCPeer<EventTypes>) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

async is not required here, but the method returns Promises, and since the return is being inferred,
Having the async act as a reminder for us, reading the code the the method is an async execution.

this.logger.debug('Invite response', response)

this.resuming = false
} catch (error) {
this.setState('hangup')
this.setState('hangup')
Copy link
Member

Choose a reason for hiding this comment

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

run prettier please


getLogger().debug('promoteDemoteWorker:', action.type, action.payload)
getLogger().debug('promoteDemoteWorker:', action.type, action.payload)
Copy link
Member

Choose a reason for hiding this comment

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

Run the prettier, please. I don't understand the changes here.

Comment on lines +952 to +955
if (this.state === 'requesting') {
// The Server Created the call, and now is trying to connect us to the destination
this.setState('trying')
}
Copy link
Member

Choose a reason for hiding this comment

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

What's the point? Where are you using this trying state? The SDK is already setting the state to requesting when the invite begins, and it only sets the state to active when verto.answer is received. Please check the vertoEventWorker code.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

trying is a well-known state in a call setup.
https://github.com/signalwire/signalwire-js/blob/main/packages/core/src/utils/interfaces.ts#L276

The SDK should be in the requesting state only until the request is confirmed by the server.
After the successful request, the state should now be trying and later after the verto.answer active.

This makes more sense in 1:1 calls, supported by the CF SDK. I believe that's why it was missing in the Video SDK.

@jpsantosbh
Copy link
Collaborator Author

changing the base on this one too

@jpsantosbh jpsantosbh changed the base branch from main to joao/fix_reconnections June 4, 2025 15:43
@jpsantosbh jpsantosbh marked this pull request as draft June 4, 2025 15:43
Base automatically changed from joao/fix_reconnections to main June 11, 2025 16:40
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