Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #82 from stephen/logical-devices
Browse files Browse the repository at this point in the history
Logical Device support
  • Loading branch information
stephen committed Feb 16, 2015
2 parents 77ea639 + bb39390 commit 04a6fae
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 71 deletions.
140 changes: 70 additions & 70 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<?xml version="1.0"?>' +
'<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/">' +
'<item id="R:0/0/49" parentID="R:0/0" restricted="true">' +
'<dc:title>' + clientName + '</dc:title>' +
'<upnp:class>object.item.audioItem.audioBroadcast</upnp:class>' +
'<desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc>' +
'</item>' +
'</DIDL-Lite>'
});

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: '<?xml version="1.0"?>' +
'<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/">' +
'<item id="R:0/0/49" parentID="R:0/0" restricted="true">' +
'<dc:title>' + clientName + '</dc:title>' +
'<upnp:class>object.item.audioItem.audioBroadcast</upnp:class>' +
'<desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc>' +
'</item>' +
'</DIDL-Lite>'
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();

});

});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"nicercast": "0.0.8",
"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"
Expand Down

0 comments on commit 04a6fae

Please sign in to comment.