Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spotify-playback-sdk

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spotify-playback-sdk

This package is an improved version of flam3rboy's -> https://github.com/Flam3rboy/spotify-playback-sdk-node.git

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

spotify-playback-sdk

An inofficial NodeJS Wrapper for the Spotify Web Playback SDK

This package is an improved version of flam3rboy's package

Installation

npm i spotify-playback-sdk
# or "yarn add spotify-playback-sdk"

Usage

ES5 import

require("spotify-playback-sdk");

or ES6 import

import "spotify-playback-sdk";

Example

const { SpotifyPlaybackSDK } = require("spotify-playback-sdk");

async function test() {
	const spotify = new SpotifyPlaybackSDK();
	await spotify.init({ /* puppeteerLaunchArgs */ });

	const player = await spotify.createPlayer({
		name: "Web",
		getOAuthToken() {
			// get your Access token here: https://developer.spotify.com/documentation/web-playback-sdk/quick-start/
			return "";
		},
	});
	player.on("player_state_changed", console.log);

	const stream = await player.getAudio();
	const connected = await player.connect();
	if (!connected) throw "couldn't connect";

	console.log("connected", stream);
}

test();

Reference

Spotify Web Playback SDK

class SpotifyPlaybackSDK {
	browser: Browser;
	constructor();
	init(opts?: LaunchOptions): Promise<this>;
	createPlayer(opts: PlayerOptions)       : Promise<SpotifyPlayer>;
	destroy()                               : Promise<void>;
}

type PlayerOptions = {
	name: string;
	volume?: number;
	getOAuthToken: () => string | Promise<string>;
};

class SpotifyPlayer extends EventEmitter {
	page: Page;
	opts: PlayerOptions;

	constructor      // use the SpotifyPlaybackSDK.createPlayer() function
	getAudio()       : Promise<import("puppeteer-stream").Stream>;
	connect()        : Promise<boolean>;
	disconnect()     : Promise<void>;
	getCurrentState(): Promise<WebPlaybackState>;
	getVolume()      : Promise<number>;
	pause()          : Promise<void>;
	resume()         : Promise<void>;
	togglePlay()     : Promise<void>;
	previousTrack()  : Promise<void>;
	nextTrack()      : Promise<void>;

	setName(name: string)    : Promise<void>;
	setVolume(volume: string): Promise<void>;
	seek(position_ms: number): Promise<void>;

	on(event: "ready",                listener: (opts: WebPlaybackPlayer) => any): this;
	on(event: "not_ready",            listener: (opts: WebPlaybackPlayer) => any): this;
	on(event: "player_state_changed", listener: (opts: WebPlaybackState) => any) : this;
	on(event: "initialization_error", listener: (opts: WebPlaybackError) => any) : this;
	on(event: "authentication_error", listener: (opts: WebPlaybackError) => any) : this;
	on(event: "account_error",        listener: (opts: WebPlaybackError) => any) : this;
	on(event: "playback_error",       listener: (opts: WebPlaybackError) => any) : this;
	on(event: string,                 listener: Function)                        : this;
}

Keywords

FAQs

Package last updated on 04 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc