Skip to content
pedrosousa13Public

About

A performant, composable, accessible React 19 media player with capability-aware providers.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

462 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Playdeck

A performant, composable, accessible React 19 media player with capability-aware providers.

One API across native MP4/WebM, HLS (VOD and live), YouTube, Vimeo and Wistia. The primitives are headless — no CSS is imported, nothing is rendered you did not compose — and every control is gated on what the active provider can actually do, so a control whose command cannot be honoured is absent rather than present and disabled.

Install @playdeck/react. It is the only package a consumer installs:

pnpm add @playdeck/react

react and react-dom are peer dependencies, at >=19 <20.

import * as Player from '@playdeck/react';

// One API across MP4/WebM, HLS, YouTube, Vimeo and Wistia: the source decides
// which provider loads, and nothing else changes.
export const Clip = () => (
  <Player.Root source="https://example.com/clip.mp4">
    <Player.Viewport>
      <Player.Media />
      <Player.Controls>
        <Player.PlayButton />
        <Player.SeekSlider />
        <Player.Time type="current" />
        <Player.FullscreenButton />
      </Player.Controls>
    </Player.Viewport>
  </Player.Root>
);

The primitives set the geometry they need inline, so the player works with no stylesheet at all — what it lacks is appearance. The default theme is one optional import:

import '@playdeck/react/theme.css';

A YouTube or Vimeo source is the same prop and nothing else — no extra package, no registration: source="https://www.youtube.com/watch?v=dQw4w9WgXcQ", source="https://vimeo.com/76979871", or source="https://vimeo.com/76979871?h=<hash>" for an unlisted video. Those are three of the forms the detector accepts; Provider setup lists every one per provider, names the forms it refuses, and covers each provider's providerOptions.

Packages

Package What it is
@playdeck/react The React primitives. Start here.
@playdeck/core Framework-neutral state, commands, events, provider contract.
@playdeck/provider-native HTMLMediaElement: progressive files and native HLS.
@playdeck/provider-hls HLS via hls.js, or the browser's own, chosen per environment.
@playdeck/provider-youtube YouTube IFrame Player API.
@playdeck/provider-vimeo Vimeo player SDK.
@playdeck/provider-wistia Wistia's Aurora <wistia-player> element.

Only @playdeck/react needs installing: it depends on the rest and loads each provider lazily, once source detection says the active source needs it. A consumer playing MP4 ships no YouTube, Vimeo, Wistia or hls.js code in its initial graph.

What a page actually downloads

Lazy loading is worth stating in bytes rather than in adjectives, because the number a reader cares about is the one for the source they are playing, and for one of these sources it is large. Gzip, excluding React itself and the optional theme.css (12.6 KB) and docked.css (7.6 KB):

Playing Downloads Total
MP4 or WebM core 10.0 + primitives 24.3 + native 7.4 41.7 KB
HLS on Safari and iOS the above + HLS adapter 5.5 47.2 KB
HLS on Chrome, Edge, Firefox the above + hls.js 192.4 239.6 KB
HLS on Chrome, Edge, Firefox, with hls.js/light core + primitives + native + HLS adapter 47.2 + hls.js light 123.3 170.5 KB
YouTube core 10.0 + primitives 24.3 + adapter 6.7 41.0 KB
Vimeo core 10.0 + primitives 24.3 + adapter 8.5 + @vimeo/player 8.5 51.3 KB
Wistia core 10.0 + primitives 24.3 + adapter 5.9 40.2 KB

hls.js is the whole story here, and it is not ours. Adaptive streaming needs manifest parsing, MSE buffer management, ABR heuristics, MPEG-TS to fMP4 transmuxing and CEA-608/708 extraction; hls.js's own smallest build is 123.3 KB, and Playdeck's HLS adapter over it is 5.5. What lazy loading buys is not a smaller hls.js. It is that the other four rows never download one, and that Safari and iOS do not either, because they play HLS natively and hls.js is never fetched there.

Two of those numbers are within your control. hls.js/light saves 69.1 KB and gives up subtitles, alternate audio and DRM — the HLS package's README covers what that costs and how the player reports it, and it is reached through loadHls without forking anything. The @vimeo/player and hls.js versions are ordinary dependencies you can pin or swap.

YouTube and Wistia load their own player from their own origin at runtime, so their SDK is a network request rather than a package in your bundle, and it is not counted above. Third-party requests and CSP names every origin involved.

The table above, and every figure the paragraphs around it repeat from it, are written rather than typed: pnpm docs:bytes fills them in from the measurements, and pnpm docs:bytes:check fails CI when the two disagree, so a change that moves a bundle cannot leave a stale number in them.

Every Playdeck package in this table is measured by pnpm test:budgets on each CI run, against a reference figure it prints but never enforces: core weighs in at 10.0 KB, the primitives at 24.3 KB, theme.css at 2.4 KB and docked.css at 2.6 KB — the two stylesheets measured on their CSS rules with the comments stripped, because both ship as authored and measuring the whole file would really be measuring their prose. None of the four can ever fail a build over it; staying lean here is a standing goal, not a ceiling this repo enforces. The provider adapters are measured and reported the same way, with no reference figure of their own, because a lazy chunk does not compete for the initial graph.

The third-party bytes are the exception, and deliberately so: hls.js and @vimeo/player are external to those bundles, so that script never sees them. They are measured from the installed packages instead: the ES module entry a bundler resolves — hls.js 1.7.3 and @vimeo/player 2.30.4 — put through the same Vite build and the same gzip that produced the first-party figures, so both halves of a row are the same unit. The check fails if what is installed is not the version each package's manifest pins. They carry no reference figure at all: they move when you upgrade, and that is your decision rather than ours.

Honesty about providers

The reason for the capability contract is that these five providers do not have parity, and pretending otherwise moves the surprise from build time to your users. Every capability answers available, unknown, or unavailable with a reason, and every provider difference that matters is measured against the real SDK rather than inferred from its documentation. YouTube will not honour a quality choice, Vimeo needs a paid plan for chromeless playback, YouTube's buffered range cannot see buffer loaded before you arrived, Wistia reports no buffered range at all: each package README says so, and so does the workbench. The same honesty applies to the network: see Third-party requests and CSP for every origin a provider reaches and what a page's Content-Security-Policy has to allow for it.

Docs

The guides are the documentation, published from main at playdeck.video/guides, so reading them needs no clone: Contract (the data-attribute and style contract), Capabilities matrix (what each provider reports), Captions and Theme.

The site renders those documents from their source files rather than from a copy, so the workbench and the site cannot disagree about what they say.

The Storybook workbench stages every primitive against a mock provider, plus real-playback stories. It is a development tool for this repository rather than something published, and it runs against your own working tree with:

pnpm --filter @playdeck/storybook dev

Provider setup lists the source values each provider accepts and the ones it refuses, plus each provider's own options. Third-party requests and CSP names every origin a provider reaches and when each request happens.

Development

pnpm install
pnpm test              # unit tests (vitest)
pnpm test --coverage   # ... with per-package coverage
pnpm test:e2e          # Playwright, deterministic suites
pnpm test:storybook    # story tests, with axe checks
pnpm typecheck && pnpm lint && pnpm format:check
pnpm build

Packaging is verified against real tarballs (pnpm test:packages), bundle sizes are measured against reference budgets (pnpm test:budgets), and a Next.js integration is built and driven in a browser (pnpm test:integrations). That integration serves two routes: one imports @playdeck/react from a 'use client' component, and one is a React Server Component that imports it directly and passes no directive of its own, so the build fails there unless the package carries 'use client' on its entry. Its limit is that it depends on @playdeck/react through the workspace protocol, so what it drives is this repository's source rather than an installed artifact. What a consumer's install resolves to is pnpm test:packages's subject, and that run reads the directive back out of the packed tarball rather than out of the working tree.

pnpm test:packages installs those tarballs into a fixture it copies to a temp directory, and replays tests/packaging/fixture/pnpm-lock.yaml there so that install is pinned like every other one in the pipeline (#336). That lockfile is generated and committed, and the run fails naming the packages it re-resolved if the two have drifted. Regenerate it after changing the fixture's dependencies, or after a root advisory floor moves one of them:

node scripts/verify-packaging.mjs --update-fixture-lockfile

Then commit the lockfile.

That fixture is a consumer's project rather than a smoke script: it is type-checked against the installed tarballs under every resolution setting these packages claim to support, and under the ones they do not claim — which have to keep failing, since a setting that ignores export maps cannot reach the declarations. scripts/resolution-modes.mjs holds that set. The fixture also imports the theme by the subpath the documentation gives consumers, so the build has to resolve it and the browser check reads it back off the page.

The @real e2e tests talk to live YouTube, Vimeo and Wistia. They never run in CI, and there is no scheduled run either (#118): YouTube will not serve video to a runner's datacenter IP, so the result reported its opinion of that IP rather than whether our adapters are correct. Vimeo and Wistia still play there, but they run on the same goodwill, so they go the same way. Run them by hand when you touch a provider adapter:

PLAYDECK_REAL_PROVIDERS=1 pnpm test:e2e --project=chromium --grep @real

e2e/visual.spec.ts runs in its own visual Playwright project (chromium only) and is the one suite that checks how the player looks: overlay layering, containment and overflow, plus five PNG baselines of the reference example in e2e/__screenshots__.

The baselines are generated on ubuntu-latest and compared there, because macOS and Linux render text differently — on macOS those five tests skip and the layering assertions still run. To refresh them after an intentional visual change:

gh workflow run visual-baselines.yml --ref "$(git branch --show-current)"
gh run download <run-id> --name visual-baselines --dir e2e/__screenshots__

Then commit the PNGs. A red visual CI job uploads the -actual and -diff images as a visual-diff artifact, which is also where the images come from when the refresh workflow is not dispatchable — GitHub only offers workflow_dispatch for workflows already on the default branch, so a workflow file added on a branch cannot be run until it has merged once.

Releasing

A release is cut by hand, from main, with release.yml. There is no push trigger: the version bump lands as an ordinary pull request first, and dispatching the workflow is the separate, deliberate act that publishes it.

The bump is pnpm version:packages, which applies the pending changesets, moves the versions, writes each package's CHANGELOG.md, and ends by naming the tags the release will need. Once that pull request has landed, tag main before dispatching anything:

pnpm tag:packages

One tag per package, named the way changesets names one — @playdeck/[email protected] — because these packages version independently, so one repo-wide tag would name a version most of them are not at. It runs before the publish rather than after it, so a release that fails halfway still leaves a tag to diff against, and a second run pushes nothing. scripts/release-tags.mjs carries the rest of the reasoning, including why the tag is not created by changeset version itself and not pushed from the workflow.

gh workflow run release.yml --ref main -f dry_run=true   # resolve and pack only
gh workflow run release.yml --ref main -f dry_run=false  # publish

dry_run defaults to true, so an accidental dispatch cannot publish. Either way the run begins by refusing outright if the remote carries no tag for a version about to be published — pnpm tag:packages above is what creates them, and this is the check that it was run, so a dry run dispatched before tagging fails here and names what is missing. Past that, the job runs typecheck, test, test:audit, build, test:packages, test:budgets, test:bundle and test:integrations before it goes near the registry, so the provenance attestation covers artifacts that run actually checked.

Every package ships its own CHANGELOG.md, so an installed copy carries the history of the version installed rather than sending its reader back to GitHub. test:packages fails a tarball that carries no changelog, or one whose changelog does not name the version being packed.

The publish is pnpm publish -r, never npm publish: the packages depend on each other through pnpm's workspace:^ protocol, and only pnpm rewrites that to a real version range when it packs. -r takes every workspace package that is not private and whose version is not already on the registry, so the set comes from the manifests and no name is listed in the workflow.

Browser support

Browser Minimum
Chrome/Edge 99
Firefox 97
Safari, iOS 15.4

The floor is set by CSS, not JavaScript: theme.css uses @layer, which is the newest feature anything in Playdeck requires. The built JavaScript needs nothing above Safari 14.1, so a consumer who never imports the optional stylesheet is bound only by that.

env(), forced-colors and prefers-reduced-motion do not raise the floor even where support arrived later — a media query that never matches simply does not apply, so they are progressive enhancement rather than requirements.

React is a separate peer requirement rather than a browser one; its range is given with the install command at the top of this file.

The reference example in the workbench uses @container, which is newer than this floor. It is a Storybook composition and not published code, so nothing a consumer installs depends on it — the floor above is what @playdeck/react itself holds to.

License

MIT.

About

A performant, composable, accessible React 19 media player with capability-aware providers.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages