-
Notifications
You must be signed in to change notification settings - Fork 0
/
sonos.js
46 lines (41 loc) · 915 Bytes
/
sonos.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
'use strict';
const eventEmitter = require ('events').EventEmitter;
const event = new eventEmitter();
const color = require('./string-contains-color');
const player = require('sonos');
const rx = require('rx-lite');
// Find sonos
let sonos = [
{
name: "upstairs",
player: new player.Sonos('192.168.178.27'),
track: ""
},
{
name: "downstairs",
player: new player.Sonos('192.168.178.79'),
track: ""
}
];
// Find currently playing tracks
function checkCurrentlyPlaying (){
for (let i in sonos){
let zone = sonos[i];
zone.player.currentTrack(function(err, track){
if (zone.track !== track.title){
zone.track = track.title;
event.emit('changed', track.title);
}
})
}
};
function pollCurrentlyPlaying()
{
checkCurrentlyPlaying();
setInterval(checkCurrentlyPlaying, 3000);
return rx.Observable.fromEvent(
event,
'changed'
);
}
exports.currentTrack = pollCurrentlyPlaying;