-
Notifications
You must be signed in to change notification settings - Fork 264
Send publisher offer with join request to accelerate connection #1846
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'livekit-client': patch | ||
| --- | ||
|
|
||
| Send publisher offer with join request to accelerate connection |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,8 @@ export default class PCTransport extends EventEmitter { | |
|
|
||
| private offerLock: Mutex; | ||
|
|
||
| private pendingInitialOffer?: RTCSessionDescriptionInit; | ||
|
|
||
| pendingCandidates: RTCIceCandidateInit[] = []; | ||
|
|
||
| restartingIce: boolean = false; | ||
|
|
@@ -163,6 +165,16 @@ export default class PCTransport extends EventEmitter { | |
| this.remoteStereoMids = stereoMids; | ||
| this.remoteNackMids = nackMids; | ||
| } else if (sd.type === 'answer') { | ||
| if (this.pendingInitialOffer) { | ||
| const initialOffer = this.pendingInitialOffer; | ||
| this.pendingInitialOffer = undefined; | ||
| const sdpParsed = parse(initialOffer.sdp ?? ''); | ||
| sdpParsed.media.forEach((media) => { | ||
| ensureIPAddrMatchVersion(media); | ||
| }); | ||
| this.log.debug('setting pending initial offer before processing answer', this.logContext); | ||
| await this.setMungedSDP(initialOffer, write(sdpParsed)); | ||
| } | ||
| const sdpParsed = parse(sd.sdp ?? ''); | ||
| sdpParsed.media.forEach((media) => { | ||
| const mid = getMidString(media.mid!); | ||
|
|
@@ -255,6 +267,31 @@ export default class PCTransport extends EventEmitter { | |
| } | ||
| }, debounceInterval); | ||
|
|
||
| async createInitialOffer() { | ||
| const unlock = await this.offerLock.lock(); | ||
| try { | ||
| if (this.pc.signalingState !== 'stable') { | ||
| this.log.warn( | ||
| 'signaling state is not stable, cannot create initial offer', | ||
| this.logContext, | ||
| ); | ||
| return; | ||
| } | ||
| const offerId = this.latestOfferId + 1; | ||
| this.latestOfferId = offerId; | ||
| const offer = await this.pc.createOffer(); | ||
| this.pendingInitialOffer = { sdp: offer.sdp, type: offer.type }; | ||
| const sdpParsed = parse(offer.sdp ?? ''); | ||
| sdpParsed.media.forEach((media) => { | ||
| ensureIPAddrMatchVersion(media); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is done when handling answer too. Is it needed in both places?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make sure server receives same offer as client
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Thank you. I thought
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| }); | ||
| offer.sdp = write(sdpParsed); | ||
| return { offer, offerId }; | ||
| } finally { | ||
| unlock(); | ||
| } | ||
| } | ||
|
|
||
| async createAndSendOffer(options?: RTCOfferOptions) { | ||
| const unlock = await this.offerLock.lock(); | ||
|
|
||
|
|
@@ -268,7 +305,10 @@ export default class PCTransport extends EventEmitter { | |
| this.restartingIce = true; | ||
| } | ||
|
|
||
| if (this._pc && this._pc.signalingState === 'have-local-offer') { | ||
| if ( | ||
| this._pc && | ||
| (this._pc.signalingState === 'have-local-offer' || this.pendingInitialOffer) | ||
| ) { | ||
| // we're waiting for the peer to accept our offer, so we'll just wait | ||
| // the only exception to this is when ICE restart is needed | ||
| const currentSD = this._pc.remoteDescription; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need feature gating here to ensure this path is only used for browsers that support compression stream: https://developer.mozilla.org/en-US/docs/Web/API/Compression_Streams_API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added 627d1ff