Skip to content
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

feat: add cluster metadata publish and subscribe options: peer and track info #260

Merged
merged 5 commits into from
Apr 23, 2024

Conversation

giangndm
Copy link
Contributor

@giangndm giangndm commented Apr 23, 2024

Pull Request

Description

This PR implement cluster metadata feature

Related Issue

If this pull request is related to any issue, please mention it here.

Checklist

  • I have tested the changes locally.
  • I have reviewed the code changes.
  • I have updated the documentation, if necessary.
  • I have added appropriate tests, if applicable.

Screenshots

If applicable, add screenshots to help explain the changes made.

Additional Notes

Add any additional notes or context about the pull request here.

Summary by CodeRabbit

  • New Features

    • Enhanced room and peer management functionalities across the platform.
    • New event handling for peer join and leave actions.
    • Improved error messaging for track-related issues.
    • Added new structs and methods related to room and peer information.
  • Refactor

    • Updated method parameters and internal logic for better handling of media tracks and peer metadata.
    • Renamed key identifiers to align with new naming conventions.
    • Adjusted data structures and logic to fix issues related to media scaling and packet handling.

@giangndm giangndm marked this pull request as draft April 23, 2024 17:16
Copy link

coderabbitai bot commented Apr 23, 2024

Walkthrough

Walkthrough

The recent updates focus on enhancing room and peer interaction functionalities within the media core system. Key changes include the introduction of new enums and parameters like PeerMeta, RoomInfoPublish, and RoomInfoSubscribe, and modifications to error handling and event management. These adjustments aim to improve the flexibility and robustness of peer connections and track events across the system.

Changes

Files Changes
.../cluster.rs, .../endpoint.rs, .../protocol/src/endpoint.rs, .../transport_webrtc/src/transport/whep.rs, .../transport_webrtc/src/transport/whip.rs Introduced PeerMeta, RoomInfoPublish, RoomInfoSubscribe; added new peer and room management functionalities.
.../cluster/room.rs, .../cluster/room/channel_pub.rs, .../cluster/room/channel_sub.rs Updated methods to use gen_channel_id for channel ID generation; added meta parameter in ClusterEndpointControl::Join.
.../cluster/room/metadata.rs, .../endpoint/internal.rs Enhanced event handling and data structures; added new parameters and enum variants for better peer tracking.
.../endpoint/internal/local_track.rs, .../errors.rs Updated error messages and types for improved clarity and specificity.
.../protocol/src/media.rs Streamlined MediaKind, MediaScaling, and MediaPacket enums; removed outdated structures.

🐇✨🌟
In the realm of code, where the bits align,
A rabbit hopped through, making changes so fine.
With a twitch of a nose, and a flick of an ear,
New features sprout, as old bugs disappear!
Hooray to the team, on this bright, code-filled day!
🌟✨🐇


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6dba8e6 and 162411f.
Files selected for processing (4)
  • packages/media_core/src/cluster/room/channel_pub.rs (1 hunks)
  • packages/media_core/src/cluster/room/channel_sub.rs (2 hunks)
  • packages/media_core/src/cluster/room/metadata.rs (1 hunks)
  • packages/transport_webrtc/src/transport/whep.rs (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/transport_webrtc/src/transport/whep.rs
Additional Context Used
GitHub Check Runs (2)
codecov/patch success (30)

packages/media_core/src/cluster/room/channel_pub.rs: [warning] 49-49: packages/media_core/src/cluster/room/channel_pub.rs#L49
Added line #L49 was not covered by tests


packages/media_core/src/cluster/room/channel_pub.rs: [warning] 55-55: packages/media_core/src/cluster/room/channel_pub.rs#L55
Added line #L55 was not covered by tests


packages/media_core/src/cluster/room/channel_sub.rs: [warning] 52-52: packages/media_core/src/cluster/room/channel_sub.rs#L52
Added line #L52 was not covered by tests


packages/media_core/src/cluster/room/channel_sub.rs: [warning] 62-63: packages/media_core/src/cluster/room/channel_sub.rs#L62-L63
Added lines #L62 - L63 were not covered by tests


packages/media_core/src/cluster/room/channel_sub.rs: [warning] 69-69: packages/media_core/src/cluster/room/channel_sub.rs#L69
Added line #L69 was not covered by tests


packages/media_core/src/cluster/room/metadata.rs: [warning] 137-137: packages/media_core/src/cluster/room/metadata.rs#L137
Added line #L137 was not covered by tests


packages/media_core/src/cluster/room/metadata.rs: [warning] 157-157: packages/media_core/src/cluster/room/metadata.rs#L157
Added line #L157 was not covered by tests


packages/media_core/src/cluster/room/metadata.rs: [warning] 183-183: packages/media_core/src/cluster/room/metadata.rs#L183
Added line #L183 was not covered by tests


packages/media_core/src/cluster/room/metadata.rs: [warning] 190-190: packages/media_core/src/cluster/room/metadata.rs#L190
Added line #L190 was not covered by tests


packages/media_core/src/cluster/room/metadata.rs: [warning] 218-218: packages/media_core/src/cluster/room/metadata.rs#L218
Added line #L218 was not covered by tests


packages/media_core/src/cluster/room/metadata.rs: [warning] 232-232: packages/media_core/src/cluster/room/metadata.rs#L232
Added line #L232 was not covered by tests


packages/media_core/src/cluster/room/metadata.rs: [warning] 272-272: packages/media_core/src/cluster/room/metadata.rs#L272
Added line #L272 was not covered by tests


packages/media_core/src/cluster/room/metadata.rs: [warning] 278-278: packages/media_core/src/cluster/room/metadata.rs#L278
Added line #L278 was not covered by tests


packages/media_core/src/cluster/room/metadata.rs: [warning] 332-332: packages/media_core/src/cluster/room/metadata.rs#L332
Added line #L332 was not covered by tests


packages/media_core/src/cluster/room/metadata.rs: [warning] 347-347: packages/media_core/src/cluster/room/metadata.rs#L347
Added line #L347 was not covered by tests


packages/media_core/src/cluster/room/metadata.rs: [warning] 371-371: packages/media_core/src/cluster/room/metadata.rs#L371
Added line #L371 was not covered by tests


packages/media_core/src/cluster/room/metadata.rs: [warning] 382-382: packages/media_core/src/cluster/room/metadata.rs#L382
Added line #L382 was not covered by tests

clippy success (3)

packages/media_core/src/cluster/room/metadata.rs: [warning] 179-184:
this if statement can be collapsed


packages/media_core/src/cluster/room/metadata.rs: [warning] 186-191:
this if statement can be collapsed

Additional comments not posted (9)
packages/media_core/src/cluster/room/channel_pub.rs (2)

49-49: The new case for handling KeyFrameRequest feedback is not covered by tests.

Please ensure to add unit tests covering this new functionality to maintain robustness and prevent regressions.


55-55: The change to use gen_channel_id in on_track_publish is not covered by tests.

Please add appropriate unit tests to verify the correct generation of channel_id using the new method.

packages/media_core/src/cluster/room/channel_sub.rs (3)

52-52: The addition of the new output event for LocalTrack in on_channel_relay_changed is not covered by tests.

Please ensure to add unit tests covering this new functionality to maintain robustness and prevent regressions.


62-63: The addition of new output events for LocalTrack in on_channel_data is not covered by tests.

Please add appropriate unit tests to verify the correct handling of incoming channel data and the generation of these events.


69-69: The change to use gen_channel_id in on_track_subscribe is not covered by tests.

Please add appropriate unit tests to verify the correct generation of channel_id using the new method.

packages/media_core/src/cluster/room/metadata.rs (4)

137-137: The new subscription logic in on_join for peers map is not covered by tests.

Please ensure to add unit tests covering this new functionality to maintain robustness and prevent regressions.


157-157: The new subscription logic in on_join for tracks map is not covered by tests.

Please ensure to add unit tests covering this new functionality to maintain robustness and prevent regressions.


183-183: The new unsubscription logic in on_leave for peers map is not covered by tests.

Please ensure to add unit tests covering this new functionality to maintain robustness and prevent regressions.


190-190: The new unsubscription logic in on_leave for tracks map is not covered by tests.

Please ensure to add unit tests covering this new functionality to maintain robustness and prevent regressions.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Comment on lines +179 to +184
if self.peers_map_subscribers.remove(&owner).is_some() {
if self.peers_map_subscribers.is_empty() {
log::info!("[ClusterRoom {}] last peer unsub peers map => unsubscribe", self.room);
self.queue.push_back(Output::Kv(dht_kv::Control::MapCmd(self.peers_map, MapControl::Unsub)));
}
}

Check warning

Code scanning / clippy

this if statement can be collapsed Warning

this if statement can be collapsed
Comment on lines +186 to +191
if self.tracks_map_subscribers.remove(&owner).is_some() {
if self.tracks_map_subscribers.is_empty() {
log::info!("[ClusterRoom {}] last peer unsub tracks map => unsubscribe", self.room);
self.queue.push_back(Output::Kv(dht_kv::Control::MapCmd(self.tracks_map, MapControl::Unsub)));
}
}

Check warning

Code scanning / clippy

this if statement can be collapsed Warning

this if statement can be collapsed
@@ -215,7 +235,7 @@
None
}

fn join_room<'a>(&mut self, now: Instant, room: RoomId, peer: PeerId) -> Option<InternalOutput> {
fn join_room<'a>(&mut self, now: Instant, room: RoomId, peer: PeerId, meta: PeerMeta, publish: RoomInfoPublish, subscribe: RoomInfoSubscribe) -> Option<InternalOutput> {

Check warning

Code scanning / clippy

this lifetime isn't used in the function definition Warning

this lifetime isn't used in the function definition
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Out of diff range and nitpick comments (3)
packages/transport_webrtc/src/transport/whip.rs (1)

98-99: Consider implementing logic for handling PeerJoined and PeerLeaved events or document why they are intentionally ignored.

packages/transport_webrtc/src/transport/whep.rs (1)

104-105: Consider implementing logic for handling PeerJoined and PeerLeaved events or document why they are intentionally ignored.

packages/media_core/src/cluster/room/metadata.rs (1)

26-31: Define the PeerContainer struct more clearly.

Consider adding documentation comments to the PeerContainer struct to explain the purpose and usage of each field. This will improve code readability and maintainability.

Comment on lines +179 to +184
if self.peers_map_subscribers.remove(&owner).is_some() {
if self.peers_map_subscribers.is_empty() {
log::info!("[ClusterRoom {}] last peer unsub peers map => unsubscribe", self.room);
self.queue.push_back(Output::Kv(dht_kv::Control::MapCmd(self.peers_map, MapControl::Unsub)));
}
}
Copy link

Choose a reason for hiding this comment

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

Simplify the if statement.

-        if self.peers_map_subscribers.remove(&owner).is_some() {
-            if self.peers_map_subscribers.is_empty() {
+        if self.peers_map_subscribers.remove(&owner).is_some() && self.peers_map_subscribers.is_empty() {

This change collapses nested if statements into a single statement, improving readability.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if self.peers_map_subscribers.remove(&owner).is_some() {
if self.peers_map_subscribers.is_empty() {
log::info!("[ClusterRoom {}] last peer unsub peers map => unsubscribe", self.room);
self.queue.push_back(Output::Kv(dht_kv::Control::MapCmd(self.peers_map, MapControl::Unsub)));
}
}
if self.peers_map_subscribers.remove(&owner).is_some() && self.peers_map_subscribers.is_empty() {
log::info!("[ClusterRoom {}] last peer unsub peers map => unsubscribe", self.room);
self.queue.push_back(Output::Kv(dht_kv::Control::MapCmd(self.peers_map, MapControl::Unsub)));
}

Comment on lines +186 to +191
if self.tracks_map_subscribers.remove(&owner).is_some() {
if self.tracks_map_subscribers.is_empty() {
log::info!("[ClusterRoom {}] last peer unsub tracks map => unsubscribe", self.room);
self.queue.push_back(Output::Kv(dht_kv::Control::MapCmd(self.tracks_map, MapControl::Unsub)));
}
}
Copy link

Choose a reason for hiding this comment

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

Simplify the if statement.

-        if self.tracks_map_subscribers.remove(&owner).is_some() {
-            if self.tracks_map_subscribers.is_empty() {
+        if self.tracks_map_subscribers.remove(&owner).is_some() && self.tracks_map_subscribers.is_empty() {

This change collapses nested if statements into a single statement, improving readability.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if self.tracks_map_subscribers.remove(&owner).is_some() {
if self.tracks_map_subscribers.is_empty() {
log::info!("[ClusterRoom {}] last peer unsub tracks map => unsubscribe", self.room);
self.queue.push_back(Output::Kv(dht_kv::Control::MapCmd(self.tracks_map, MapControl::Unsub)));
}
}
if self.tracks_map_subscribers.remove(&owner).is_some() && self.tracks_map_subscribers.is_empty() {
log::info!("[ClusterRoom {}] last peer unsub tracks map => unsubscribe", self.room);
self.queue.push_back(Output::Kv(dht_kv::Control::MapCmd(self.tracks_map, MapControl::Unsub)));
}

self.queue
.push_back(Output::Endpoint(vec![owner.clone()], ClusterEndpointEvent::TrackStarted(peer.clone(), name.clone(), meta.clone())));
.push_back(Output::Endpoint(vec![owner.clone()], ClusterEndpointEvent::PeerJoined(info.peer.clone(), info.meta.clone())));
Copy link

Choose a reason for hiding this comment

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

Avoid unnecessary cloning.

-                    .push_back(Output::Endpoint(vec![owner.clone()], ClusterEndpointEvent::PeerJoined(info.peer.clone(), info.meta.clone())));
+                    .push_back(Output::Endpoint(vec![owner], ClusterEndpointEvent::PeerJoined(info.peer.clone(), info.meta.clone())));

Since Owner implements the Copy trait, there's no need to use clone() here. This change avoids unnecessary cloning and improves performance.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
.push_back(Output::Endpoint(vec![owner.clone()], ClusterEndpointEvent::PeerJoined(info.peer.clone(), info.meta.clone())));
.push_back(Output::Endpoint(vec![owner], ClusterEndpointEvent::PeerJoined(info.peer.clone(), info.meta.clone())));

for (_track_key, info) in self.cluster_tracks.iter() {
//TODO avoiding duplicate same peer
self.queue.push_back(Output::Endpoint(
vec![owner.clone()],
Copy link

Choose a reason for hiding this comment

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

Avoid unnecessary cloning.

-                    vec![owner.clone()],
+                    vec![owner],

Since Owner implements the Copy trait, there's no need to use clone() here. This change avoids unnecessary cloning and improves performance.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
vec![owner.clone()],
vec![owner],

@@ -215,7 +235,7 @@
None
}

fn join_room<'a>(&mut self, now: Instant, room: RoomId, peer: PeerId) -> Option<InternalOutput> {
fn join_room<'a>(&mut self, now: Instant, room: RoomId, peer: PeerId, meta: PeerMeta, publish: RoomInfoPublish, subscribe: RoomInfoSubscribe) -> Option<InternalOutput> {
Copy link

Choose a reason for hiding this comment

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

Address the unused lifetime warning in the join_room function definition.

- fn join_room<'a>(&mut self, now: Instant, room: RoomId, peer: PeerId, meta: PeerMeta, publish: RoomInfoPublish, subscribe: RoomInfoSubscribe) -> Option<InternalOutput> {
+ fn join_room(&mut self, now: Instant, room: RoomId, peer: PeerId, meta: PeerMeta, publish: RoomInfoPublish, subscribe: RoomInfoSubscribe) -> Option<InternalOutput> {

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
fn join_room<'a>(&mut self, now: Instant, room: RoomId, peer: PeerId, meta: PeerMeta, publish: RoomInfoPublish, subscribe: RoomInfoSubscribe) -> Option<InternalOutput> {
fn join_room(&mut self, now: Instant, room: RoomId, peer: PeerId, meta: PeerMeta, publish: RoomInfoPublish, subscribe: RoomInfoSubscribe) -> Option<InternalOutput> {

Copy link

codecov bot commented Apr 23, 2024

Codecov Report

Attention: Patch coverage is 89.00929% with 71 lines in your changes are missing coverage. Please review.

Project coverage is 23.60%. Comparing base (dee58cc) to head (162411f).

Files Patch % Lines
packages/media_core/src/endpoint/internal.rs 0.00% 21 Missing ⚠️
packages/transport_webrtc/src/transport/whep.rs 0.00% 15 Missing ⚠️
packages/media_core/src/cluster/room/metadata.rs 97.83% 12 Missing ⚠️
packages/transport_webrtc/src/transport/whip.rs 0.00% 9 Missing ⚠️
...ackages/media_core/src/cluster/room/channel_sub.rs 0.00% 4 Missing ⚠️
packages/media_core/src/cluster/room.rs 0.00% 3 Missing ⚠️
...es/media_core/src/endpoint/internal/local_track.rs 0.00% 3 Missing ⚠️
...ackages/media_core/src/cluster/room/channel_pub.rs 0.00% 2 Missing ⚠️
packages/protocol/src/endpoint.rs 96.87% 1 Missing ⚠️
packages/protocol/src/media.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #260       +/-   ##
===========================================
+ Coverage    1.80%   23.60%   +21.79%     
===========================================
  Files          36       36               
  Lines        2215     2779      +564     
===========================================
+ Hits           40      656      +616     
+ Misses       2175     2123       -52     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@giangndm giangndm marked this pull request as ready for review April 23, 2024 18:08
@giangndm giangndm merged commit 9880d54 into 8xFF:master Apr 23, 2024
10 checks passed
@github-actions github-actions bot mentioned this pull request Apr 23, 2024
@giangndm giangndm deleted the feat-cluster-media branch June 6, 2024 00:44
giangndm added a commit to giangndm/8xFF-decentralized-media-server that referenced this pull request Nov 26, 2024
…ack info (8xFF#260)

* feat: add cluster metadata publish and subscribe options: peer and track info

* fixed: wrong sending media mid in whep

* test: cluster metadata tests
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.

1 participant