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

@napplet/nub-media

v0.2.1

Published

NUB-MEDIA message types for media session control and playback

Readme

@napplet/nub-media

TypeScript message types, shim, and SDK helpers for the media NUB domain (media session control and playback).

Installation

npm install @napplet/nub-media

Overview

NUB-MEDIA provides media session management between napplets and the shell. Napplets that play audio or video create media sessions to expose playback state and metadata to the shell, which displays media controls and enforces audio policy.

Key features:

  1. Explicit session lifecycle -- create, update, and destroy sessions
  2. Multiple sessions per napplet -- each identified by a unique sessionId
  3. Dynamic capabilities -- napplets declare which actions they support, can change mid-session
  4. Dual volume -- napplet reports its volume, shell can adjust via command
  5. Shell control list -- shell tells napplet which controls it supports
  6. Rich metadata -- title, artist, album, artwork (URL or Blossom hash), duration, mediaType -- all optional

Message Types

All messages use the NIP-5D JSON envelope wire format ({ type: "media.<action>", ...payload }).

Napplet -> Shell

| Type | Payload | Description | |------|---------|-------------| | media.session.create | id, sessionId, metadata? | Create a new media session (correlated by id) | | media.session.update | sessionId, metadata | Update session metadata (fire-and-forget) | | media.session.destroy | sessionId | Destroy a session (fire-and-forget) | | media.state | sessionId, status, position?, duration?, volume? | Report playback state (fire-and-forget) | | media.capabilities | sessionId, actions[] | Declare supported actions (fire-and-forget) |

Shell -> Napplet

| Type | Payload | Description | |------|---------|-------------| | media.session.create.result | id, sessionId, error? | Result of session creation | | media.command | sessionId, action, value? | Shell sends playback command | | media.controls | controls[] | Shell pushes its supported control list |

Usage

import type {
  MediaSessionCreateMessage,
  MediaCommandMessage,
  MediaNubMessage,
  MediaMetadata,
  MediaAction,
} from '@napplet/nub-media';

import { DOMAIN } from '@napplet/nub-media';
// DOMAIN === 'media'

Shim API

import {
  createSession,
  updateSession,
  destroySession,
  reportState,
  reportCapabilities,
  onCommand,
  onControls,
} from '@napplet/nub-media';

// Create a session
const { sessionId } = await createSession({
  title: 'My Song',
  artist: 'The Artist',
  artwork: { hash: 'abc123...' },
});

// Report playback state
reportState(sessionId, {
  status: 'playing',
  position: 42.5,
  duration: 240,
  volume: 0.8,
});

// Declare capabilities
reportCapabilities(sessionId, ['play', 'pause', 'seek', 'volume']);

// Listen for shell commands
const sub = onCommand(sessionId, (action, value) => {
  if (action === 'pause') player.pause();
  if (action === 'seek') player.seekTo(value);
  if (action === 'volume') player.setVolume(value);
});

// Listen for shell control list
const ctrlSub = onControls(sessionId, (controls) => {
  showNextButton = controls.includes('next');
});

// Clean up
sub.close();
ctrlSub.close();
destroySession(sessionId);

SDK Helpers

import {
  mediaCreateSession,
  mediaReportState,
  mediaReportCapabilities,
  mediaOnCommand,
  mediaDestroySession,
} from '@napplet/nub-media';

Supporting Types

interface MediaMetadata {
  title?: string;
  artist?: string;
  album?: string;
  artwork?: { url?: string; hash?: string };
  duration?: number;
  mediaType?: 'audio' | 'video';
}

type MediaAction = 'play' | 'pause' | 'stop' | 'next' | 'prev' | 'seek' | 'volume';

Artwork

The artwork field supports two forms:

  • url -- A direct URL to the artwork image
  • hash -- A Blossom hash (SHA-256) the shell can resolve via its Blossom servers

If both are provided, the shell MAY prefer either.

Domain Registration

Importing @napplet/nub-media automatically registers the 'media' domain with the core dispatch singleton via registerNub(). This ensures dispatch.getRegisteredDomains() includes 'media'.

Protocol Reference

License

MIT