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

windows-media-sessions

v1.0.3

Published

Read Windows Global System Media Transport Controls (GSMTC / SMTC) sessions from Node.js. Pure stdio bridge to a self-contained .NET 8 backend — no native addons.

Readme

windows-media-sessions

Read every active media session that Windows knows about — the same data that powers the media keys on your keyboard, the volume flyout, and the lock screen.

  • Pure stdio bridge to a self-contained .NET 8 backend — no native node addons, no node-gyp, no rebuild step on npm install.
  • Works under CommonJS and ESM, ships full TypeScript typings.
  • Streams live updates (SessionsChanged, MediaPropertiesChanged, PlaybackInfoChanged, TimelinePropertiesChanged).
  • Crash-resistant: the backend is respawned with exponential backoff if it dies.
  • Compatible with Electron's main process.

Install

npm install windows-media-sessions

Requires Windows 10 build 17763+ (the GSMTC API minimum) and Node 20+.

Usage

import {
  getAllSessions,
  getActiveSessions,
  onSessionsChanged,
} from 'windows-media-sessions';

// Every session Windows knows about, regardless of state.
const all = await getAllSessions();
console.log(all);

// Only the sessions currently in 'playing' state.
const active = await getActiveSessions();
for (const s of active) {
  console.log(s.sourceAppDisplayName, '—', s.title);
}

// Stream live updates
const stop = onSessionsChanged((sessions) => {
  console.log(`${sessions.length} session(s)`);
});

// Later…
stop();

API

getAllSessions(): Promise<MediaSession[]>

Resolves with a snapshot of every session Windows is currently tracking, regardless of playbackStatus (playing, paused, stopped, ...).

getActiveSessions(): Promise<MediaSession[]>

Resolves with the subset of sessions whose playbackStatus === 'playing'. Equivalent to filtering getAllSessions() manually.

onSessionsChanged(cb): Unsubscribe

Subscribes to live updates. The callback fires with a fresh array on every backend snapshot (debounced). Returns a function that detaches the listener.

shutdown(): Promise<void>

Stops the backend and disposes the internal manager. Most apps never need to call this; Electron apps may want to invoke it on before-quit.

Types

type PlaybackStatus =
  | 'closed' | 'opened' | 'changing'
  | 'stopped' | 'playing' | 'paused';

interface MediaSession {
  id: string;
  sourceAppUserModelId: string;
  title?: string;
  artist?: string;
  albumTitle?: string;
  genres?: string[];
  playbackStatus: PlaybackStatus;
  timeline?: { positionMs?: number; durationMs?: number };
  controls?: {
    canPlay: boolean;
    canPause: boolean;
    canSkipNext: boolean;
    canSkipPrevious: boolean;
  };
}

How it works

The package ships a tiny windows-media-sessions-backend.exe (a self-contained .NET 8 single-file binary, ~15 MB) under bin/win-x64/. On the first API call Node spawns the executable and listens for line-delimited JSON on its stdout. The backend hooks the Windows GlobalSystemMediaTransportControlsSessionManager and re-emits a full snapshot each time anything changes. See docs/PROTOCOL.md for the wire contract.

Electron

Works out of the box in the main process. Forward to the renderer through ipcMain / contextBridge like any other Node API. Pair with onSessionsChanged plus webContents.send('sessions', …) to drive a now-playing widget.

Troubleshooting

  • Backend executable not found — install missed the binary, or you cloned the repo without running npm run build:backend. Point at a custom binary via WINDOWS_MEDIA_SESSIONS_BACKEND=path\to\backend.exe.
  • Empty session list — most apps register an SMTC session only when they start playing. Hit play in Spotify / Edge / Groove first.
  • Linux / macOS — unsupported. The package errors out on import.

License

MIT