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

@spelljam/audio-engine

v3.0.0

Published

A Spotify-backed theme-driven ambient music engine for browser environments.

Readme

@spelljam/audio-engine

A Spotify-backed theme-driven ambient music engine for browser environments. Send it a Scene; it selects and plays appropriate music from Spotify.

Project: SpellJam
Repository: spelljam-audio-engine
npm package: @spelljam/audio-engine


Purpose and Scope

This package is the audio control layer of the SpellJam ecosystem. Its responsibility is to accept a Scene object and coordinate playback via the Spotify Web API.

A Scene has two independent dimensions:

  • mood — emotional and musical character.
  • atmosphere — environmental colour.

The engine uses a TrackCatalog to map mood and atmosphere combinations to specific Spotify tracks.

Spotify Integration

This library requires a Spotify Premium account for playback and a registered Spotify Application to obtain a clientId. It uses the PKCE auth flow for secure, client-side authentication.


Features

  • Spotify-Driven Playback: Leverages the vast Spotify library for high-quality ambient music.
  • Scene-Driven Selection: Automatically selects tracks based on the current mood and atmosphere.
  • Intelligent Queueing: Automatically queues related tracks (e.g., from the same album) to ensure continuous playback.
  • History Management: Avoids immediate repetition of tracks.
  • Master Control: unified API for volume, playback state, and device management.

Repository Structure

spelljam-audio-engine/
├── src/
│   ├── index.ts                 ← public API — re-exports only
│   ├── types.ts                 ← Scene, Mood, Atmosphere, etc.
│   ├── api/                     ← Spotify Web API client
│   ├── auth/                    ← Spotify PKCE authentication logic
│   ├── catalog/                 ← Track mapping and selection logic
│   └── controller/              ← Main SpotifyController factory

Scene Vocabulary

Moods

| Mood | Example D&D context | | --------------- | ------------------------------------- | | "peaceful" | Safe rest, gentle downtime | | "exploration" | Traveling, discovering new locations | | "suspense" | Tense moments, investigation | | "battle" | Combat encounters | | "boss" | Major set pieces, epic confrontations | | "tavern" | Inns, social gatherings | | "town" | Busy streets, markets | | "melancholy" | Sadness, loss, aftermath | | "triumph" | Victory, positive resolutions | | "mystical" | Magic, wonder, fey realms |

Atmospheres

| Atmosphere | Example D&D context | | ---------------- | ----------------------------------- | | "forest" | Woods, nature | | "cave" | Underground, natural caverns | | "rain" | Light to moderate precipitation | | "storm" | Heavy rain, thunder | | "ocean" | Seaside, on a boat | | "city" | Urban environments | | "tavern_crowd" | Busy indoor social setting | | "magic" | Arcane resonance, spellcasting | | "fire" | Campfires, burning buildings | | "desert" | Hot, dry, sandy regions | | "swamp" | Wetlands, marshes | | "snow" | Cold, wintry conditions | | "mountains" | High altitude, rocky terrain | | "dungeon" | Worked stone, oppressive atmosphere | | "night" | Nocturnal environments | | null | No specific atmosphere |


Usage

Initializing the Controller

import { createSpotifyController } from '@spelljam/audio-engine';

const controller = createSpotifyController({
  clientId: 'YOUR_SPOTIFY_CLIENT_ID',
  redirectUri: 'YOUR_REDIRECT_URI',
  scopes: ['streaming', 'user-read-playback-state', 'user-modify-playback-state'],
});

// Start auth flow
if (!controller.isAuthenticated()) {
  await controller.authenticate();
}

Updating the Scene

// Update everything
await controller.setScene({
  mood: 'battle',
  atmosphere: 'dungeon',
});

// Change mood only
await controller.setMood('boss');

// Change atmosphere only
await controller.setAtmosphere('fire');

Playback Control

await controller.play();
await controller.pause();
await controller.setVolume(50); // 0-100
await controller.next();

Development

npm install
npm run build
npm test