Skip to content

Commit

Permalink
Fix invite with redirect destination (#545)
Browse files Browse the repository at this point in the history
* accept requesting as valid state on executeInvite

* changeset
  • Loading branch information
edolix authored May 24, 2022
1 parent 875b2bb commit 78d1aea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-shirts-rush.md
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 14 additions & 3 deletions packages/webrtc/src/BaseConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,17 @@ export class BaseConnection<EventTypes extends EventEmitter.ValidEventTypes>
}
}

/** @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.
Expand All @@ -561,7 +569,10 @@ export class BaseConnection<EventTypes extends EventEmitter.ValidEventTypes>
`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
? {
Expand Down

0 comments on commit 78d1aea

Please sign in to comment.