feat: add onAccessTokenExpired prop for token refresh handling - #18
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe 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
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Poem
✨ Finishing Touches🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
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
onAccessTokenExpiredprop to theTPStreamsPlayercomponent, 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
-
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. ↩
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
README.mdis 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
setNewAccessTokencall to the underlying view following the established patternAlso applies to: 50-50, 120-122
src/TPStreamsPlayerViewNativeComponent.ts (1)
38-38: LGTM! Proper bridge interface definition.The implementation correctly:
- Defines the
onAccessTokenExpiredevent handler with appropriate payload structure- Adds the
setNewAccessTokencommand 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
releasePlayerprevents 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.
Summary by CodeRabbit