Skip to content

feat: add onAccessTokenExpired prop for token refresh handling - #18

Merged
Gowreesh-A-M merged 2 commits into
mainfrom
feat/token-expiry
Jul 30, 2025
Merged

feat: add onAccessTokenExpired prop for token refresh handling#18
Gowreesh-A-M merged 2 commits into
mainfrom
feat/token-expiry

Conversation

@Gowreesh-A-M

@Gowreesh-A-M Gowreesh-A-M commented Jul 30, 2025

Copy link
Copy Markdown
  • Added onAccessTokenExpired prop to the player component for handling access token expiration events.
  • Integrated native logic to detect token expiration and emit a corresponding event to JavaScript.

Summary by CodeRabbit

  • New Features
    • Added support for handling access token expiration events in the player component.
    • Introduced a new event that notifies when an access token has expired, allowing users to provide a new token dynamically.
    • Enabled seamless token renewal without interrupting playback by updating the access token directly from the app interface.

@coderabbitai

coderabbitai Bot commented Jul 30, 2025

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository.

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.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce support for handling access token expiration events in the TPStreams player components. This includes adding callback mechanisms and event handlers at both the Android native and React Native levels, enabling dynamic access token renewal when notified by the player. New methods and event constants are added to facilitate this integration.

Changes

Cohort / File(s) Change Summary
Android Player View: Access Token Handling
android/src/main/java/com/tpstreams/TPStreamsRNPlayerView.kt
Introduced a nullable access token callback, added a method to set a new access token, and updated player listener and release logic to support token renewal and event emission.
Android Player View Manager: Event & Command
android/src/main/java/com/tpstreams/TPStreamsRNPlayerViewManager.kt
Added a new event constant for access token expiration, exported it to JS, and implemented a method to forward new tokens to the native view.
React Native Player Component: Token Expiry Prop
src/TPStreamsPlayer.tsx
Added a new prop and handler for access token expiration, wiring it to native events and commands for seamless token refresh from JS.
Native Component Interface & Commands
src/TPStreamsPlayerViewNativeComponent.ts
Extended native props and commands to support the new access token expiration event and token update command.

Sequence Diagram(s)

sequenceDiagram
    participant NativePlayer as Android TPStreamsRNPlayerView
    participant JSComponent as TPStreamsPlayer (React Native)
    participant User as App User

    NativePlayer->>JSComponent: Emit onAccessTokenExpired(videoId)
    JSComponent->>User: onAccessTokenExpired(videoId, callback)
    User->>JSComponent: callback(newToken)
    JSComponent->>NativePlayer: setNewAccessToken(newToken)
    NativePlayer->>NativePlayer: Invoke accessTokenCallback(newToken)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

A token hops, it leaps, expires—
But don’t you fret, the code aspires!
With callbacks swift and events anew,
The stream resumes, refreshed for you.
So let the player play its tune,
While rabbits code beneath the moon.
🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/token-expiry

🪧 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

@codetortoiseai

Copy link
Copy Markdown

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 30, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary of Changes

Hello @Gowreesh-A-M, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial new feature to the TPStreams React Native player component: the ability to gracefully handle access token expiration. By providing a new onAccessTokenExpired prop, the player can now notify the JavaScript application when a token expires, allowing the application to fetch a new token and seamlessly provide it back to the native player, ensuring uninterrupted video playback.

Highlights

  • New Feature: Access Token Expiration Handling: Introduced a new onAccessTokenExpired prop to the TPStreamsPlayer component, allowing React Native applications to handle video access token expiration events and refresh tokens dynamically.
  • Cross-Platform Event Communication: Implemented native logic (Android/Kotlin) to detect token expiration and emit a corresponding event to the JavaScript layer. The JavaScript layer then provides a mechanism to send a new token back to the native player to resume playback.
  • Improved Player Resilience: This feature enhances the player's ability to handle long-running playback sessions by providing a robust way to refresh authentication tokens without interrupting the user experience.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request adds a new feature to handle access token expiration via an onAccessTokenExpired prop. The implementation is solid, with corresponding changes on the native Android side and the React Native component layer. My feedback includes a fix for a potential race condition in the Android code, a correction for a type inconsistency in the TypeScript implementation, and a suggestion to improve the documentation with a more practical example. Overall, great work on this important feature.

Comment thread android/src/main/java/com/tpstreams/TPStreamsRNPlayerView.kt
Comment thread README.md
Comment thread src/TPStreamsPlayer.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2190291 and 1c5a51f.

⛔ Files ignored due to path filters (1)
  • README.md is excluded by !*.md
📒 Files selected for processing (4)
  • android/src/main/java/com/tpstreams/TPStreamsRNPlayerView.kt (4 hunks)
  • android/src/main/java/com/tpstreams/TPStreamsRNPlayerViewManager.kt (3 hunks)
  • src/TPStreamsPlayer.tsx (4 hunks)
  • src/TPStreamsPlayerViewNativeComponent.ts (3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: syed-tp
PR: testpress/react-native-tpstreams#2
File: android/src/main/java/com/tpstreams/TPStreamsDownloadModule.kt:32-40
Timestamp: 2025-06-17T15:45:22.435Z
Learning: In the react-native-tpstreams project, there's a naming convention where the same identifier is called "assetId" in the Android SDK but "videoId" in the React/JavaScript layer. The React Native bridge intentionally maps item.assetId to the "videoId" key to maintain consistency with React naming conventions.
src/TPStreamsPlayerViewNativeComponent.ts (1)

Learnt from: syed-tp
PR: #2
File: android/src/main/java/com/tpstreams/TPStreamsDownloadModule.kt:32-40
Timestamp: 2025-06-17T15:45:22.435Z
Learning: In the react-native-tpstreams project, there's a naming convention where the same identifier is called "assetId" in the Android SDK but "videoId" in the React/JavaScript layer. The React Native bridge intentionally maps item.assetId to the "videoId" key to maintain consistency with React naming conventions.

android/src/main/java/com/tpstreams/TPStreamsRNPlayerView.kt (1)

Learnt from: syed-tp
PR: #2
File: android/src/main/java/com/tpstreams/TPStreamsDownloadModule.kt:32-40
Timestamp: 2025-06-17T15:45:22.435Z
Learning: In the react-native-tpstreams project, there's a naming convention where the same identifier is called "assetId" in the Android SDK but "videoId" in the React/JavaScript layer. The React Native bridge intentionally maps item.assetId to the "videoId" key to maintain consistency with React naming conventions.

🪛 GitHub Check: lint
src/TPStreamsPlayer.tsx

[warning] 171-171:
'videoId' is already declared in the upper scope on line 66 column 5

🔇 Additional comments (7)
android/src/main/java/com/tpstreams/TPStreamsRNPlayerViewManager.kt (1)

29-29: LGTM! Clean implementation following existing patterns.

The implementation correctly:

  • Follows the existing naming convention for event constants
  • Properly exports the new event in the custom direct event types
  • Delegates the setNewAccessToken call to the underlying view following the established pattern

Also applies to: 50-50, 120-122

src/TPStreamsPlayerViewNativeComponent.ts (1)

38-38: LGTM! Proper bridge interface definition.

The implementation correctly:

  • Defines the onAccessTokenExpired event handler with appropriate payload structure
  • Adds the setNewAccessToken command with proper type annotations
  • Includes the new command in the supported commands list
  • Maintains consistency with the existing bridge interface patterns

Also applies to: 60-63, 76-76

android/src/main/java/com/tpstreams/TPStreamsRNPlayerView.kt (3)

26-26: LGTM! Proper nullable callback declaration.

The callback variable is appropriately declared as nullable to handle the asynchronous nature of token refresh.


102-107: LGTM! Proper event listener implementation.

The listener correctly:

  • Stores the callback for later use
  • Emits the access token expired event with the video ID
  • Follows the established event emission pattern

205-205: LGTM! Proper cleanup of callback reference.

Clearing the callback reference in releasePlayer prevents potential memory leaks.

src/TPStreamsPlayer.tsx (2)

51-54: LGTM! Well-defined callback interface for token refresh.

The prop interface correctly defines the callback pattern for handling token expiration with appropriate type annotations.


250-250: LGTM! Proper event handler wiring.

The event handler is correctly wired into the native props, completing the bridge between native and React Native layers.

Comment thread android/src/main/java/com/tpstreams/TPStreamsRNPlayerView.kt
Comment thread src/TPStreamsPlayer.tsx
@Gowreesh-A-M
Gowreesh-A-M merged commit 3e692a2 into main Jul 30, 2025
6 checks passed
@Gowreesh-A-M
Gowreesh-A-M deleted the feat/token-expiry branch July 30, 2025 14:00
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