lib/sonos.js
function Sonos (host, port, options) {
  this.host = host
  this.port = port || 1400
  this.options = options || {}
  if (!this.options.endpoints) this.options.endpoints = {}
  if (!this.options.endpoints.transport) this.options.endpoints.transport = TRANSPORT_ENDPOINT
  if (!this.options.endpoints.rendering) this.options.endpoints.rendering = RENDERING_ENDPOINT
  if (!this.options.endpoints.device) this.options.endpoints.device = DEVICE_ENDPOINT

  this.options.spotify = this.options.spotify || {}
  this.options.spotify.region = this.options.spotify.region || SpotifyRegion.US

  // Attach to newListener event
  var self = this
  var implicitListen = async function (event, listener) {
    if (event === 'newListener') return
    self.removeListener('newListener', implicitListen)
    return Listener.subscribeTo(self).catch(err => {
      debug('Error subscribing to listener %j', err)
    })
  }
  this.on('newListener', implicitListen)
  // Maybe stop the eventListener once last listener is removed?
}
function Sonos (host, port, options) {
  this.host = host
  this.port = port || 1400
  this.options = options || {}
  if (!this.options.endpoints) this.options.endpoints = {}
  if (!this.options.endpoints.transport) this.options.endpoints.transport = TRANSPORT_ENDPOINT
  if (!this.options.endpoints.rendering) this.options.endpoints.rendering = RENDERING_ENDPOINT
  if (!this.options.endpoints.device) this.options.endpoints.device = DEVICE_ENDPOINT

  this.options.spotify = this.options.spotify || {}
  this.options.spotify.region = this.options.spotify.region || SpotifyRegion.US

  // Attach to newListener event
  var self = this
  var implicitListen = async function (event, listener) {
    if (event === 'newListener') return
    self.removeListener('newListener', implicitListen)
    return Listener.subscribeTo(self).catch(err => {
      debug('Error subscribing to listener %j', err)
    })
  }
  this.on('newListener', implicitListen)
  // Maybe stop the eventListener once last listener is removed?
}
function Sonos ( host , port , options ) { this . host = host this . port = port || 1400 this . options = options || { } if ( ! this . options . endpoints ) this . options . endpoints = { } if ( ! this . options . endpoints . transport ) this . options . endpoints . transport = TRANSPORT_ENDPOINT if ( ! this . options . endpoints . rendering ) this . options . endpoints . rendering = RENDERING_ENDPOINT if ( ! this . options . endpoints . device ) this . options . endpoints . device = DEVICE_ENDPOINT this . options . spotify = this . options . spotify || { } this . options . spotify . region = this . options . spotify . region || SpotifyRegion . US // Attach to newListener event var self = this var implicitListen = async function ( event , listener ) { if ( event === 'newListener' ) return self . removeListener ( 'newListener' , implicitListen ) return Listener . subscribeTo ( self ) . catch ( err => { debug ( 'Error subscribing to listener %j' , err ) } ) } this . on ( 'newListener' , implicitListen ) // Maybe stop the eventListener once last listener is removed? }
Create an instance of Sonos
@class Sonos
@param {String} host IP/DNS
@param {Number} port
@returns {Sonos}
Create an instance of Sonos