lib/spotify.js
function Spotify () {
  if (!(this instanceof Spotify)) return new Spotify();
  EventEmitter.call(this);

  this.seq = 0;
  this.heartbeatInterval = 18E4; // 180s, from "spotify.web.client.js"
  this.agent = superagent.agent();
  this.connected = false; // true after the WebSocket "connect" message is sent
  this._callbacks = Object.create(null);

  this.authServer = 'play.spotify.com';
  this.authUrl = '/xhr/json/auth.php';
  this.landingUrl = '/';
  this.userAgent = 'Mozilla/5.0 (Chrome/13.37 compatible-ish) spotify-web/' + pkg.version;

  // base URLs for Image files like album artwork, artist prfiles, etc.
  // these values taken from "spotify.web.client.js"
  this.sourceUrl = 'https://d3rt1990lpmkn.cloudfront.net';
  this.sourceUrls = {
    tiny:   this.sourceUrl + '/60/',
    small:  this.sourceUrl + '/120/',
    normal: this.sourceUrl + '/300/',
    large:  this.sourceUrl + '/640/',
    avatar: this.sourceUrl + '/artist_image/'
  };

  // mappings for the protobuf `enum Size`
  this.sourceUrls.DEFAULT = this.sourceUrls.normal;
  this.sourceUrls.SMALL = this.sourceUrls.tiny;
  this.sourceUrls.LARGE = this.sourceUrls.large;
  this.sourceUrls.XLARGE = this.sourceUrls.avatar;

  // WebSocket callbacks
  this._onopen = this._onopen.bind(this);
  this._onclose = this._onclose.bind(this);
  this._onmessage = this._onmessage.bind(this);

  // start the "heartbeat" once the WebSocket connection is established
  this.once('connect', this._startHeartbeat);

  // handle "message" commands...
  this.on('message', this._onmessagecommand);

  // needs to emulate Spotify's "CodeValidator" object
  this._context = vm.createContext();
  this._context.reply = this._reply.bind(this);

  // binded callback for when user doesn't pass a callback function
  this._defaultCallback = this._defaultCallback.bind(this);
}
function Spotify () {
  if (!(this instanceof Spotify)) return new Spotify();
  EventEmitter.call(this);

  this.seq = 0;
  this.heartbeatInterval = 18E4; // 180s, from "spotify.web.client.js"
  this.agent = superagent.agent();
  this.connected = false; // true after the WebSocket "connect" message is sent
  this._callbacks = Object.create(null);

  this.authServer = 'play.spotify.com';
  this.authUrl = '/xhr/json/auth.php';
  this.landingUrl = '/';
  this.userAgent = 'Mozilla/5.0 (Chrome/13.37 compatible-ish) spotify-web/' + pkg.version;

  // base URLs for Image files like album artwork, artist prfiles, etc.
  // these values taken from "spotify.web.client.js"
  this.sourceUrl = 'https://d3rt1990lpmkn.cloudfront.net';
  this.sourceUrls = {
    tiny:   this.sourceUrl + '/60/',
    small:  this.sourceUrl + '/120/',
    normal: this.sourceUrl + '/300/',
    large:  this.sourceUrl + '/640/',
    avatar: this.sourceUrl + '/artist_image/'
  };

  // mappings for the protobuf `enum Size`
  this.sourceUrls.DEFAULT = this.sourceUrls.normal;
  this.sourceUrls.SMALL = this.sourceUrls.tiny;
  this.sourceUrls.LARGE = this.sourceUrls.large;
  this.sourceUrls.XLARGE = this.sourceUrls.avatar;

  // WebSocket callbacks
  this._onopen = this._onopen.bind(this);
  this._onclose = this._onclose.bind(this);
  this._onmessage = this._onmessage.bind(this);

  // start the "heartbeat" once the WebSocket connection is established
  this.once('connect', this._startHeartbeat);

  // handle "message" commands...
  this.on('message', this._onmessagecommand);

  // needs to emulate Spotify's "CodeValidator" object
  this._context = vm.createContext();
  this._context.reply = this._reply.bind(this);

  // binded callback for when user doesn't pass a callback function
  this._defaultCallback = this._defaultCallback.bind(this);
}
function Spotify ( ) { if ( ! ( this instanceof Spotify ) ) return new Spotify ( ) ; EventEmitter . call ( this ) ; this . seq = 0 ; this . heartbeatInterval = 18E4 ; // 180s, from "spotify.web.client.js" this . agent = superagent . agent ( ) ; this . connected = false ; // true after the WebSocket "connect" message is sent this . _callbacks = Object . create ( null ) ; this . authServer = 'play.spotify.com' ; this . authUrl = '/xhr/json/auth.php' ; this . landingUrl = '/' ; this . userAgent = 'Mozilla/5.0 (Chrome/13.37 compatible-ish) spotify-web/' + pkg . version ; // base URLs for Image files like album artwork, artist prfiles, etc. // these values taken from "spotify.web.client.js" this . sourceUrl = 'https://d3rt1990lpmkn.cloudfront.net' ; this . sourceUrls = { tiny : this . sourceUrl + '/60/' , small : this . sourceUrl + '/120/' , normal : this . sourceUrl + '/300/' , large : this . sourceUrl + '/640/' , avatar : this . sourceUrl + '/artist_image/' } ; // mappings for the protobuf `enum Size` this . sourceUrls . DEFAULT = this . sourceUrls . normal ; this . sourceUrls . SMALL = this . sourceUrls . tiny ; this . sourceUrls . LARGE = this . sourceUrls . large ; this . sourceUrls . XLARGE = this . sourceUrls . avatar ; // WebSocket callbacks this . _onopen = this . _onopen . bind ( this ) ; this . _onclose = this . _onclose . bind ( this ) ; this . _onmessage = this . _onmessage . bind ( this ) ; // start the "heartbeat" once the WebSocket connection is established this . once ( 'connect' , this . _startHeartbeat ) ; // handle "message" commands... this . on ( 'message' , this . _onmessagecommand ) ; // needs to emulate Spotify's "CodeValidator" object this . _context = vm . createContext ( ) ; this . _context . reply = this . _reply . bind ( this ) ; // binded callback for when user doesn't pass a callback function this . _defaultCallback = this . _defaultCallback . bind ( this ) ; }
Spotify Web base class.

@api public
Spotify Web base class .