Skip to content

range-source-web 1.1.0

Choose a tag to compare

@danielkpl2 danielkpl2 released this 23 Oct 02:28
· 1 commit to main since this release
  • A Service Worker for media elements. <video> and <audio> make their own requests, so what they played skipped the reader and the store. The worker answers them: from the store first, fetching what's missing by range and storing it, so a file played through plays again with no requests, offline too.
    • The page registers it before rendering with registerRangeSourceWorker('/range-source-sw.js'), which resolves once the worker controls the page (claiming it again after a hard reload), and gives elements serviceWorkerUrl(src, { namespace, key, storage, maxBytes, headers }), a URL on the page's origin that the worker answers. rangeSourceWorker() tells whether one controls the page.
    • It sends the page's headers for the element, and plays a Blob, bytes or a ByteSource the page holds, whose ranges the page reads and passes on. A file on another origin without CORS is passed through, unstored.
    • The package ships the worker as dist/range-source-sw.js (export range-source-web/range-source-sw.js). An app with its own worker adds the handler from range-source-web/sw (installRangeSourceWorker, handleRangeSourceFetch) or importScripts the script.
  • Stores are shared between pages, tabs and the worker: blocks written and keys deleted are announced on a BroadcastChannel, and a key open in any of them isn't evicted (Web Locks).
  • SourceInfo.contentType, from the response's Content-Type or the Blob's type.
  • httpSource's openAt option: the first request starts there rather than at 0.
  • ByteReader.stored(): resolves once the blocks read so far are in the store.
  • npm run test:browsers: the worker in Chromium, Firefox and WebKit through Playwright.
  • The package includes this changelog.

Install: npm install range-source-web@1.1.0. Only range-source-web changed; the native packages stay at 1.0.0.