Skip to content

Send publisher offer with join request to accelerate connection#1846

Open
cnderrauber wants to merge 3 commits intomainfrom
join_offer
Open

Send publisher offer with join request to accelerate connection#1846
cnderrauber wants to merge 3 commits intomainfrom
join_offer

Conversation

@cnderrauber
Copy link
Copy Markdown
Contributor

Also create 3 a/v media sections to receive auto subscribed media

Also create 3 a/v media sections to receive auto subscribed media
@cnderrauber cnderrauber requested review from boks1971 and lukasIO March 23, 2026 02:09
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 23, 2026

⚠️ No Changeset found

Latest commit: 627d1ff

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

Copy link
Copy Markdown
Contributor

@boks1971 boks1971 left a comment

Choose a reason for hiding this comment

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

LGTM! But would be good to get another pair of 👀 . Lukas is out this week. So maybe wait till merging this?

'join_request',
btoa(String.fromCharCode(...wrappedBytes))
.replace(/\+/g, '-')
.replace(/\//g, '_'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is this replacing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Browser complains invalid code in btoa(...), copliot said those char code are invalid in url encoding and fix it with the replace, need @lukasIO to confirm it is ok.

Copy link
Copy Markdown
Contributor

@lukasIO lukasIO Mar 23, 2026

Choose a reason for hiding this comment

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

we shouldn't need these replacers if we keep the TextDecoder path from before.

fromCharCode interprets as UTF-16, but we probably want UTF-8.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Get error Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range. if use btoa(new TextDecoder('utf-8').decode(wrappedBytes))

Copy link
Copy Markdown
Contributor

@lukasIO lukasIO Mar 23, 2026

Choose a reason for hiding this comment

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

Ah, I see. Sorry for the confusion. the second example here https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa#unicode_strings uses TextEncoder first and then String.fromCodePoint before passing it to btoa

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My comments were wrong, the underlying issue is that btoa creates plain base64 but we need base64url encoding.

For this to work reliably we need to add a third replacer to strip the padding at the end, see https://stackoverflow.com/a/78178053

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the server complains cannot decode base64 ... again if I use the third replace: bytesToBase64(wrappedBytes).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok, not sure why this is, but at this point I'm out of ideas and am inclined to just accept this as is as long as it works.

this.pendingInitialOffer = { sdp: offer.sdp, type: offer.type };
const sdpParsed = parse(offer.sdp ?? '');
sdpParsed.media.forEach((media) => {
ensureIPAddrMatchVersion(media);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To make sure server receives same offer as client

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Got it. Thank you. I thought pendingInitialOffer generated here will already have the changes in-place and when it is read in answer path, it should have the changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The setMungedSDP in answer handle has a fallback path that use original sdp again if munged sdp is invalid(return error in setLocalDescription), ensureIPAddrMatchVersion shoud not make sdp invalid in theory but still keep the original sdp here to get a consistent behavior.


if (!supportOptionalDatachannel(joinResponse.serverInfo?.protocol)) {
this.createDataChannels();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Has this moved to some other place or not needed any more?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is imported when I implement optional datachannel in server side to make sure it will not break function when connect to a old server version. It is not needed now.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 23, 2026

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 87.11 KB (+0.43% 🔺)
dist/livekit-client.umd.js 97.83 KB (+0.58% 🔺)

}
const joinRequestBytes = joinRequest.toBinary();
const compressedBytes = await (async () => {
const stream = new CompressionStream('gzip');
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added 627d1ff

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.

3 participants