npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@interlacejs/hls-adapter

v0.3.0

Published

HLS VideoAdapter for Interlace: hls.js playback with selectable quality levels, native HLS and MP4 fallback.

Readme

@interlacejs/hls-adapter

An HLS implementation of the @interlacejs/core VideoAdapter contract, built on hls.js. It extends NativeVideoAdapter from @interlacejs/native-adapter (play/pause/seek, programmaticSeek, overlay mounting, fullscreen and destroy() behave the same) and adds the optional quality capability, so @interlacejs/player shows its built-in quality menu.

Install

pnpm add @interlacejs/hls-adapter @interlacejs/core hls.js

hls.js (^1.5) is a peer dependency.

Usage

import { HlsVideoAdapter } from "@interlacejs/hls-adapter";
import { InteractiveVideoPlayer } from "@interlacejs/player";

function Watch({ doc, hlsUrl, mp4Url }) {
  const videoRef = useRef<HTMLVideoElement>(null);
  const [adapter, setAdapter] = useState<HlsVideoAdapter>();

  useEffect(() => {
    if (!videoRef.current) return;
    const a = new HlsVideoAdapter(videoRef.current, {
      src: hlsUrl, // .m3u8 manifest
      fallbackSrc: mp4Url, // optional progressive fallback
      rememberQualityKey: "my-app:video-quality", // optional
    });
    setAdapter(a);
    return () => a.destroy();
  }, [hlsUrl, mp4Url]);

  return (
    <div style={{ position: "relative" }}>
      {/* No src: the adapter sets the source. */}
      <video ref={videoRef} controls />
      {adapter && (
        <div style={{ position: "absolute", inset: 0, pointerEvents: "none" }}>
          <InteractiveVideoPlayer
            adapter={adapter}
            document={doc}
            registry={registry}
          />
        </div>
      )}
    </div>
  );
}

Don't set src on the <video> yourself; the adapter picks the source.

Options

| Option | Description | | -------------------- | -------------------------------------------------------------------------------------------------------------------- | | src | Video URL (required): an HLS manifest (.m3u8) or a plain video file such as an MP4. | | type | "auto" (default: HLS when the URL path ends in .m3u8), "hls" or "progressive". | | fallbackSrc | Progressive source (e.g. MP4) for browsers without HLS support and for unrecoverable errors. | | hlsConfig | Partial<HlsConfig> passed to new Hls(). | | refreshSource | () => Promise<{ src, fallbackSrc? }>: fetches fresh URLs when the current ones are rejected as expired. See below. | | rememberQualityKey | localStorage key for the viewer's quality choice (stored as a height or "auto"). Not remembered when omitted. |

Playback paths

  • Plain video files (src isn't HLS, e.g. an MP4): played directly in the <video> element, like NativeVideoAdapter. There is one quality, so getQualityLevels() returns [] and the player shows no quality menu. You can use this adapter for every video and let it pick the path.
  • hls.js (Hls.isSupported(), most desktop and Android browsers): attaches hls.js and loads src. Once the manifest is parsed, levels are exposed one per height (highest bitrate wins), sorted high to low and labelled 720p, etc. A remembered choice is re-applied (the same height, or the nearest lower one), and qualitychange fires.
  • Native HLS (Safari, iOS): sets video.src = src. The browser picks the quality, so getQualityLevels() returns [] and the player hides its quality menu.
  • Neither: plays fallbackSrc, if given.

Quality API

HlsVideoAdapter implements QualityCapableAdapter from @interlacejs/core:

getQualityLevels(): QualityLevel[]; // [] until the manifest loads, and on the native/fallback paths
getQualityLevel(): number; // selected id, -1 = Auto
getActiveQualityLevel(): number | null; // the level playing right now (useful in Auto)
setQualityLevel(id: number): void; // -1 = Auto; persisted under rememberQualityKey

qualitychange fires when the levels load or are cleared, when the selection changes, and when hls.js switches the level that is playing. getHls() returns the hls.js instance (or null) if you need lower-level access.

Error handling

  • Fatal network error after the manifest loaded: hls.startLoad() is retried once.
  • Fatal media error: hls.recoverMediaError() is tried once.
  • Anything else, or a repeated failure: hls.js is destroyed and the adapter switches to fallbackSrc (if given), keeping the current time and paused state. The position is restored with the adapter's own seek(), so the player receives programmaticSeek, not a user seek. Levels become [] and qualitychange fires.
  • On the native HLS path, a <video> error event switches to fallbackSrc in the same way.

Expiring links

Signed URLs expire. Pass refreshSource and the adapter asks for fresh URLs, then reloads from where playback is (same position and play state); through hls.js this is a brief stall, not a restart. It refreshes when a stream request is rejected with 401/403, when hls.js gives up on a network error (object storage often rejects expired segment URLs without CORS headers, which the browser reports as a failed request rather than a 403), and when a plain or fallback video fails to load. It refreshes at most once every 30 seconds (REFRESH_COOLDOWN_MS), so links that still fail when fresh go through the usual handling above, as does a refresh that rejects.

new HlsVideoAdapter(video, {
  src: hlsUrl,
  fallbackSrc: mp4Url,
  refreshSource: async () => {
    const lesson = await api.getLesson(id); // re-signed URLs
    return { src: lesson.hlsUrl, fallbackSrc: lesson.mp4Url };
  },
});

License

ISC