-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·58 lines (52 loc) · 1.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
var sonos = require('sonos');
var _ = require('underscore');
var DialServer = require('./lib/tube-server');
var sonosPlayers = {};
var TIMEOUT = 2000 // Search for 2 seconds, increase this value if not all devices are shown
var SEARCH_INTERVAL = 60 * 1000; // Search for new Sonos device every minute
var PORT = 3100;
// Search and collect device information
function searchSonosDevices() {
sonos.search(function(device, model) {
var deviceData = {
ip: device.host,
port: device.port,
model: model
}
var ssdpStarted = false;
device.getZoneAttrs(function(err, attrs) {
if (!err) {
_.extend(deviceData, attrs)
}
device.getZoneInfo(function(err, info) {
if (!err) {
_.extend(deviceData, info)
}
device.getTopology(function(err, info) {
if (!err) {
info.zones.forEach(function(group) {
if (group.location === 'http://' + deviceData.ip + ':' + deviceData.port + '/xml/device_description.xml') {
_.extend(deviceData, group)
}
})
}
if (!sonosPlayers[deviceData.name] && deviceData.name === 'Ritinha') {
var d = new DialServer(deviceData, PORT++);
d.start(function() {
sonosPlayers[deviceData.name] = d;
});
}
})
});
})
})
}
var pjson = require('./package.json');
console.log('SonosTube - Stream from YouTube directly to your Sonos players v' + pjson.version + '\n');
console.log('Searching for Sonos devices...');
searchSonosDevices();
// Refresh the search
setInterval(function() {
searchSonosDevices();
}, SEARCH_INTERVAL);