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

@sonn-audio/node-sendspin

v0.6.2

Published

Nodejs implementation of the Sendspin protocol.

Readme

node-sendspin

TypeScript/Node.js implementation of the Sendspin protocol. It provides both server and client building blocks, tracks the reference implementation (aiosendspin), and is used by Sonn core — but is generic enough for other Sendspin deployments.

Runtime dependencies: ws. Noise encryption is implemented on node:crypto, so there is no crypto dependency to audit.

Install

npm install @sonn-audio/node-sendspin

Server

sendspinCore is a ready-made session manager: hand it WebSocket connections and it runs the handshake, tracks sessions per client, and gives you the calls to push streams, state, metadata and commands.

import { sendspinCore, Identity } from '@sonn-audio/node-sendspin';
import { WebSocketServer } from 'ws';

sendspinCore.configureServer({
  // Unique on the network and stable across restarts: a client with more than one
  // server tells them apart by this, so a constant like "server" makes every
  // installation indistinguishable.
  serverId: 'AA:BB:CC:DD:EE:FF',
  name: 'Living Room Audio',
});

const wss = new WebSocketServer({ port: 8927, path: '/sendspin' });
wss.on('connection', (ws, req) => sendspinCore.handleConnection(ws, req));

sendspinCore.registerHooks('client-id', {
  onIdentified: (session) => console.log('client ready', session.getRoles()),
  onPlayerState: (_session, update) => console.log('volume', update.volume),
  onGroupCommand: (_session, command) => console.log('command', command.command),
});

Per-session sends go through SendspinSession (or the sendspinCore.* shortcuts that take a clientId): sendStreamStart, sendPcmAudioFrame, sendMetadata, sendControllerState, sendColor, sendArtwork, the sendVisualizer* family, and sendServerCommand. Backpressure guards and per-client format negotiation are handled for you.

A player must send an initial client/state before its session counts as identified.

Encryption

Optional, and opt-in per connection: a client that opens with client/hello keeps the unencrypted (transition-mode) path, one that opens with client/init gets Noise.

import { sendspinCore, Identity } from '@sonn-audio/node-sendspin';

// Persist this. The public half is your `server_id` under encryption, so a new
// identity each boot makes you an unknown server to every client that knew you.
const identity = Identity.fromPrivateB64u(storedKey ?? (storedKey = Identity.generate().privateB64u));
sendspinCore.enableEncryption(identity);

With no PskProvider every client is admitted with the published Sentinel PSK. Be clear-eyed about what that buys: the connection is confidential and tamper-evident against a passive listener, but it authenticates nothing, because the static keys are exchanged in the clear on the same connection. That is what "unpaired access" means in the spec. Pass your own provider to admit clients on stored per-client PSKs instead:

sendspinCore.enableEncryption(identity, async (clientId) => lookupPairing(clientId));

Under encryption client_id is the client's static public key (43 chars, base64url), not a name it chose — a hello claiming a different id is refused. Anything keyed on a client id therefore has to hold the key, not a UUID.

Not implemented: pairing (dynamic PIN, static PIN, pairing PSK), the trust store, and the management/* messages. The source@v1 role requires a paired connection per spec, so it cannot be used over encryption yet.

Client

import { SendspinClient, Roles, AudioCodec, MediaCommand } from '@sonn-audio/node-sendspin';

const client = new SendspinClient('my-client-id', 'My Player', [Roles.PLAYER], {
  playerSupport: {
    supported_formats: [
      { codec: AudioCodec.PCM, channels: 2, sample_rate: 48000, bit_depth: 16 },
    ],
    buffer_capacity: 512 * 1024,
    supported_commands: [],
  },
  staticDelayMs: 75,
});

client.addStreamStartListener(() => console.log('Stream started'));
client.addAudioChunkListener((timestampUs, data, format) => {
  const playAt = client.computePlayTime(timestampUs);
  // schedule playback of `data` at `playAt` microseconds on your clock
});

await client.connect('ws://localhost:8927/sendspin');
await client.sendGroupCommand(MediaCommand.PLAY);

To connect over Noise, pass an identity. client_id is then the key and the constructor argument is ignored:

const client = new SendspinClient('unused', 'My Player', [Roles.PLAYER], {
  playerSupport: { /* ... */ },
  encryption: {
    identity,                    // persist it; it is your client_id
    expectedServerId: storedId,  // omit only if you accept an unauthenticated server
  },
});
await client.connect('wss://server/sendspin');
client.isEncrypted;        // true
client.admittedWith;       // PskCategory.SENTINEL
client.info?.serverId;     // taken from the handshake, not from server/hello

expectedServerId is what turns encryption into authentication. Without it an active man-in-the-middle can substitute its own keys in both directions; with it, only the server you paired with can complete the handshake.

Notes

  • SendspinTimeFilter provides Kalman-filtered clock sync at microsecond precision, and is reused by the client.
  • Helpers for packing/unpacking the 9-byte binary header (packBinaryHeaderRaw, unpackBinaryHeader).
  • SendspinServer / ServerClient are an older, separate server implementation, kept for compatibility. They do not speak encryption, do not stamp server_transmitted, and reject a client/init. Use sendspinCore for anything new.
  • Noise correctness is pinned by interop tests against noiseprotocol, the library the reference server uses — both cipher suites, both roles, comparing handshake hashes and round-tripping transport frames.

Migrating from 0.3.x

  • ControllerStatePayload now requires repeat and shuffle (they moved out of the metadata object) and accepts seek_max_ms.
  • stream/start, stream/clear and stream/end payloads carry a required server_transmitted, stamped at send. It is the start of the window a player's required_lead_time_ms is measured over.
  • Roles.VISUALIZER now means visualizer@v1. The legacy batched wire is Roles.VISUALIZER_DRAFT_R1. Roles.VISUALIZER_V1 remains as a deprecated alias.
  • MediaCommand.SELECT_SOURCE is gone; SEEK and SEEK_RELATIVE were added, carrying position_ms / offset_ms.
  • source@v1 follows the spec: the format is announced with client_stream/start (see the onSourceStreamStart hook) rather than in the hello support object, which no longer requires supported_formats.
  • client/state.available supersedes the state enum; the session resolves both and exposes isAvailable().

Building

npm install
npm run build

Compiled artifacts land in dist/ with type declarations for publishing to npm.