diff --git a/.changeset/lovely-shirts-rush.md b/.changeset/lovely-shirts-rush.md new file mode 100644 index 000000000..72b668632 --- /dev/null +++ b/.changeset/lovely-shirts-rush.md @@ -0,0 +1,5 @@ +--- +'@signalwire/webrtc': patch +--- + +Accept `requesting` as valid state when we need to send again the offer on a different node (redirect destination) diff --git a/packages/webrtc/src/BaseConnection.ts b/packages/webrtc/src/BaseConnection.ts index 707c83bee..d4163f675 100644 --- a/packages/webrtc/src/BaseConnection.ts +++ b/packages/webrtc/src/BaseConnection.ts @@ -550,9 +550,17 @@ export class BaseConnection } } - /** @internal */ + /** + * Send the `verto.invite` only if the state is either `new` or `requesting` + * - new: the first time we send out the offer. + * - requesting: we received a redirect to a different node so need to send + * again the offer with a different nodeId. + * + * @internal + */ async executeInvite(sdp: string) { - if (this.state !== 'new') { + const validStates: BaseConnectionState[] = ['new', 'requesting'] + if (!validStates.includes(this.state)) { /** * Something bad happened. Either App logic invoking * methods in a wrong order or events are not correct. @@ -561,7 +569,10 @@ export class BaseConnection `Invalid state: '${this.state}' for connection id: ${this.id}` ) } - this.setState('requesting') + // Set state to `requesting` only when `new`, otherwise keep it as `requesting`. + if (this.state === 'new') { + this.setState('requesting') + } try { const ssOpts = this.options.screenShare ? {