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

@z-torrent/host-sdk

v0.0.1

Published

PostMessage SDK for z-torrent hosted sites to request torrent content from the parent portal

Readme

@z-torrent/host-sdk

Lightweight postMessage SDK: sites running inside the Z-Torrent portal iframe can ask the parent window to add a torrent to the shared client and receive file URLs for streaming (e.g. <video src>).

Requirements

  • Browser only (the constructor throws if window is undefined).
  • add() must run inside a nested iframe (window.parent !== window). If the page is top-level, isEmbedded is false and add() rejects.

Installation

npm install @z-torrent/host-sdk
# or
bun add @z-torrent/host-sdk

In the Z-Torrent monorepo: "@z-torrent/host-sdk": "workspace:*".

The package is built as browser ESM; consume it through your bundler (Vite, Astro, etc.), like examples/sintel-web.

Quick example

import { ZTorrentHost } from '@z-torrent/host-sdk'

const host = new ZTorrentHost()

if (!host.isEmbedded) {
  console.warn('Not in portal iframe — add() is unavailable')
} else {
  try {
    const { infoHash, files } = await host.add(magnetURI, {
      timeout: 120_000,
      onProgress(p) {
        console.log(p.phase, p.progress, p.peers)
      },
    })

    const video = document.querySelector('video')
    if (video && files['Sintel.mp4']) {
      video.src = files['Sintel.mp4']
      void video.play()
    }
  } catch (e) {
    console.error(e)
  }
}

// On teardown / component unmount:
host.destroy()

files maps torrent file names to paths like /z-torrent/<infoHash>/<path-in-torrent> relative to the portal origin. The portal Service Worker intercepts those requests and serves bytes from the client.

API

ZTorrentHost

| Member | Description | | --- | --- | | Constructor | Registers a message listener. | | isEmbedded: boolean | true when embedded (window.parent !== window). | | add(magnetURI: string, opts?: AddTorrentOptions): Promise<AddTorrentResult> | Sends a request to the parent; default timeout 120 seconds. | | destroy(): void | Removes the listener and rejects pending requests. |

AddTorrentOptions

  • timeout?: number — response timeout in ms (default 120_000).
  • onProgress?: (p: TorrentProgress) => void — progress callback from the portal.

TorrentProgress

  • phase: 'connecting' | 'metadata' | 'downloading' | 'ready'
  • progress: 0–1
  • downloadSpeed: bytes per second
  • peers: peer count
  • downloaded, totalSize: bytes

AddTorrentResult

  • infoHash: string
  • files: Record<string, string> — torrent file name → path URL usable in the iframe document

PostMessage protocol

Message types use the z-torrent: prefix. Useful if you implement a custom portal compatible with this SDK.

| Direction | type | Payload (key fields) | | --- | --- | --- | | iframe → parent | z-torrent:add-torrent | id, magnetURI | | parent → iframe | z-torrent:torrent-added | id, infoHash, files | | parent → iframe | z-torrent:torrent-progress | id, same fields as TorrentProgress | | parent → iframe | z-torrent:torrent-error | id, error |

The SDK uses postMessage(..., '*'). The parent portal should validate event.origin and, when replying, prefer a concrete targetOrigin instead of *.

Reference handler: examples/web-portal/src/components/Viewer.svelte.

Further reading

License

MIT