-
Notifications
You must be signed in to change notification settings - Fork 23
fix: improve video loading compatibility #1342
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
Conversation
📝 WalkthroughWalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Promise as loadVideo Promise
participant Video as Video Element
participant Handler as Event Handlers
Caller->>Promise: Call loadVideo(url)
Note over Promise: Create promise, set settled = false
Promise->>Video: Set src attribute
Promise->>Video: Attach loadeddata listener
Promise->>Video: Attach canplay listener
Promise->>Video: Attach error listener
Promise->>Video: Call video.play()
alt Autoplay Blocked
Video-->>Promise: (play promise rejects)
Note over Promise: Log autoplay blocked warning
end
alt Success Path
Video->>Handler: loadeddata event fires
Handler->>Handler: Check settled flag
Handler->>Promise: handleSuccess()
Note over Promise: settled = true
Promise->>Video: Remove all listeners (cleanup)
Promise->>Caller: Resolve with video element
else or
Video->>Handler: canplay event fires
Handler->>Handler: Check settled flag
Handler->>Promise: handleSuccess()
Note over Promise: settled = true
Promise->>Video: Remove all listeners (cleanup)
Promise->>Caller: Resolve with video element
else Error Path
Video->>Handler: error event fires
Handler->>Handler: Check settled flag
Handler->>Promise: handleError()
Note over Promise: settled = true
Promise->>Video: Remove all listeners (cleanup)
Promise->>Caller: Reject with error message
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/effects-core/src/downloader.ts (1)
314-316: Video may remain playing after promise resolves.Calling
video.play()to trigger loading (instead ofvideo.load()) is a reasonable fix for the compatibility issue. However, ifplay()succeeds, the video will be actively playing when the promise resolves. Since the function is namedloadVideo, callers might expect a preloaded but paused video.Consider pausing after successful load if the intent is purely to preload:
🔎 Suggested fix
const handleSuccess = () => { if (settled) {return;} settled = true; cleanup(); + video.pause(); resolve(video); };
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/effects-core/src/downloader.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
packages/effects-core/src/downloader.ts (1)
288-308: Well-structured promise handling with proper cleanup.The
settledflag pattern correctly prevents multiple resolutions, and the cleanup function properly removes all event listeners. Using bothloadeddataandcanplayevents improves compatibility across different browsers.
原因:只调用 video.load() 而不调用 play(),canplay 事件可能不会触发
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.