Repository navigation
feat(media): add resolveAdapterType and resolveMimeType - #3024
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for vjs10-site ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for vjs-registry ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@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: |
📦 Bundle Size Report🎨 @videojs/html — 45 small size changes
Presets (7)
Media (18)
Players (5)
Skins (29)
UI Components (62)
⚛️ @videojs/react — 50 small size changes
Presets (7)
Media (22)
Extensions (2)
Players (5)
Skins (18)
UI Components (39)
🧩 @videojs/core — 1 small size change
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 — no changes📦 @videojs/google-cast — no changes📦 @videojs/hlsjs-video — no changes📦 @videojs/media
Entries (3)
📦 @videojs/mux — no changes📦 @videojs/mux-audio — 1 small size change
Entries (2)
📦 @videojs/mux-data — 1 small size change
📦 @videojs/mux-video — no changesEntries (2)
📦 @videojs/native-hls-video — 1 small size change
📦 @videojs/shaka-video — no changes📦 @videojs/spf — no changesEntries (7)
📦 @videojs/spotify-audio — 1 small size change
📦 @videojs/tiktok-video — 1 small size change
📦 @videojs/twitch-video — 1 small size change
📦 @videojs/other
Entries (3)
📦 @videojs/vimeo-video — 1 small size change
📦 @videojs/wistia-video — 2 small size changes
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 |
…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.
luwes
left a comment
There was a problem hiding this comment.
Proposal: drop src and id from DetectedSource, keep the name detectSource.
Right now the result mixes classification with normalization. That's why the docs have to say "pass the returned src" twice, and it's where the Mux token bug below comes from. Suggest:
interface DetectedSource {
kind: SourceKind;
type?: string;
}src: move the rewriting into the media that plays the source.parseYouTubeSourceacceptsyoutube/<id>(as nocookie),parseVimeoSourceacceptsvimeo/<id>, and Mux media acceptsplayer.mux.com/<id>and mapsplayback-tokentotokennext toparseMuxVideoURL. ThendetectSourcenever changes the input, apps pass the URL they already have, and<youtube-video src="youtube/…">works for Vidstack migrants whether or not they calldetectSource. TodayparseYouTubeSourcedoesn't recognize the shorthand, so passing one straight toYouTubeVideodoesn't work.id: it means different things per kind (YouTube video id vs playlist id, Twitch VOD id vs channel name), and the result doesn't say which. Apps that need a provider id can callparseYouTubeSourceand friends, which carry their ownkind.
Removing fields after release is a breaking change, so it'd be good to do this before it ships, even if the adapter shorthand support lands as a follow-up.
`parseYouTubeSource` and `parseVimeoSource` now read Vidstack's `youtube/<id>` and `vimeo/<id>` shorthands, so the YouTube and Vimeo media play them as `src` without an app rewriting them first. YouTube shorthands keep playing from the privacy-enhanced host, as in Vidstack. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…MimeType `resolveMediaType(src, type?)` returns only the media type that plays a source, such as `'youtube'` or `'hls'`, instead of an object with a rewritten `src` and provider `id`. Apps pass the source they already have to the media, and adapters read ids with their own parsers. `resolveMimeType(src)` returns the MIME type a file extension implies, the part of the old result that wasn't about the media type. `player.mux.com` page URLs no longer resolve to `mux`, since Mux media only plays stream URLs and nothing rewrites the source anymore. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Replaces the detectSource page. Usage passes the original `src` to the media, and the shorthand table says what each shorthand plays rather than what it expands to. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1aa64cd. Configure here.
The type becomes `MediaSourceKind`, and the reference page moves to `resolve-source-kind`. "Media type" read like a MIME type next to `resolveMimeType`. Also drops the reference page's note on calling it from Server Components, which needs its own investigation. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`stream.mux.com/<playback-id>` serves the same HLS manifest as the `.m3u8` URL, and the installation flow already treats it as Mux. Static renditions under a playback id, such as `/<id>/highest.mp4`, still resolve by file extension. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`detectRendererCandidates` maps the source kind to renderers, then adds the generic stream renderers a file extension implies, so a Mux or Cloudflare manifest still accepts `hls` or `dash`. The host and extension tables are gone. Resolving through the media parsers tightens detection: provider pages without a video, such as `youtube.com/`, and `mux.com` pages, which aren't streams, no longer match a provider. The CLI bundles `@videojs/media` along with the rest, so the published file still needs only Node built-ins. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`resolveProviderKind(src)` answers which hosting provider serves a URL, and `resolveFormatKind(src, type?)` answers which stream or file format it is. `resolveSourceKind` is the first answer, falling back to the second. `MediaSourceKind` is now `MediaProviderKind | MediaFormatKind`. Installation needs both answers for one URL: a Mux manifest plays in the Mux media and in the generic HLS media. The halves stay in `@videojs/media` and aren't re-exported by the framework packages. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`detectRenderer` becomes `resolveRenderer` and returns just the renderer; callers read its label with `getInstallationRenderer`, as they already did for `articleFor`. `detectRendererCandidates` becomes `resolveRendererCandidates` and lists the provider's renderers followed by the format's, replacing the file-name lookup. The module moves to `resolve-renderer.ts`, and `DetectionResult` is gone. Project detection in `node.ts` keeps `detect`: it reads the file system rather than resolving a value it was given. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`resolveProviderKind` becomes `resolveSourcePlatform` and `resolveFormatKind` becomes `resolveSourceFormat`, with the types `MediaSourcePlatform` and `MediaSourceFormat`, so every source resolver reads `resolveSource*`. Prose around them says hosting platform rather than provider. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Drops `resolveSourcePlatform` and `resolveSourceFormat` and their types; `MediaSourceKind` is one union again. Installation resolves the kind with `resolveSourceKind`, and resolves the file name alone for the generic stream renderers a provider's manifest also plays in. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Summaryinconclusive — the Failed run
Evidence
Likely causeVerified: the process creating the Next/Tailwind registry fixture crashed before product tests ran. Inference: this is likely a transient/upstream Recommended actions
|
`application/x-mpegURL; charset=utf-8` and `application/dash+xml; profiles=…` missed the HLS and DASH checks, and `audio/mpegurl; …` fell through to `audio`. The type's parameters are now dropped before matching. Also rewords the YouTube shorthand comment to say why it plays from the privacy-enhanced host. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The installation Markdown edge function loads `dist/index.js` through an import map, and Netlify's edge bundler resolves npm specifiers only from the root `node_modules`, where pnpm doesn't link workspace packages. The `@videojs/media` import broke the site's deploy previews. Installation now bundles the source kind resolver and parsers it uses, so its main entry imports no packages again. `@videojs/media` moves to its devDependencies, and the CLI no longer lists it, since it bundles installation's output. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Applies the maintain-tests audit from #3080 to the tests this branch touches. Installation now delegates host and extension recognition to `resolveSourceKind`, so its per-host and per-extension cases replayed media's contract. They're gone; installation keeps one case per kind for the renderer mapping, the use-case selection and null cases as tables, and the file-name fallback. Media takes over what only installation proved: the videodelivery.net host, the Vimeo page gate, and the ogv, m4a, wav, ogg, and aac MIME types. Whitespace trimming gets a padded URL that resolves, since a blank string returns null with or without trimming. Shorthand variants move to their parser tests, and query, hash, and case handling to `resolveMimeType`. The `video/mp4; codecs=…` case is dropped because it passes without the parameter fix. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The result names the type of adapter that plays a source, so the function becomes `resolveAdapterType` and its type `AdapterType`, alongside `resolveMimeType`. The module, tests, and reference page move to `adapter-type`, and the prose says adapter type instead of kind. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
luwes
left a comment
There was a problem hiding this comment.
LGTM thanks!
nit some mentions of provider
resolveMimeType can be used in the HLS adapter, for future.
"Provider" meant two things around `resolveAdapterType`: the hosting service a URL belongs to, and the adapter type or renderers it resolves to. Prose and test names now say service for the first and adapter type or the renderers for the second. The private `resolveProvider` helper becomes `fromService`, beside `fromMimeType`. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Refs videojs/video.js#9290
Summary
Adds
resolveAdapterType(src, type?)andresolveMimeType(src)to@videojs/media, and re-exports both from@videojs/reactand@videojs/html.resolveAdapterTypetells an app which media component plays a URL, so the app can renderYouTubeVideo,HlsJsVideo,Video, and so on without writing its own URL matching. The app passes the samesrcit already has to that component. It's the near-term answer to videojs/video.js#9290's "which media do I use for this URL?". The auto-loading media component in that issue can build on it later.The installation flow (site picker, Markdown twins, and
@videojs/cli) now resolves media with it too, so the docs and the runtime share one set of rules.Vidstack chose providers from
srcautomatically, so this also closes the biggest ergonomic gap in the Vidstack migration (#3021).Changes
resolveAdapterTypereturns only the adapter type. It's anAdapterTypestring such as'youtube'or'hls', ornull. It doesn't rewrite the source or return a service's video or channel id, so apps never have to pass a transformedsrc. Adapters read ids with their own parsers.stream.mux.com, with or without.m3u8), Cloudflare Stream, Spotify, TikTok, and Twitch URLs, plusspotify:URIs. A service URL only matches when its parser finds a video, and a service URL nested in a query parameter isn't mistaken for the service.blob:URLs. Its parameters (; codecs=…) are ignored.resolveMimeTypereturns the MIME type a file extension implies, ignoring the query string and hash.resolveAdapterTypeuses it for the extension fallback.null. An 11-character YouTube id and a 10-character Wistia id look alike.youtube/<id>andvimeo/<id>shorthands. Vidstack accepted both assrc.resolveAdapterTyperecognizes them through the same parsers, so the media plays whatever resolves. YouTube shorthands play fromyoutube-nocookie.com, the host Vidstack played them from.player.mux.compage URLs aren't matched. Mux media plays stream URLs, and nothing rewrites the source.resolveRendererCandidates(wasdetectRendererCandidates) maps the adapter type to renderers, then adds the generic stream renderers the file name resolves to, so--media hlsstill fits a Mux.m3u8.resolveRenderer(wasdetectRenderer) returns just the renderer; callers read the label withgetInstallationRenderer. The module isresolve-renderer.ts, and its host and extension tables are gone. Resolution gets stricter in two places: service pages without a video (youtube.com/) andmux.compages (they 404 as streams) no longer match a service.@videojs/installationbundles the resolver and parsers it uses from@videojs/media(a devDependency), so its main entry still imports no packages. The CLI gets them through installation's output and still needs only Node built-ins (144.8 KB → 155.8 KB).@videojs/reactand@videojs/html, together with theAdapterTypetype. Apps depend on those packages rather than@videojs/media, and pnpm won't let an app import a package it doesn't depend on directly.resolveAdapterTypeandresolveMimeType. TheresolveAdapterTypepage maps each adapter type to its media component for React and HTML, and covers MIME types, bare ids, and the shorthands. The API docs builder now scanspackages/media/src/core/source/adapter-type.tsas a framework-neutral entry point, the same way it scansorientation-lock.ts. It has to, because framework scans skip exports owned by other packages.@videojs/media(the first commit, a pure refactor):parseYouTubeSource,parseVimeoSource,parseWistiaMediaId,parseCloudflareSource,parseSpotifySource,parseTikTokSource,parseTwitchSource, and their id helpers and types. Every adapter already depends on@videojs/media, so nothing depends the wrong way. Each adapter imports the parsers back and re-exports them under the same names, so its public API doesn't change. The parser tests move with them.Implementation details
detectSource, which returned{ kind, src, id, type }. Review settled on a function per answer:resolveAdapterType(brieflyresolveMediaType, thenresolveSourceKind) for the adapter type,resolveMimeTypefor the MIME type, and theparse*Sourceparsers for service ids.detectMediaSourcewas ruled out earlier becauseMediaSourceis the Media Source Extensions API.hlscovers every HLS adapter anddashevery DASH adapter. Choosing between hls.js, SPF, and native HLS stays with the app, and later with Feature: Provide a URL-Based Video Source Detection Facade video.js#9290.wistiabut list no installation candidates, as before.vm.tiktok.comshort links, Twitch clips, and custom Mux stream domains still fall through, the last to plainhls.@videojs/mediabecause the Netlify edge function that renders installation Markdown twins loads@videojs/installation'sdistthrough an import map. Netlify's edge bundler resolves npm specifiers only from the rootnode_modules, where pnpm doesn't link workspace packages, so an external@videojs/mediaimport failed the deploy.Preview
resolveAdapterType· HTMLresolveAdapterTyperesolveMimeType· HTMLresolveMimeTypeFor review
youtube/<id>from the nocookie host the behavior we want? A bare id still plays fromyoutube.com.Testing
pnpm -F @videojs/media test src/core/source: 136 tests.adapter-type.test.tscovers every adapter type, the shorthands, extensionless Mux streams and static renditions, MIME precedence, parameters, and fallback,resolveMimeType, and thenullcases, including bare ids, malformed shorthands,player.mux.compages, short links, clips, and nested URLs. The YouTube and Vimeo parser tests cover the shorthands.maintain-testsskill from test(packages): audit every test with the maintain-tests skill #3080: cases that replayed a stronger owner were removed, each removal was checked against a named keeper by an independent reviewer, and the MIME-parameter and whitespace tests were each seen failing under a source mutation.pnpm -F @videojs/youtube-video testandpnpm -F @videojs/vimeo-video testpass, including new embed URL tests for the shorthands.pnpm -F @videojs/installation test: 293 tests. Renderer resolution tests keep one case per adapter type for the mapping, use-case selection and null cases as tables, andresolveRendererCandidatescoverage for Mux and Cloudflare manifests, embeds, and Wistia. Host and extension recognition is proven once, in media.pnpm -F @videojs/cli testand the skins installation registry test pass. The built CLI resolves YouTube, extensionless Mux, and.m3u8URLs, and still rejects--media youtubefor a Mux URL.@netlify/edge-bundlerbundles all three edge functions locally with the site's import map; before the bundling fix it failed on@videojs/mediaexactly as the deploy preview did.pnpm -F site test scripts/api-docs-builder src/utils integrations(681 tests) passes.pnpm typecheck,pnpm lint,pnpm check:workspace,pnpm -F site astro check, andpnpm build:sitepass. Both framework versions of both reference pages render.🤖 Generated with Claude Code
Note
Medium Risk
Touches shared source parsing and installation auto-selection; behavior is stricter in edge cases (bare ids, service homepages), so regressions would affect picker defaults and any app switching on
resolveAdapterType.Overview
Adds
resolveAdapterTypeandresolveMimeTypeto@videojs/media(re-exported from@videojs/reactand@videojs/html) so apps can pick the right media component from a URL without duplicating host/extension rules. Resolution uses shared embed parsers, optional MIME type, and returnsnullfor ambiguous bare ids; YouTube and Vimeo gainyoutube/<id>andvimeo/<id>shorthands (nocookie embed for YouTube).Embed parsing moves from individual adapters into
@videojs/media/core/source; adapters import and re-export the sameparse*SourceAPIs so public surfaces stay stable, with parser tests relocated to media.Installation drops hostname/extension tables in favor of
resolve-renderer.ts(resolveRenderer/resolveRendererCandidatesbuilt onresolveAdapterType), updates the site picker and selection validation, bundles@videojs/mediafor Netlify edge, and adds reference docs for the new utils.Reviewed by Cursor Bugbot for commit c6634c7. Bugbot is set up for automated code reviews on this repo. Configure here.