This package is a fork and a extension of the Node Spotify Web Helper module: https://github.com/nadavbar/node-spotify-webhelper It keeps the same interface as described in the docs below and extend it to use a port scanner to detect Spotify open ports that supports Spotify local protocol.
Node.js interface for the Spotify WebHelper API, based on this great article: http://cgbystrom.com/articles/deconstructing-spotifys-builtin-http-server/
The API interacts with the SpotifyWebHelper process via HTTP. For windows, the module checks whether SpotifyWebHelper.exe is running, and try to run it if not.
This module exposes the SpotifyWebHelper object, which exposes the following methods:
- getStatus (cb : function(err, res)) - get current status information (name of song/artist which is currently playing, etc..)
- pause (cb : function(err, res)) - pause currently playing song
- unpause (cb : function(err, res)) - unpause currently playing song
- play (spotifyurl : string, cb : function(err, res)) - play the given spotify url
- Constructor (port : number (optional)) - Creates a new SpotifyWebHelper object, default port to communicate with the SpotifyWebHelper is 4370, other port can be specified when creating the object.
Examples - Get Status
var SpotifyWebHelper = ;var spotify = ;// get the name of the song which is currently playingspotify;
Examples - Port detection The following example will detect open ports for Spotify desktop applications. To detect open ports a forked and modified port scanner node module has been used: https://github.com/baalexander/node-portscanner
Each of those ports respond to the Spotify local protocol and can be used to communicate to Spotify desktop application on the same host.
var SpotifyWebHelper = ;var spotifyClient = ; // init with default portspotifyClient;
lowPort is the lower port number,
highPort is the higher port number,
timeout is the socket timeout for the port in
An example of the ouput. A json containing a
port number and an
error field if any like:
Examples - Connect to a specific port As soon as a port is known to work, the Spotify Web Helper can be instantiated with that port to correctly communicate to Spotify running application on the same host:
var SpotifyWebHelper = ;console;var spotifyClient = port : openPort ;spotifyClient;return console;});
Examples - Auto detect an open port and connect
To automatically detect an open port and connect to this one, use the
autoDectect option set to true.
var SpotifyWebHelper = ;var spotifyClient = autoDectect : true ; // init with default portspotifyClient;
examples/ folder for more examples and code.