Skip to content

Conversation

cnderrauber
Copy link
Contributor

Add fastPublish option to establish publisher peerconnection when
joining.

Neogtiate new track without AddTrackRequest response

Add fastPublish option to establish publisher peerconnection when
joining.

Neogtiate new track without AddTrackRequest response
Copy link

changeset-bot bot commented Aug 23, 2024

🦋 Changeset detected

Latest commit: 65d1dd6

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

This PR includes changesets to release 1 package
Name Type
livekit-client 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

onError(e as Error);
} else {
throw e;
async negotiate(onError?: (e: Error) => void) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

negotiate immediately if time elapsed since last negotiation > debounce interval (100ms)

Copy link
Contributor

Choose a reason for hiding this comment

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

this optimization will then only work for a single track. If someone were to publish cam + mic at the same time, one of these would get delayed.
Wondering if we can take a different approach that would allow multiple tracks to be negotiated together without having to necessarily wait for the 100ms debounce timeout

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently, the publishTrack method doesn't know if there is another track publishing together, I think we can provide a publishTracks method for this case and make enableMicAndCamera and setTrackEnabled(sceenshare) to call the new method.

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, I should have checked for this earlier, but turns out the debounce lib we're using has this functionality built in already: https://github.com/chodorowicz/ts-debounce?tab=readme-ov-file#function-arguments

we can just pass {isImmediate: true} as an option. Then we don't have to do the conditional execution handling and can get rid of the doNegotiate declaration again

Copy link
Contributor

Choose a reason for hiding this comment

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

pushed a commit to make use of the built-in version

Copy link
Contributor

Choose a reason for hiding this comment

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

provide a publishTracks method for this case and make enableMicAndCamera and setTrackEnabled(sceenshare)

I think in practice the problem here will be that a lot of the client time is spent on actually acquiring the devices, so we're missing out on a lot of potential speed improvement.
I was thinking whether we could optimistically publish empty tracks for these APIs immediately when called and then replaceTrack once the getUserMedia promise has resolved. Not sure how to handle initial trackinfo in that regard though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The publisher's offer is limited so it is ok to do frequency negotiations, maybe worth to remove the negotiation debounce totally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The setLocalDescription failed after removing the debounce and publishing two tracks at once, looks like a condition race issue. we can address the issue in a separate PR since it is a client side change, just reduce the debounce interval to 20ms in this PR.

onError(e as Error);
} else {
throw e;
async negotiate(onError?: (e: Error) => void) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this optimization will then only work for a single track. If someone were to publish cam + mic at the same time, one of these would get delayed.
Wondering if we can take a different approach that would allow multiple tracks to be negotiated together without having to necessarily wait for the 100ms debounce timeout

Copy link
Contributor

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 81.68 KB (+0.42% 🔺)
dist/livekit-client.umd.js 87.52 KB (+0.35% 🔺)

@cnderrauber cnderrauber merged commit 10b3b68 into main Aug 28, 2024
3 checks passed
@cnderrauber cnderrauber deleted the fast_publication branch August 28, 2024 09:00
@github-actions github-actions bot mentioned this pull request Aug 28, 2024
hiroshihorie added a commit to livekit/client-sdk-swift that referenced this pull request Apr 4, 2025
When enabled by server, we don't need to wait for AddTrackRequest to
return so we can negotiate concurrently.

Reference: 
livekit/client-sdk-android#612
livekit/client-sdk-js#1228
livekit/client-sdk-js#1231
svajunas-budrys pushed a commit to svajunas-budrys/client-sdk-js that referenced this pull request Jun 17, 2025
* Speed up track publication

Add fastPublish option to establish publisher peerconnection when
joining.

Neogtiate new track without AddTrackRequest response

* changeset

* don't do parallel negotiate if no enabled codecs return

* Update src/options.ts

Co-authored-by: lukasIO <mail@lukasseiler.de>

* negotiate error

* use isImmediate option of ts-debounce

* Use fastPublish option in JoinResponse

Also reduce the negotiate debounce interval

* Update protocol dependency

---------

Co-authored-by: lukasIO <mail@lukasseiler.de>
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