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

fix: webrtc rpc not working if sender and receiver is created after rpc arrivered #200

Merged

Conversation

giangndm
Copy link
Contributor

@giangndm giangndm commented Jan 30, 2024

Summary by CodeRabbit

  • New Features
    • Introduced an RPC wait queue in the WebRTC transport layer to enhance handling and tracking of remote procedure calls.
  • Refactor
    • Updated internal WebRTC transport mechanisms for improved RPC management.
  • Tests
    • Modified tests to align with the new RPC wait queue functionality and internal changes.

@giangndm giangndm marked this pull request as ready for review January 30, 2024 17:48
Copy link

coderabbitai bot commented Jan 30, 2024

Important

Auto Review Skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The update introduces a new module rpc_wait_queue in the WebRTC transport layer, enhancing the management of RPC events with a focus on wait queues. It integrates this functionality by adding relevant fields to the TransportWebrtcInternal struct and refining the handling of incoming RPCs, including adjustments in log messages and test updates. This modular approach aims to streamline the tracking and retrieval of events associated with specific RPC tracks.

Changes

Files Changes
.../webrtc/src/transport.rs Added the rpc_wait_queue module.
.../webrtc/src/transport/internal.rs Added local_wait_rpc, remote_wait_rpc fields; updated log messages and RPC handling.
.../webrtc/src/transport/rpc_wait_queue.rs Introduced a new module for a generic RPC wait queue using a HashMap.

🐰✨
In the land of code where the data bytes roam,
A new queue was born, in the WebRTC home.
With a hop and a skip, events neatly array,
"To manage and track," the rabbit did say. 🌟

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8b8ca23 and 0f5a19e.
Files selected for processing (3)
  • transports/webrtc/src/transport.rs (1 hunks)
  • transports/webrtc/src/transport/internal.rs (8 hunks)
  • transports/webrtc/src/transport/rpc_wait_queue.rs (1 hunks)
Additional comments: 11
transports/webrtc/src/transport/rpc_wait_queue.rs (3)
  • 3-5: The RpcWaitQueue struct is well-defined with a clear purpose, utilizing a HashMap to queue RPC events by track.
  • 7-11: The implementation of the Default trait for RpcWaitQueue is correct and idiomatic, ensuring an empty HashMap is initialized for new instances.
  • 22-24: The take method correctly retrieves and removes the vector of events for a given track, returning an empty vector if the track does not exist.
transports/webrtc/src/transport.rs (1)
  • 34-34: The addition of the rpc_wait_queue module is correctly implemented, ensuring the new functionality is accessible within the transport module.
transports/webrtc/src/transport/internal.rs (7)
  • 30-30: The import of RpcWaitQueue is correctly added to support the new functionality within TransportWebrtcInternal.
  • 76-78: The addition of local_wait_rpc and remote_wait_rpc fields to the TransportWebrtcInternal struct is correctly implemented, aligning with the PR objectives to handle RPC events for tracks that are not yet added.
  • 101-102: Initialization of local_wait_rpc and remote_wait_rpc with Default::default() is correct, ensuring these fields are properly initialized when a new instance of TransportWebrtcInternal is created.
  • 250-252: The logic to queue RPC events for local tracks not yet added is correctly implemented. This ensures that RPC events are not lost and can be processed once the track is available.
  • 262-264: Similarly, the logic to queue RPC events for remote tracks not yet added is correctly implemented, ensuring that these events are handled appropriately once the track is available.
  • 299-307: The process of handling queued RPC events for remote tracks upon their addition is correctly implemented, ensuring that any queued events are processed in the correct order.
  • 319-328: The handling of queued RPC events for local tracks upon their addition is correctly implemented, ensuring that any queued events are processed appropriately.

Comment on lines +14 to +20
pub fn put(&mut self, track: &str, e: E) {
if let Some(track) = self.tracks.get_mut(track) {
track.push(e);
} else {
self.tracks.insert(track.to_string(), vec![e]);
}
}
Copy link

Choose a reason for hiding this comment

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

The put method correctly handles both existing and new tracks, ensuring that RPC events are queued appropriately. However, consider using entry API for a more concise implementation.

self.tracks.entry(track.to_string()).or_insert_with(Vec::new).push(e);

@giangndm giangndm merged commit 5e56bfd into 8xFF:master Jan 30, 2024
7 checks passed
@github-actions github-actions bot mentioned this pull request Jan 30, 2024
@giangndm giangndm deleted the fix-webrtc-rpc-not-working-lazy-sender-receiver branch June 6, 2024 00:44
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.

None yet

1 participant