-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathevents.js
50 lines (40 loc) · 1.89 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
const SonosDevice = require('../lib/').SonosDevice
const ServiceEvents = require('../lib/models/service-event').ServiceEvents;
const SonosEvents = require('../lib/index').SonosEvents;
const kantoor = new SonosDevice(process.env.SONOS_HOST || '192.168.96.56', 1400, 'RINCON_000Esecret1400')
kantoor.Events.on(SonosEvents.Error, (err) => {
console.error('Subscribe error', err);
});
kantoor.Events.on(SonosEvents.CurrentTransportStateSimple, (state) => {
console.log('New State %s', state.toString());
})
kantoor.AlarmClockService.Events.on(ServiceEvents.ServiceEvent, data => {
console.log('AlarmClock data %s', JSON.stringify(data))
})
kantoor.ZoneGroupTopologyService.Events.on(ServiceEvents.Error, (err) => {
console.error('Subscribe error for ZoneGroupTopologyService', err);
})
kantoor.ZoneGroupTopologyService.Events.on(ServiceEvents.ServiceEvent, data => {
console.log('ZoneGroupTopology data %s', JSON.stringify(data))
})
kantoor.AVTransportService.Events.on(ServiceEvents.ServiceEvent, data => {
console.log('AVTransport lastchange %s', JSON.stringify(data, null, 2))
})
kantoor.RenderingControlService.Events.on(ServiceEvents.ServiceEvent, data => {
console.log('RenderingControl lastchange %s', JSON.stringify(data, null, 2))
})
setInterval(async () => {
const result = await kantoor.RefreshEventSubscriptions();
console.log('Succesfully refreshed the events %s', result)
}, 300 * 1000)
process.on('SIGINT', () => {
console.log('Hold-on cancelling all subscriptions')
kantoor.CancelEvents();
kantoor.AlarmClockService.Events.removeAllListeners(ServiceEvents.ServiceEvent)
kantoor.AVTransportService.Events.removeAllListeners(ServiceEvents.ServiceEvent)
kantoor.RenderingControlService.Events.removeAllListeners(ServiceEvents.ServiceEvent)
kantoor.ZoneGroupTopologyService.Events.removeAllListeners(ServiceEvents.ServiceEvent)
setTimeout(() => {
process.exit(0)
}, 3000)
})