Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
const { DeviceDiscovery } = require('sonos')
const { Sonos } = require('sonos')

// event on all found...
DeviceDiscovery((device) => {
  console.log('found device at ' + device.host)
 
  // mute every device...
  device.setMuted(true)
    .then(d => console.log(`${d.host} now muted`))
})
 
// find one device
DeviceDiscovery().once('DeviceAvailable', (device) => {
  console.log('found device at ' + device.host)
 
  // get all groups
  sonos = new Sonos(device.host)
  sonos.getAllGroups().then(groups => {
    groups.forEach(group => {
      console.log(group.Name);
    })
  })
})


Run it

> node discover.js


If you want to add it to npm, edit the package.json file

Code Block
{
  "name": "sonosplayer",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node discover.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "sonos": "git://github.com/bencevans/node-sonos.git"
  }
}




References

...