Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/spotify

src/exports/playback-state.ts

17 lines · 729 B · TypeScript
import { getPlaybackState, normalizePlaybackState } from '../lib/spotify-api.ts'
import type { PlaybackStateParams } from '../lib/export-types.ts'

/**
 * Read the current Spotify playback state.
 * @returns Normalized playback, or `{ ok: true, nothing_playing: true }` when idle.
 * @example
 * import playbackState from 'kody:@kody/spotify/playback-state'
 * const state = await playbackState()
 */
export default async function playbackState(params: PlaybackStateParams = {}) {
	const result = await getPlaybackState(params)
	if (result.nothingPlaying) {
		return { ok: true, nothing_playing: true, integration: result.integration }
	}
	return { ...normalizePlaybackState(result.playback), integration: result.integration }
}