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') 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
{ "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
Reference | URL |
---|---|
node-sonos | https://www.npmjs.com/package/sonos |