From d350aac9d957bddc6a43572644363011d2574ced Mon Sep 17 00:00:00 2001 From: Stephen Wan Date: Fri, 5 Dec 2014 23:47:15 -0600 Subject: [PATCH 1/2] First pass at experimental logical device support --- lib/main.js | 140 ++++++++++++++++++++++++++-------------------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/lib/main.js b/lib/main.js index c6e5c78..4009817 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,91 +26,91 @@ if (flags.get('version')) { } else { console.log('Searching for Sonos devices on network...'); - sonos.search(function(device, model) { + sonos.LogicalDevice.search(function(err, devices) { + devices.forEach(function(device) { - if (model === 'BR100' || model === 'ANVIL') return; // ignore Sonos Bridge and Sub device + device.getZoneAttrs(function(err, zoneAttrs) { + if (err) throw err; - device.getZoneAttrs(function(err, zoneAttrs) { - if (err) throw err; + var deviceName = zoneAttrs.CurrentZoneName; - var deviceName = zoneAttrs.CurrentZoneName; + console.log('Setting up AirSonos for', deviceName, '{' + device.host + ':' + device.port + '}'); - console.log('Setting up AirSonos for', deviceName, '{' + device.host + ':' + device.port + '}'); - - var airplayServer = new NodeTunes({ - serverName: deviceName + ' (AirSonos)', - verbose: flags.get('verbose'), - controlTimeout: flags.get('timeout') - }); + var airplayServer = new NodeTunes({ + serverName: deviceName + ' (AirSonos)', + verbose: flags.get('verbose'), + controlTimeout: flags.get('timeout') + }); - var clientName = 'AirSonos'; - airplayServer.on('clientNameChange', function(name) { - clientName = 'AirSonos @ ' + name; - }); + var clientName = 'AirSonos'; + airplayServer.on('clientNameChange', function(name) { + clientName = 'AirSonos @ ' + name; + }); - airplayServer.on('error', function(err) { - if (err.code === 415) { - console.error('Warning!', err.message); - console.error('AirSonos currently does not support codecs used by applications such as iTunes or AirFoil.'); - console.error('Progress on this issue: https://github.com/stephen/nodetunes/issues/1'); - } else { - console.error('Unknown error:'); - console.error(err); - } - }) - - airplayServer.on('clientConnected', function(audioStream) { - - portastic.find({ - min : 8000, - max : 8050, - retrieve: 1 - }, function(err, port) { - if (err) throw err; - - var icecastServer = new Nicercast(audioStream, { - name: 'AirSonos @ ' + deviceName - }); + airplayServer.on('error', function(err) { + if (err.code === 415) { + console.error('Warning!', err.message); + console.error('AirSonos currently does not support codecs used by applications such as iTunes or AirFoil.'); + console.error('Progress on this issue: https://github.com/stephen/nodetunes/issues/1'); + } else { + console.error('Unknown error:'); + console.error(err); + } + }) + + airplayServer.on('clientConnected', function(audioStream) { + + portastic.find({ + min : 8000, + max : 8050, + retrieve: 1 + }, function(err, port) { + if (err) throw err; + + var icecastServer = new Nicercast(audioStream, { + name: 'AirSonos @ ' + deviceName + }); + + airplayServer.on('metadataChange', function(metadata) { + if (metadata.minm) + icecastServer.setMetadata(metadata.minm + (metadata.asar ? ' - ' + metadata.asar : '') + (metadata.asal ? ' (' + metadata.asal + ')' : '')); + }); + + airplayServer.on('clientDisconnected', function() { + icecastServer.stop(); + }); + + icecastServer.start(port); + + device.play({ + uri: 'x-rincon-mp3radio://' + ip.address() + ':' + port + '/listen.m3u', + metadata: '' + + '' + + '' + + '' + clientName + '' + + 'object.item.audioItem.audioBroadcast' + + 'SA_RINCON65031_' + + '' + + '' + }); - airplayServer.on('metadataChange', function(metadata) { - if (metadata.minm) - icecastServer.setMetadata(metadata.minm + (metadata.asar ? ' - ' + metadata.asar : '') + (metadata.asal ? ' (' + metadata.asal + ')' : '')); }); + }); - airplayServer.on('clientDisconnected', function() { - icecastServer.stop(); - }); + airplayServer.on('clientDisconnected', function() { + device.stop(function() {}); + }); - icecastServer.start(port); - - device.play({ - uri: 'x-rincon-mp3radio://' + ip.address() + ':' + port + '/listen.m3u', - metadata: '' + - '' + - '' + - '' + clientName + '' + - 'object.item.audioItem.audioBroadcast' + - 'SA_RINCON65031_' + - '' + - '' + airplayServer.on('volumeChange', function(vol) { + vol = 100 - Math.floor(-1 * (Math.max(vol, -30) / 30) * 100); + device.setVolume(vol, function() { + // ? }); - }); - }); - airplayServer.on('clientDisconnected', function() { - device.stop(function() {}); - }); + airplayServer.start(); - airplayServer.on('volumeChange', function(vol) { - vol = 100 - Math.floor(-1 * (Math.max(vol, -30) / 30) * 100); - device.setVolume(vol, function() { - // ? - }); }); - - airplayServer.start(); - }); }); From bb39390fd7cd61934a76ccccd95997958efeef74 Mon Sep 17 00:00:00 2001 From: Stephen Wan Date: Sun, 15 Feb 2015 17:19:43 -0800 Subject: [PATCH 2/2] Move to custom node-sonos package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d1e0607..4f8375c 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "nicercast": "0.0.7", "nodetunes": "0.1.2", "portastic": "0.0.1", - "sonos": "0.6.1", + "sonos": "git+ssh://git@github.com:stephen/node-sonos.git#stephen-1.0.0", "throttle": "~1.0.3" }, "license": "MIT"