This repository was archived by the owner on Oct 21, 2026. It is now read-only.
Repository navigation
Conversation
The YouTube, Vimeo, Wistia, Cloudflare, Spotify, TikTok, and Twitch URL parsers were pure string functions, but each lived beside its adapter class, so nothing outside the adapter could use them without importing the whole embed. They now live in @videojs/media, which every adapter already depends on, and each adapter imports them and re-exports them under the same names. The parser tests move with them.
Picks the kind of media that plays a source URL, so apps can choose between media components the way Vidstack's provider did: - YouTube, Vimeo, Wistia, Mux, Cloudflare Stream, Spotify, TikTok, and Twitch, matched by host; - HLS and DASH manifests and video and audio files, matched by MIME type when one is passed, then by file extension. Bare ids return null, because an 11-character YouTube id and a 10-character Wistia id look alike. Vidstack's youtube/<id> and vimeo/<id> shorthands expand to URLs the matching media accepts. YouTube expands to the nocookie host, which is the host Vidstack played them from. Refs #2160
…eojs/html Apps depend on the framework packages, not on @videojs/media, so importing detectMediaSource from @videojs/media would fail under pnpm's strict dependency resolution. Both packages now re-export it with its DetectedMediaSource and MediaSourceKind types.
The builder scans the media source module as a framework-neutral entry point, since framework scans skip exports owned by other packages. The page maps each kind to its media component for React and HTML and covers MIME types, bare ids, and the Vidstack shorthands.
MediaSource is the Media Source Extensions API, and SPF already exports supportsMediaSource, createMediaSource, and attachMediaSource for it, so detectMediaSource read like MSE feature detection. The types follow: DetectedSource and SourceKind. The reference page moves to reference/api/detect-source.
A media class lists the brands it answers to under MEDIA_BRANDS, a global symbol, and isBrandedMedia checks a value or the adapter a custom media element wraps. Brands are import paths, so they still match across two bundled copies of a package.
Each adapter class carries its brand, and a guard beside it narrows media to that adapter, which types its engine. Mux flavors are branded per import path and also carry their engine's brand; Mux audio over hls.js drops the Mux video brand it would otherwise inherit.
Each @videojs/react/media and @videojs/html/media entry exports the guard for the media it provides, so apps import it next to the component or element, including media that ship inside the framework packages.
The media sources guide gets a section on engine access with a guard per media, and the Mux Player, Media Chrome, and Video.js 8 guides point to it.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@videojs/cdn
@videojs/cli
@videojs/core
@videojs/element
@videojs/html
@videojs/media
@videojs/react
@videojs/spf
@videojs/store
@videojs/utils
@videojs/cloudflare-video
@videojs/dash-video
@videojs/hlsjs-video
@videojs/mux-audio
@videojs/mux-video
@videojs/native-hls-video
@videojs/shaka-video
@videojs/spotify-audio
@videojs/tiktok-video
@videojs/twitch-video
@videojs/vimeo-video
@videojs/wistia-video
@videojs/youtube-video
@videojs/google-cast
@videojs/mux-data
commit: |
Contributor
📦 Bundle Size Report🎨 @videojs/html — 70 small size changes
Presets (7)
Media (18)
Players (5)
Skins (29)
UI Components (62)
⚛️ @videojs/react — 68 small size changes
Presets (7)
Media (22)
Extensions (2)
Players (5)
Skins (18)
UI Components (39)
🧩 @videojs/core — 2 small size changes
Entries (76)
🏷️ @videojs/element — no changesEntries (2)
📦 @videojs/store — no changesEntries (3)
🔧 @videojs/utils — no changesEntries (13)
📦 @videojs/cdn — no changes📦 @videojs/cloudflare-video — 1 small size change
📦 @videojs/dash-video — 1 small size change
📦 @videojs/google-cast — no changes📦 @videojs/hlsjs-video — 1 small size change
📦 @videojs/media — 1 small size change
Entries (3)
📦 @videojs/mux — no changes📦 @videojs/mux-audio — 2 small size changes
Entries (2)
📦 @videojs/mux-data — no changes📦 @videojs/mux-video — 2 small size changes
Entries (2)
📦 @videojs/native-hls-video — 1 small size change
📦 @videojs/shaka-video — 1 small size change
📦 @videojs/spf — 3 small size changes
Entries (7)
📦 @videojs/spotify-audio — 1 small size change
📦 @videojs/tiktok-video — 1 small size change
📦 @videojs/twitch-video — 1 small size change
📦 @videojs/other — 1 small size change
Entries (3)
📦 @videojs/vimeo-video — 1 small size change
📦 @videojs/wistia-video — 1 small size change
Entries (2)
📦 @videojs/youtube-video — 1 small size change
ℹ️ How to interpretEach entry is independently bundled, minified, and brotli-compressed. Initial size includes its static import graph; lazy dynamic chunks are reported separately. Entries are not additive because their dependency graphs overlap. Preset rows represent realistic combined bundles. Changes of 300 B or less across initial, lazy, and total size are collapsed, not discarded. Run |
Each guard narrows to an adapter class, so it's named for it: isHlsJsAdapter narrows to HlsJsAdapter. The brand constants beside them become *_BRAND.
The engine is created one microtask after a source is set, so reading media.engine straight away could find nothing and skip the listener. The example now subscribes to the current engine and again on every loadstart, removing first so a reused engine isn't subscribed twice.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes videojs/video.js#9467
Stacked on #3024
Summary
useMedia()types its media generically, because it doesn't know which component you rendered, so readingenginemeans guessing at its shape. This adds a type guard for every public media, which narrows the media, and with itengine, to that media's type:Each guard lives in the package that owns its adapter, and the React and HTML
/media/*entry points re-export it next to the component or element.Changes
@videojs/mediaaddsMEDIA_BRANDS, a global-symbol key under which a media class lists the brands it answers to, andisBrandedMedia(value, brand), which the per-media guards build on. A brand is the import path of the class, such as'@videojs/hlsjs-video'.isBrandedMediachecks the value itself, which is what React'suseMedia()returns, or itsadapter, which is what a custom media element wraps in HTML.isHlsJsAdapter,isNativeHlsAdapter,isDashAdapter,isShakaAdapter;isHlsVideoAdapter,isHlsAudioAdapter,isHlsBackgroundVideoAdapterin@videojs/spf;isMuxVideoAdapterandisMuxAudioAdapter, from both@videojs/mux-*and@videojs/mux-*/spf;isYouTubeAdapter,isVimeoAdapter,isWistiaAdapter,isCloudflareAdapter,isSpotifyAdapter,isTikTokAdapter,isTwitchAdapter.isHlsJsAdapter, and Mux over SPF toisHlsVideoAdapterorisHlsAudioAdapter. Each Mux flavor's own guard recognizes only that flavor, so the guard from/hls-jsnarrowsengineto hls.js.MuxVideoAdapter(the TODO inmux-audioalready calls that upside down), so its class lists its brands explicitly and drops Mux video's.@videojs/mux-audionow depends on@videojs/mediadirectly for the key.dash-videoandwistia-videoresolve to an inert stub outside the browser; the stubs carry the brand and export the guard, so a server import finds the same names.isMuxVideoAdapter, and the Media Chrome and Video.js 8 guides link to the new section.Why brands and not `instanceof`
<hlsjs-video>proxies its adapter's members and exposes it asadapter, soinstanceof HlsJsAdapteris false for the element the player registers.instanceofneeds the class at runtime, so asking "is this hls.js?" would pull in hls.js. Each guard module imports its adapter as a type only. Bundling justisHlsJsAdapterorisDashAdapterfrom the package root came to about 330 bytes with both esbuild and Rolldown, with no engine code. I didn't measure webpack; the adapter packages don't declaresideEffects.instanceof, Mux audio over hls.js would count as Mux video.For review
isHlsJsAdapterforHlsJsAdapter.isHlsBackgroundVideoAdaptercoversHlsBackgroundVideoand itsMuxBackgroundVideoalias, which share one adapter.<hls-background-video>and<mux-background-video>keep their adapter private and register it, not themselves, as the player's media. The guard recognizes what the player holds, not the element, and the element doesn't exposeengineanyway. The HTML table in the guide leaves them out.Testing
tests/predicate.test.tsin every adapter package and in@videojs/spf's three adapters. They cover the adapter, rejection of other media, a custom media element built on the adapter (hls.js), a subclassed Wistia element, and each Mux flavor's identities.isBrandedMediatests in@videojs/media: subclass inheritance, a subclass dropping a brand, the element look-through, a second copy of the key, and unbranded values.HlsJsVideoandMuxVideocreate media their guards recognize. HTML:<hlsjs-video>,<hls-video>, and both background video tags, through the@videojs/html/media/*entries.pnpm typecheckandpnpm check:workspacepass.pnpm build:sitepasses.🤖 Generated with Claude Code