You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »


Create Project 

mkdir sonosPlayer
cd sonosPlayer

npm init

npm install sonos

npm install git://github.com/bencevans/node-sonos.git


> vi discover.js

const { DeviceDiscovery } = 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



References

  • No labels