feat(core,html,react): add YouTube provider, refactor IframeMediaHost and fix stale TextTrackList for iframe providers#1573
Conversation
|
@ronald-urbina is attempting to deploy a commit to the Mux Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
sampotts
left a comment
There was a problem hiding this comment.
I realized it's draft after diving in so just a few minor comments. Cheers!
| 'simple-hls-video': 'Simple HLS Video', | ||
| 'dash-video': 'DASH Video', | ||
| 'vimeo-video': 'Vimeo Video', | ||
| 'youtube-video': 'Youtube Video', |
| }, | ||
| // YouTube embed element | ||
| { | ||
| '[&_.media-youtube]:block [&_.media-youtube]:w-full [&_.media-youtube]:h-full [&_.media-youtube]:overflow-hidden [&_.media-youtube]:rounded-(--media-video-border-radius)': |
There was a problem hiding this comment.
Can we not apply the classNames directly onto the component (it looks like you're passing className down to the rendered <div> where .media-youtube is) and share it with the Vimeo media? Maybe an embeds.ts - I'll leave naming up to you! It just feels a little odd to use class names like .media-youtube in the Tailwind styles and target them this way.
| }, | ||
| // YouTube embed element | ||
| { | ||
| '[&_.media-youtube]:block [&_.media-youtube]:w-full [&_.media-youtube]:h-full [&_.media-youtube]:overflow-hidden [&_.media-youtube]:rounded-(--media-video-border-radius)': |
| iframe.style.border = 'none'; | ||
|
|
||
| if (!this.#controls) { | ||
| // CSS crop trick — hides the YouTube title bar (top) and branding bar (bottom) |
There was a problem hiding this comment.
Are we sure we're not breaching YouTube terms of service by doing this? We'll want to check we're not causing issues for users with this. I got a cease and desist from YouTube for hiding their chrome. I appreciate it doesn't look as nice though.
|
I also built the sandbox and noticed a few things:
|
Summary
Adds a full YouTube embed provider —
YouTubeMedia(core),YouTubeVideocustom element (html), andYoutubeVideoReact component (react) — and extracts a sharedIframeMediaHostbase class that both YouTube and Vimeo now extend.Also fixes a bug where iframe providers created a new
TextTrackListon everysrcchange, leaving stale listeners on the old list.What's included
New: YouTube provider
packages/core/src/dom/media/youtube/index.ts—YouTubeMedia: fullMediaEngineHostimplementation over the YouTube IFrame Player APItimeupdate(250 ms) — the YouTube SDK doesn't emit these nativelygetOption('captions', 'tracklist')MediaErrormappingsrc,autoplay,controls,loop,muted,playsinline,nocookie,startpackages/core/src/dom/media/youtube/api.ts— lightweight IFrame API loader with module-level caching and multi-player callback chainingpackages/html/src/media/youtube-video/—YouTubeVideocustom element (Shadow DOM, observed attributes)packages/react/src/media/youtube-video/—YoutubeVideoReact component (useMediaInstance,useSyncProps,useComposedRefs)packages/core/src/dom/media/youtube/tests/youtube-media.test.ts— ~690-line test suiteRefactor: shared
IframeMediaHostpackages/core/src/dom/media/iframe-host.ts— abstract base class extracted from the Vimeo providerrequestPictureInPicturepostMessage for SafariTextTrackListmanagementattach/detach/destroypackages/core/src/dom/media/vimeo/index.ts— simplified ~320 lines by extendingIframeMediaHostpackages/html/src/media/vimeo-video/— new HTML custom element for Vimeo (parallel to YouTube)Bug fix: stale
TextTrackListfor iframe providerspackages/core/src/dom/store/features/text-track.ts— re-subscribes to track list events (addtrack,removetrack,change) on everyloadstart, using anAbortControllerto clean up the previous subscription before attaching to the new listSandbox / demos
html-youtube-videoandreact-youtube-videosandbox templateshtml-vimeo-videoandreact-vimeo-videosandbox templates (Vimeo was missing React)Architecture notes
autoplay,controls,loop,nocookie,start) require an iframe remount on change; runtime props (muted,volume,playbackRate) delegate to the SDK directlyloopparam requiresplaylistto be set to the same video ID — handled automaticallynocookiedefaults tofalse(opt-in) so URLs stay consistent with what users provide