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

client: refactor PlyrPlayer for better typechecking #1229

Merged
merged 1 commit into from
Jan 17, 2024
Merged

Conversation

dyc3
Copy link
Owner

@dyc3 dyc3 commented Jan 17, 2024

related to #1225

Copy link
Contributor

coderabbitai bot commented Jan 17, 2024

Walkthrough

The updates involve enhancing the media player interface to support both synchronous and asynchronous control of media playback, reflecting modern browser capabilities. Additionally, the PlyrPlayer component has been streamlined by centralizing player operations within a single playerImpl object, simplifying the codebase and improving maintainability.

Changes

File Path Change Summary
.../players/OmniPlayer.vue Updated MediaPlayer interface to support synchronous/asynchronous play and pause.
.../PlyrPlayer.vue Refactored player methods into playerImpl, removed playback rate methods, and moved getCaptionsTracks into playerImpl.

🐇✨
In code, we hop and leap,
Through the async, await we peep.
Refactored with care, no more disarray,
Here's to code that's sleek, hip hooray! 🎉

    (\(\ 
    ( -.-)
o_(")(")

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.

@dyc3 dyc3 added the refactor Something needs to be reworked to improve code quality label Jan 17, 2024
Copy link

codecov bot commented Jan 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b92692d) 62.1432% compared to head (5bc6570) 61.6513%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master      #1229        +/-   ##
================================================
- Coverage   62.1432%   61.6513%   -0.4920%     
================================================
  Files           117        117                
  Lines          8445       9471      +1026     
  Branches       1156       1156                
================================================
+ Hits           5248       5839       +591     
- Misses         3197       3632       +435     

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

Copy link

cypress bot commented Jan 17, 2024

Passing run #827 ↗︎

0 71 1 0 Flakiness 0

Details:

Merge 5bc6570 into bbf671c...
Project: OpenTogetherTube Commit: 429d57f360 ℹ️
Status: Passed Duration: 02:55 💡
Started: Jan 17, 2024 2:21 PM Ended: Jan 17, 2024 2:24 PM

Review all test suite changes for PR #1229 ↗︎

Copy link
Contributor

@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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between bbf671c and 5bc6570.
Files selected for processing (2)
  • client/src/components/players/OmniPlayer.vue (2 hunks)
  • client/src/components/players/PlyrPlayer.vue (6 hunks)
Additional comments: 7
client/src/components/players/PlyrPlayer.vue (5)
  • 14-14: The import of MediaPlayerWithCaptions and MediaPlayerWithPlaybackRate from ./OmniPlayer.vue is a new addition that aligns with the refactoring of the PlyrPlayer component to use these interfaces.
  • 44-139: The player methods have been successfully refactored into the playerImpl object, which now encapsulates these methods. This change should centralize the player's functionality and improve maintainability. However, ensure that all references to these methods throughout the codebase have been updated to use playerImpl.
Verification successful

The review comment's concern about ensuring that all references to player methods throughout the codebase have been updated to use playerImpl is addressed by the design of OmniPlayer.vue. The component is intended to work with any implementation of the MediaPlayer interface, and the calls to player.value.methodName() are appropriate as long as the player instance conforms to this interface. There is no evidence from the provided context that player.value specifically refers to an instance of PlyrPlayer.vue that would necessitate accessing methods through playerImpl. Therefore, the review comment does not apply to the references in OmniPlayer.vue.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any direct references to the old player methods that should now be accessed through playerImpl.
rg --type ts 'play\(\)|pause\(\)|setVolume\(|getPosition\(\)|setPosition\(|isCaptionsSupported\(\)|setCaptionsEnabled\(|isCaptionsEnabled\(\)|getCaptionsTracks\(\)|setCaptionsTrack\('

Length of output: 652



Script:

#!/bin/bash
# Search for any direct references to the old player methods within Vue component files in the client directory.
rg --type ts --glob '*.vue' 'play\(\)|pause\(\)|setVolume\(|getPosition\(\)|setPosition\(|isCaptionsSupported\(\)|setCaptionsEnabled\(|isCaptionsEnabled\(\)|getCaptionsTracks\(\)|setCaptionsTrack\(' client/src/components

Length of output: 9903



Script:

#!/bin/bash
# Check a sample of method references in OmniPlayer.vue to see if they are accessed through playerImpl or directly.
rg --type ts --glob 'OmniPlayer.vue' 'play\(\)|pause\(\)|setVolume\(|getPosition\(\)|setPosition\(|isCaptionsSupported\(\)|setCaptionsEnabled\(|isCaptionsEnabled\(\)|getCaptionsTracks\(\)|setCaptionsTrack\(' client/src/components/players

Length of output: 3225



Script:

#!/bin/bash
# Check the initialization of `player.value` in OmniPlayer.vue to determine what it refers to.
rg --type ts 'player.value' client/src/components/players/OmniPlayer.vue

Length of output: 1647



Script:

#!/bin/bash
# Search for the assignment or creation of `player.value` in OmniPlayer.vue.
rg --type ts 'player\s*=\s*' client/src/components/players/OmniPlayer.vue

Length of output: 75



Script:

#!/bin/bash
# Broaden the search to capture the context in which `player` is used within OmniPlayer.vue.
# This includes looking for imports, props, emits, or component definitions related to `player`.
rg --type ts 'player' client/src/components/players/OmniPlayer.vue

Length of output: 2332

* 122-138: The methods `getAvailablePlaybackRates`, `getPlaybackRate`, and `setPlaybackRate` have been removed from the `PlyrPlayer` component. This could be a simplification or a relocation of these functionalities. If these methods are essential, ensure they have been moved to an appropriate location or that their removal has been accounted for in the application's functionality.
Verification successful

The methods getAvailablePlaybackRates, getPlaybackRate, and setPlaybackRate have been removed from the PlyrPlayer component, but the functionality related to playback rate appears to be managed elsewhere in the application. References to playback rate settings are found in server-side files (server/room.ts) and in the API utilities (client/src/util/roomapi.ts). The application maintains this functionality, albeit refactored or relocated from the original PlyrPlayer component.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if the removed methods have been relocated or if their functionality is handled elsewhere.
rg --type ts 'getAvailablePlaybackRates\(\)|getPlaybackRate\(\)|setPlaybackRate\('

Length of output: 144



Script:

#!/bin/bash
# Check for any references to the playback rate functionality that might indicate how it's being handled now.
rg --type ts 'playbackRate|speed'

Length of output: 470

* 180-180: The `getCaptionsTracks` method is now being called from the `playerImpl` object. This is consistent with the refactoring and should work as long as the `playerImpl` object is correctly initialized and maintained.

Also applies to: 265-265

  • 344-344: The spread operator is used to expose the methods of playerImpl on the component's instance. This is a clean way to expose these methods and should work well with the Vue composition API.
client/src/components/players/OmniPlayer.vue (2)
  • 139-150: The MediaPlayer interface has been updated to allow the play and pause methods to return either void or Promise<void>. This change accommodates different browser behaviors regarding promise support for these operations and is a good enhancement for compatibility.
  • 222-222: The play and pause functions within the defineComponent have been updated to reflect the changes in the MediaPlayer interface. They now correctly handle the possibility of returning a Promise<void>. Ensure that the rest of the application correctly handles these methods' potential to return a promise.

Also applies to: 228-228

Verification successful

The play() and pause() methods in roomapi.ts do not need to handle promises as the underlying send method they call is synchronous, returning void. The review comment's concern about handling the potential for these methods to return a promise does not apply to the implementation in roomapi.ts.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for proper handling of play and pause methods that may return a promise.
rg --type ts 'play\(\)|pause\(\)'

Length of output: 502



Script:

#!/bin/bash
# View the implementation of play() and pause() in roomapi.ts
cat client/src/util/roomapi.ts | grep -A 10 'play()' 
cat client/src/util/roomapi.ts | grep -A 10 'pause()'

Length of output: 491



Script:

#!/bin/bash
# Check the implementation of the send method in the connection object within roomapi.ts
cat client/src/util/roomapi.ts | grep -A 20 'connection ='

Length of output: 453



Script:

#!/bin/bash
# View more of the context around the connection object in roomapi.ts
cat client/src/util/roomapi.ts | grep -B 5 -A 15 'this.connection ='

Length of output: 449



Script:

#!/bin/bash
# Find the file where OttRoomConnection is defined and view the implementation of the send method
rg --type ts 'class OttRoomConnection' -l | xargs grep 'send('

Length of output: 336

@dyc3 dyc3 merged commit 06b4a6c into master Jan 17, 2024
18 checks passed
@dyc3 dyc3 deleted the player-refactor branch January 17, 2024 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Something needs to be reworked to improve code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant