-
-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathevents.js
61 lines (50 loc) · 1.78 KB
/
events.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
59
60
61
const Sonos = require('../').Sonos
const listener = require('../').Listener
const sonos = new Sonos(process.env.SONOS_HOST || '192.168.96.56')
console.log('Listen for sonos events. CTRL + C to exit')
// Subscribe to global events. They are emitted on the listener.
listener.on('AlarmClock', result => {
console.log('Alarms changed event %j', result)
})
listener.on('ZoneGroupTopology', result => {
console.log('Zone group topology event, got info about all current groups')
})
// Manually subscribe to a events from a sonos speaker
listener.subscribeTo(sonos).then(result => {
console.log('Manually subscribed to sonos events')
})
// Or start listening for events on the sonos itself, will call the listener in the background
sonos.on('CurrentTrack', track => {
console.log('Track changed to %s by %s', track.title, track.artist)
})
sonos.on('NextTrack', track => {
console.log('The next track will be %s by %s', track.title, track.artist)
})
sonos.on('Volume', volume => {
console.log('New Volume %d', volume)
})
sonos.on('Mute', isMuted => {
console.log('This speaker is %s.', isMuted ? 'muted' : 'unmuted')
})
sonos.on('PlayState', state => {
console.log('The state changed to %s.', state)
})
sonos.on('AVTransport', transport => {
console.log('AVTransport event %j', transport)
})
sonos.on('QueueChanged', data => {
console.log('QueueChanged event %j', data)
})
// Subscribe to the CTRL + C event and cancel the current subscribtions
process.on('SIGINT', () => {
console.log('Hold-on cancelling all subscriptions')
listener.stopListener().then(result => {
console.log('Cancelled all subscriptions')
process.exit()
}).catch(err => {
console.log('Error cancelling subscriptions, exit in 3 seconds %s', err)
setTimeout(() => {
process.exit(1)
}, 2500)
})
})