-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathuse-manager.js
64 lines (59 loc) · 2.67 KB
/
use-manager.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
62
63
64
const SonosManager = require('../lib').SonosManager
const SonosEvents = require('../lib/models/sonos-events').SonosEvents
const manager = new SonosManager()
// Switch on one of the following lines
// Do device discovery
// manager.InitializeWithDiscovery(120)
// Connect known device
manager.InitializeFromDevice(process.env.SONOS_HOST || '192.168.96.56')
.then(console.log)
.then(() => {
manager.Devices.forEach(d => {
console.log('Device %s (%s) is joined in %s', d.Name, d.Uuid, d.GroupName)
d.Events.on(SonosEvents.Coordinator, Uuid => {
console.log('Coordinator for %s changed to %s', d.Name, Uuid)
})
d.Events.on(SonosEvents.GroupName, newName => {
console.log('Group name for %s changed to %s', d.Name, newName)
})
d.Events.on(SonosEvents.CurrentTrack, uri => {
console.log('Current Track for %s %s', d.Name, uri)
})
d.Events.on(SonosEvents.CurrentTrackMetadata, metadata => {
console.log('Current Track metadata for %s %s', d.Name, JSON.stringify(metadata, null, 2))
})
d.Events.on(SonosEvents.NextTrack, uri => {
console.log('Next Track for %s %s', d.Name, uri)
})
d.Events.on(SonosEvents.NextTrackMetadata, metadata => {
console.log('Next Track metadata for %s %s', d.Name, JSON.stringify(metadata, null, 2))
})
d.Events.on(SonosEvents.CurrentTransportState, state => {
console.log('New state for %s %s', d.Name, state)
})
d.Events.on(SonosEvents.CurrentTransportStateSimple, state => {
console.log('New simple state for %s %s', d.Name, state)
})
})
// return manager.PlayNotification({
// trackUri: 'https://cdn.smartersoft-group.com/various/pull-bell-short.mp3', // Can be any uri sonos understands
// // trackUri: 'https://cdn.smartersoft-group.com/various/someone-at-the-door.mp3', // Cached text-to-speech file.
// onlyWhenPlaying: true, // make sure that it only plays when you're listening to music. So it won't play when you're sleeping.
// timeout: 10, // If the events don't work (to see when it stops playing) or if you turned on a stream, it will revert back after this amount of seconds.
// volume: 15, // Set the volume for the notification (and revert back afterwards)
// delayMs: 700 // Pause between commands in ms, (when sonos fails to play notification often).
// })
})
.catch(console.error)
manager.OnNewDevice((device) => {
console.log('New device found %s %s', device.Name, device.Uuid);
})
process.on('SIGINT', () => {
manager.Devices.forEach(d => {
d.CancelEvents()
})
manager.CancelSubscription()
setTimeout(() => {
process.exit(0)
}, 200)
})