Skip to content

Automatically manage remote video track layer#77

Merged
davidzhao merged 3 commits intomainfrom
auto-layer-management
Nov 8, 2021
Merged

Automatically manage remote video track layer#77
davidzhao merged 3 commits intomainfrom
auto-layer-management

Conversation

@davidzhao
Copy link
Copy Markdown
Member

Opt-in feature for now. When enabled, the client will automatically request an appropriately sized layer that matches the attached video elements. It'll also pause the stream when the object becomes invisible, without requiring explicit management from client apps.

@jibon57
Copy link
Copy Markdown
Contributor

jibon57 commented Nov 7, 2021

Excellent job @davidzhao

Copy link
Copy Markdown
Member

@hiroshihorie hiroshihorie left a comment

Choose a reason for hiding this comment

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

👏

Comment thread src/room/track/RemoteVideoTrack.ts Outdated
// override id to parsed ID
this.sid = sid;
this.receiver = receiver;
this.intersectionObserver = new IntersectionObserver(this.handleVisibilityChanged);
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.

Instead of creating an own IntersectionObserver for each RemoteVideoTrack, it would probably be more performant to use a shared IntersectionObserver (maybe on Room level or as a singleton). I'm not sure how big the impact would be for a couple of video elements and if it's worth it, but when implementing lazy-loading where potentially hundreds of image elements get observed, the difference becomes noticable. (https://www.bennadel.com/blog/3954-intersectionobserver-api-performance-many-vs-shared-in-angular-11-0-5.htm)
The same might be true for ResizeObserver.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lukasIO this is a great insight! thanks for sharing it.

I'll modify this to use a shared instance instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

actually reading this a bit more. this is quite complicated to share an instance.. because currently it's nicely scoped to a single RemoteVideoTrack. from the post, the author wasn't sure the source of the speedup with sharing a single instance, and suspected it could be angular.

it could be that the performance bottleneck is actually the Angular template reconciliation and the number of change-detection digests.

Because of the added complexity without clear payoff, I'm going to leave it the way it is for now. We can always optimize in a future PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Though I did remove the observers when this is not in use. Just so that we are not adding unnecessary processing.

track?: RemoteTrack;

/** @internal */
autoManageVideo?: boolean;
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.

is it intended that users can change the flag also after the TrackPublication and it's corresponding MediaTrack have been created?
I'm only asking because setting the autoManageVideo option (additionally) on RemoteVideoTrack would allow to actually opt out of instantiating the observers all together (or not calling observe in attach)
Which in turn would make all the if (this.autoManageVideo) return checks in RemoteVideoPublication redundant.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this would be a room-level setting, where you couldn't change it on a track by track basis. Instead of this flag though, I'll pass down the shared observer instances and use those to determine eligibility

@davidzhao davidzhao merged commit 52924f4 into main Nov 8, 2021
@davidzhao davidzhao deleted the auto-layer-management branch November 8, 2021 06:32
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.

Excellent stuff @davidzhao . This will be magical!

coryetzkorn pushed a commit to coryetzkorn/client-sdk-js that referenced this pull request Nov 5, 2025
afgarcia86 pushed a commit to afgarcia86/client-sdk-js that referenced this pull request Mar 19, 2026
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

5 participants