-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
sonos.test.js
690 lines (605 loc) Β· 46.8 KB
/
sonos.test.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/* eslint-env mocha */
/* eslint no-unused-vars: "off" */
const assert = require('assert')
const SONOS = require('../')
const Sonos = SONOS.Sonos
const nock = require('nock')
const Helpers = require('../lib/helpers')
const generateResponse = function (responseTag, serviceName, responseBody) {
const soapBody = `<u:${responseTag} xmlns:u="urn:schemas-upnp-org:service:${serviceName}:1">${(responseBody || null)}</u:${responseTag}>`
return Helpers.CreateSoapEnvelop(soapBody)
}
const mockRequest = function (endpoint, action, requestBody, responseTag, serviceName, responseBody) {
return nock('http://localhost:1400', { reqheaders: { soapaction: action } })
.post(endpoint, Helpers.CreateSoapEnvelop(requestBody))
.reply(200, generateResponse(responseTag, serviceName, responseBody))
}
describe('Sonos - Mock', function () {
describe('play()', function () {
it('should generate play command', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#Play"',
'<u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play>',
'PlayResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
return sonos.play()
})
it('should accept a uri add => Zone Info => Select queue => seek => play', function () {
this.skip()
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>http://livingears.com/music/SceneNotHeard/091909/Do You Mind Kyla.mp3</EnqueuedURI><EnqueuedURIMetaData></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport',
'<FirstTrackNumberEnqueued>1</FirstTrackNumberEnqueued><NewQueueLength>1</NewQueueLength><NumTracksAdded>1</NumTracksAdded>'
)
mockRequest('/DeviceProperties/Control',
'"urn:schemas-upnp-org:service:DeviceProperties:1#GetZoneInfo"',
'<u:GetZoneInfo xmlns:u="urn:schemas-upnp-org:service:DeviceProperties:1"></u:GetZoneInfo>',
'GetZoneInfoResponse',
'DeviceProperties',
'<MACAddress>xx:xx:xx:xx:xx</MACAddress>'
)
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"',
'<u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>x-rincon-queue:RINCON_xxxxxxxxxx01400#0</CurrentURI><CurrentURIMetaData></CurrentURIMetaData></u:SetAVTransportURI>',
'SetAVTransportURIResponse',
'AVTransport'
)
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#Seek"',
'<u:Seek xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Unit>TRACK_NR</Unit><Target>1</Target></u:Seek>',
'SeekResponse',
'AVTransport'
)
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#Play"',
'<u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play>',
'PlayResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
return sonos.play('http://livingears.com/music/SceneNotHeard/091909/Do You Mind Kyla.mp3')
})
it('should be able to accept an object instead of uri', function () {
this.skip()
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>http://livingears.com/music/SceneNotHeard/091909/Do You Mind Kyla.mp3</EnqueuedURI><EnqueuedURIMetaData>test</EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport',
'<FirstTrackNumberEnqueued>1</FirstTrackNumberEnqueued><NewQueueLength>1</NewQueueLength><NumTracksAdded>1</NumTracksAdded>'
)
mockRequest('/DeviceProperties/Control',
'"urn:schemas-upnp-org:service:DeviceProperties:1#GetZoneInfo"',
'<u:GetZoneInfo xmlns:u="urn:schemas-upnp-org:service:DeviceProperties:1"></u:GetZoneInfo>',
'GetZoneInfoResponse',
'DeviceProperties',
'<MACAddress>xx:xx:xx:xx:xx</MACAddress>'
)
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"',
'<u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>x-rincon-queue:RINCON_xxxxxxxxxx01400#0</CurrentURI><CurrentURIMetaData></CurrentURIMetaData></u:SetAVTransportURI>',
'SetAVTransportURIResponse',
'AVTransport'
)
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#Seek"',
'<u:Seek xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Unit>TRACK_NR</Unit><Target>1</Target></u:Seek>',
'SeekResponse',
'AVTransport'
)
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#Play"',
'<u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play>',
'PlayResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
sonos.play({
uri: 'http://livingears.com/music/SceneNotHeard/091909/Do You Mind Kyla.mp3',
metadata: 'test'
})
})
})
describe('queue()', function () {
it('should generate queue command', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>http://livingears.com/music/SceneNotHeard/091909/Do You Mind Kyla.mp3</EnqueuedURI><EnqueuedURIMetaData></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
return sonos.queue('http://livingears.com/music/SceneNotHeard/091909/Do You Mind Kyla.mp3')
})
it('should encode html characters in uri', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>x-sonos-spotify:spotify%3atrack%3a01Bz4Mijhe7m7qRvq2Ujpn?sid=12&flags=8224&sn=2</EnqueuedURI><EnqueuedURIMetaData></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
return sonos.queue('x-sonos-spotify:spotify%3atrack%3a01Bz4Mijhe7m7qRvq2Ujpn?sid=12&flags=8224&sn=2')
})
it('should accept object in place of uri', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>http://livingears.com/music/SceneNotHeard/091909/Do You Mind Kyla.mp3</EnqueuedURI><EnqueuedURIMetaData><test>"hello"</test></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
return sonos.queue({
uri: 'http://livingears.com/music/SceneNotHeard/091909/Do You Mind Kyla.mp3',
metadata: '<test>"hello"</test>'
})
})
it('should accept a Spotify track uri', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>x-sonos-spotify:spotify%3atrack%3a1AhDOtG9vPSOmsWgNW0BEY</EnqueuedURI><EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="00032020spotify%3atrack%3a1AhDOtG9vPSOmsWgNW0BEY" restricted="true"><dc:title></dc:title><upnp:class>object.item.audioItem.musicTrack</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON3079_X_#Svc3079-0-Token</desc></item></DIDL-Lite></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
return sonos.queue('spotify:track:1AhDOtG9vPSOmsWgNW0BEY')
})
it('should accept a Spotify EU track uri', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>x-sonos-spotify:spotify%3atrack%3a1AhDOtG9vPSOmsWgNW0BEY</EnqueuedURI><EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="00032020spotify%3atrack%3a1AhDOtG9vPSOmsWgNW0BEY" restricted="true"><dc:title></dc:title><upnp:class>object.item.audioItem.musicTrack</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-0-Token</desc></item></DIDL-Lite></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
sonos.setSpotifyRegion(SONOS.SpotifyRegion.EU)
return sonos.queue('spotify:track:1AhDOtG9vPSOmsWgNW0BEY')
})
it('should accept a Spotify album uri', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>x-rincon-cpcontainer:0004206cspotify%3aalbum%3a1TSZDcvlPtAnekTaItI3qO</EnqueuedURI><EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="0004206cspotify%3aalbum%3a1TSZDcvlPtAnekTaItI3qO" restricted="true"><dc:title></dc:title><upnp:class>object.container.album.musicAlbum</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON3079_X_#Svc3079-0-Token</desc></item></DIDL-Lite></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
sonos.queue('spotify:album:1TSZDcvlPtAnekTaItI3qO')
})
it('should accept a Spotify artist top tracks uri', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>x-rincon-cpcontainer:000e206cspotify%3aartistTopTracks%3a1dfeR4HaWDbWqFHLkxsg1d</EnqueuedURI><EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="000e206cspotify%3aartistTopTracks%3a1dfeR4HaWDbWqFHLkxsg1d" restricted="true"><dc:title></dc:title><upnp:class>object.container.playlistContainer</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON3079_X_#Svc3079-0-Token</desc></item></DIDL-Lite></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
sonos.queue('spotify:artistTopTracks:1dfeR4HaWDbWqFHLkxsg1d')
})
it('should accept a Spotify user public playlist uri', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>x-rincon-cpcontainer:10062a6cspotify%3auser%3a26iFraqozskd5POrzg68pr?sid=9&flags=10860&sn=7</EnqueuedURI><EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="10062a6cspotify%3auser%3a26iFraqozskd5POrzg68pr" parentID="10082664playlists" restricted="true"><dc:title>User playlist</dc:title><upnp:class>object.container.playlistContainer</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON3079_X_#Svc3079-0-Token</desc></item></DIDL-Lite></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
sonos.queue('spotify:user:26iFraqozskd5POrzg68pr')
})
it('should accept a Spotify EU user public playlist uri', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>x-rincon-cpcontainer:10062a6cspotify%3auser%3a26iFraqozskd5POrzg68pr?sid=9&flags=10860&sn=7</EnqueuedURI><EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="10062a6cspotify%3auser%3a26iFraqozskd5POrzg68pr" parentID="10082664playlists" restricted="true"><dc:title>User playlist</dc:title><upnp:class>object.container.playlistContainer</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-0-Token</desc></item></DIDL-Lite></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
sonos.setSpotifyRegion(SONOS.SpotifyRegion.EU)
sonos.queue('spotify:user:26iFraqozskd5POrzg68pr')
})
})
describe('playWithoutQueue()', function () {
it('should accept a Spotify artist radio uri', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>x-sonosapi-radio:spotify%3aartistRadio%3a1dfeR4HaWDbWqFHLkxsg1d?sid=12&flags=8300&sn=5</EnqueuedURI><EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="100c206cspotify%3aartistRadio%3a1dfeR4HaWDbWqFHLkxsg1d" parentID="10052064spotify%3aartist%3a1dfeR4HaWDbWqFHLkxsg1d" restricted="true"><dc:title>Artist Radio</dc:title><upnp:class>object.item.audioItem.audioBroadcast.#artistRadio</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON3079_X_#Svc3079-0-Token</desc></item></DIDL-Lite></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
sonos.queue('spotify:artistRadio:1dfeR4HaWDbWqFHLkxsg1d')
})
it('should accept a Spotify EU artist radio uri', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"',
'<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>x-sonosapi-radio:spotify%3aartistRadio%3a1dfeR4HaWDbWqFHLkxsg1d?sid=12&flags=8300&sn=5</EnqueuedURI><EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="100c206cspotify%3aartistRadio%3a1dfeR4HaWDbWqFHLkxsg1d" parentID="10052064spotify%3aartist%3a1dfeR4HaWDbWqFHLkxsg1d" restricted="true"><dc:title>Artist Radio</dc:title><upnp:class>object.item.audioItem.audioBroadcast.#artistRadio</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-0-Token</desc></item></DIDL-Lite></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue>',
'AddURIToQueueResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
sonos.setSpotifyRegion(SONOS.SpotifyRegion.EU)
sonos.queue('spotify:artistRadio:1dfeR4HaWDbWqFHLkxsg1d')
})
})
describe('playTuneinRadio()', function () {
it('should generate play command', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"',
'<u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>x-sonosapi-stream:34682?sid=254&flags=8224&sn=0</CurrentURI><CurrentURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="F0009202034682" parentID="L" restricted="true"><dc:title>88.5 | Jazz24 (Jazz)</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc></item></DIDL-Lite></CurrentURIMetaData></u:SetAVTransportURI>',
'SetAVTransportURIResponse',
'AVTransport'
)
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#Play"',
'<u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play>',
'PlayResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
sonos.playTuneinRadio('34682', '88.5 | Jazz24 (Jazz)')
})
})
describe('playSpotifyRadio()', function () {
it('should generate play command', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"',
'<u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>x-sonosapi-radio:spotify%3aartistRadio%3a1dfeR4HaWDbWqFHLkxsg1d?sid=12&flags=8300&sn=5</CurrentURI><CurrentURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="100c206cspotify%3aartistRadio%3a1dfeR4HaWDbWqFHLkxsg1d" parentID="10052064spotify%3aartist%3a1dfeR4HaWDbWqFHLkxsg1d" restricted="true"><dc:title>Queen</dc:title><upnp:class>object.item.audioItem.audioBroadcast.#artistRadio</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON3079_X_#Svc3079-0-Token</desc></item></DIDL-Lite></CurrentURIMetaData></u:SetAVTransportURI>',
'SetAVTransportURIResponse',
'AVTransport'
)
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#Play"',
'<u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play>',
'PlayResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
sonos.playSpotifyRadio('1dfeR4HaWDbWqFHLkxsg1d', 'Queen')
})
})
describe('setAVTransportURI()', function () {
it('should generate queue command', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"',
'<u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>http://livingears.com/music/SceneNotHeard/091909/Do You Mind Kyla.mp3</CurrentURI><CurrentURIMetaData></CurrentURIMetaData></u:SetAVTransportURI>',
'SetAVTransportURIResponse',
'AVTransport'
)
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#Play"',
'<u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play>',
'PlayResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
sonos.setAVTransportURI('http://livingears.com/music/SceneNotHeard/091909/Do You Mind Kyla.mp3')
})
it('should accept object in place of uri', function () {
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"',
'<u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>http://livingears.com/music/SceneNotHeard/091909/Do You Mind Kyla.mp3</CurrentURI><CurrentURIMetaData><test>"hello"</test></CurrentURIMetaData></u:SetAVTransportURI>',
'SetAVTransportURIResponse',
'AVTransport'
)
mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#Play"',
'<u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play>',
'PlayResponse',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
sonos.setAVTransportURI({
uri: 'http://livingears.com/music/SceneNotHeard/091909/Do You Mind Kyla.mp3',
metadata: '<test>"hello"</test>'
})
})
})
describe('createPlaylist()', function () {
it('should create new playlist', async function () {
const scope = mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#CreateSavedQueue"',
'<u:CreateSavedQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Title>Test</Title><EnqueuedURI></EnqueuedURI><EnqueuedURIMetaData></EnqueuedURIMetaData></u:CreateSavedQueue>',
'CreateSavedQueue',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
await sonos.createPlaylist('Test')
scope.done()
})
})
describe('deletePlaylist()', function () {
it('should remove existing playlist', async function () {
const scope = mockRequest('/MediaServer/ContentDirectory/Control',
'"urn:schemas-upnp-org:service:ContentDirectory:1#DestroyObject"',
'<u:DestroyObject xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1"><ObjectID>SQ:5</ObjectID></u:DestroyObject>',
'DestroyObject',
'ContentDirectory'
)
var sonos = new Sonos('localhost', 1400)
await sonos.deletePlaylist(5)
scope.done()
})
})
describe('addToPlaylist()', function () {
it('should add track to playlist', async function () {
mockRequest('/MediaServer/ContentDirectory/Control',
'"urn:schemas-upnp-org:service:ContentDirectory:1#Browse"',
'<u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1"><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter>*</Filter><StartingIndex>0</StartingIndex><RequestedCount>100</RequestedCount><SortCriteria></SortCriteria><ObjectID>SQ:1</ObjectID></u:Browse>',
'BrowseResponse',
'ContentDirectory',
'<Result><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="x-file-cifs://localhost/Music/Song.mp4" parentID="SQ:1" restricted="true"><res protocolInfo="x-file-cifs:*:audio/mp4:*">x-file-cifs://localhost/Music/Song.mp3</res><upnp:albumArtURI></upnp:albumArtURI><dc:title>Song</dc:title><upnp:class>object.item.audioItem.musicTrack</upnp:class><dc:creator>MyInterpret</dc:creator><upnp:album>MyAlbum</upnp:album><upnp:originalTrackNumber>1</upnp:originalTrackNumber></item></DIDL-Lite></Result><NumberReturned>0</NumberReturned><TotalMatches>0</TotalMatches><UpdateID>0</UpdateID>'
)
const scope = mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToSavedQueue"',
'<u:AddURIToSavedQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><ObjectID>SQ:1</ObjectID><UpdateID>0</UpdateID><EnqueuedURI>x-file-cifs://localhost/Music/Song.mp3</EnqueuedURI><EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="S://localhost/Music/Song.mp3" parentID="A:TRACKS" restricted="true"><dc:title>Song</dc:title><upnp:class>object.item.audioItem.musicTrack</upnp:class><upnp:albumArtURI></upnp:albumArtURI><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">RINCON_AssociatedZPUDN</desc></item></DIDL-Lite></EnqueuedURIMetaData><AddAtIndex>4294967295</AddAtIndex></u:AddURIToSavedQueue>',
'AddURIToSavedQueue',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
await sonos.addToPlaylist(1, 'x-file-cifs://localhost/Music/Song.mp3')
scope.done()
})
it('should add album to playlist', async function () {
mockRequest('/MediaServer/ContentDirectory/Control',
'"urn:schemas-upnp-org:service:ContentDirectory:1#Browse"',
'<u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1"><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter>*</Filter><StartingIndex>0</StartingIndex><RequestedCount>100</RequestedCount><SortCriteria></SortCriteria><ObjectID>SQ:1</ObjectID></u:Browse>',
'BrowseResponse',
'ContentDirectory',
'<Result><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="x-file-cifs://localhost/Music/Song.mp4" parentID="SQ:1" restricted="true"><res protocolInfo="x-file-cifs:*:audio/mp4:*">x-file-cifs://localhost/Music/Song.mp3</res><upnp:albumArtURI></upnp:albumArtURI><dc:title>Song</dc:title><upnp:class>object.item.audioItem.musicTrack</upnp:class><dc:creator>MyInterpret</dc:creator><upnp:album>MyAlbum</upnp:album><upnp:originalTrackNumber>1</upnp:originalTrackNumber></item></DIDL-Lite></Result><NumberReturned>0</NumberReturned><TotalMatches>0</TotalMatches><UpdateID>0</UpdateID>'
)
const scope = mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToSavedQueue"',
'<u:AddURIToSavedQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><ObjectID>SQ:1</ObjectID><UpdateID>0</UpdateID><EnqueuedURI>x-rincon-playlist://localhost/Music/Album#A:ALBUMS/MyAlbum</EnqueuedURI><EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="A:ALBUMS/MyAlbum" parentID="A:ALBUMS" restricted="true"><dc:title>MyAlbum</dc:title><upnp:class>object.item.audioItem.musicAlbum</upnp:class><upnp:albumArtURI></upnp:albumArtURI><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">RINCON_AssociatedZPUDN</desc></item></DIDL-Lite></EnqueuedURIMetaData><AddAtIndex>4294967295</AddAtIndex></u:AddURIToSavedQueue>',
'AddURIToSavedQueue',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
await sonos.addToPlaylist(1, 'x-rincon-playlist://localhost/Music/Album#A:ALBUMS/MyAlbum')
scope.done()
})
it('should add albumartist to playlist', async function () {
mockRequest('/MediaServer/ContentDirectory/Control',
'"urn:schemas-upnp-org:service:ContentDirectory:1#Browse"',
'<u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1"><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter>*</Filter><StartingIndex>0</StartingIndex><RequestedCount>100</RequestedCount><SortCriteria></SortCriteria><ObjectID>SQ:1</ObjectID></u:Browse>',
'BrowseResponse',
'ContentDirectory',
'<Result><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="x-file-cifs://localhost/Music/Song.mp4" parentID="SQ:1" restricted="true"><res protocolInfo="x-file-cifs:*:audio/mp4:*">x-file-cifs://localhost/Music/Song.mp3</res><upnp:albumArtURI></upnp:albumArtURI><dc:title>Song</dc:title><upnp:class>object.item.audioItem.musicTrack</upnp:class><dc:creator>MyInterpret</dc:creator><upnp:album>MyAlbum</upnp:album><upnp:originalTrackNumber>1</upnp:originalTrackNumber></item></DIDL-Lite></Result><NumberReturned>0</NumberReturned><TotalMatches>0</TotalMatches><UpdateID>0</UpdateID>'
)
const scope = mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToSavedQueue"',
'<u:AddURIToSavedQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><ObjectID>SQ:1</ObjectID><UpdateID>0</UpdateID><EnqueuedURI>x-rincon-playlist://localhost/Music/AlbumArtist#A:ALBUMARTIST/My Album Artist</EnqueuedURI><EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="A:ALBUMARTIST/My%20Album%20Artist" parentID="A:ALBUMARTIST" restricted="true"><dc:title>My Album Artist</dc:title><upnp:class>object.item.audioItem.musicArtist</upnp:class><upnp:albumArtURI></upnp:albumArtURI><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">RINCON_AssociatedZPUDN</desc></item></DIDL-Lite></EnqueuedURIMetaData><AddAtIndex>4294967295</AddAtIndex></u:AddURIToSavedQueue>',
'AddURIToSavedQueue',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
await sonos.addToPlaylist(1, 'x-rincon-playlist://localhost/Music/AlbumArtist#A:ALBUMARTIST/My Album Artist')
scope.done()
})
it('should add genre to playlist', async function () {
mockRequest('/MediaServer/ContentDirectory/Control',
'"urn:schemas-upnp-org:service:ContentDirectory:1#Browse"',
'<u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1"><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter>*</Filter><StartingIndex>0</StartingIndex><RequestedCount>100</RequestedCount><SortCriteria></SortCriteria><ObjectID>SQ:1</ObjectID></u:Browse>',
'BrowseResponse',
'ContentDirectory',
'<Result><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="x-file-cifs://localhost/Music/Song.mp4" parentID="SQ:1" restricted="true"><res protocolInfo="x-file-cifs:*:audio/mp4:*">x-file-cifs://localhost/Music/Song.mp3</res><upnp:albumArtURI></upnp:albumArtURI><dc:title>Song</dc:title><upnp:class>object.item.audioItem.musicTrack</upnp:class><dc:creator>MyInterpret</dc:creator><upnp:album>MyAlbum</upnp:album><upnp:originalTrackNumber>1</upnp:originalTrackNumber></item></DIDL-Lite></Result><NumberReturned>0</NumberReturned><TotalMatches>0</TotalMatches><UpdateID>0</UpdateID>'
)
const scope = mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#AddURIToSavedQueue"',
'<u:AddURIToSavedQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><ObjectID>SQ:1</ObjectID><UpdateID>0</UpdateID><EnqueuedURI>x-rincon-playlist://localhost/Music/Genre#A:GENRE/MyGenre</EnqueuedURI><EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="A:GENRE/MyGenre" parentID="A:GENRE" restricted="true"><dc:title>MyGenre</dc:title><upnp:class>object.container.genre.musicGenre</upnp:class><upnp:albumArtURI></upnp:albumArtURI><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">RINCON_AssociatedZPUDN</desc></item></DIDL-Lite></EnqueuedURIMetaData><AddAtIndex>4294967295</AddAtIndex></u:AddURIToSavedQueue>',
'AddURIToSavedQueue',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
await sonos.addToPlaylist(1, 'x-rincon-playlist://localhost/Music/Genre#A:GENRE/MyGenre')
scope.done()
})
})
describe('removeFromPlaylist()', function () {
it('should remove track from playlist', async function () {
mockRequest('/MediaServer/ContentDirectory/Control',
'"urn:schemas-upnp-org:service:ContentDirectory:1#Browse"',
'<u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1"><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter>*</Filter><StartingIndex>0</StartingIndex><RequestedCount>100</RequestedCount><SortCriteria></SortCriteria><ObjectID>SQ:1</ObjectID></u:Browse>',
'BrowseResponse',
'ContentDirectory',
'<Result><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="x-file-cifs://localhost/Music/Song.mp4" parentID="SQ:1" restricted="true"><res protocolInfo="x-file-cifs:*:audio/mp4:*">x-file-cifs://localhost/Music/Song.mp3</res><upnp:albumArtURI></upnp:albumArtURI><dc:title>Song</dc:title><upnp:class>object.item.audioItem.musicTrack</upnp:class><dc:creator>MyInterpret</dc:creator><upnp:album>MyAlbum</upnp:album><upnp:originalTrackNumber>1</upnp:originalTrackNumber></item></DIDL-Lite></Result><NumberReturned>0</NumberReturned><TotalMatches>0</TotalMatches><UpdateID>0</UpdateID>'
)
const scope = mockRequest('/MediaRenderer/AVTransport/Control',
'"urn:schemas-upnp-org:service:AVTransport:1#ReorderTracksInSavedQueue"',
'<u:ReorderTracksInSavedQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><ObjectID>SQ:1</ObjectID><UpdateID>0</UpdateID><TrackList>2</TrackList><NewPositionList></NewPositionList></u:ReorderTracksInSavedQueue>',
'ReorderTracksInSavedQueue',
'AVTransport'
)
var sonos = new Sonos('localhost', 1400)
await sonos.removeFromPlaylist(1, 2)
scope.done()
})
})
})
describe('DeviceDiscovery', function () {
it('should emit a timeout event when timeout is hit', function (done) {
const failTimeout = setTimeout(function () {
assert(false, 'Event never fired')
done()
}, 100)
var search = SONOS.DeviceDiscovery({ timeout: 10 }, function (device, model) {})
search.on('timeout', function () {
clearTimeout(failTimeout)
assert(true)
done()
})
})
it('should not emit a timeout event when no timeout option is passed in', function (done) {
setTimeout(function () {
assert(true)
done()
}, 10)
var search = SONOS.DeviceDiscovery(function (device, model) {})
search.on('timeout', function () {
assert(false, 'Timeout event should never fire')
done()
})
})
it('should not emit a timeout event after search is stopped', function (done) {
var search = SONOS.DeviceDiscovery({ timeout: 10 }, function (device, model) {})
search.on('timeout', function () {
assert(false, 'Timeout event should never fire')
done()
})
search.destroy(function () {
assert(true)
done()
})
})
})
describe('Async DeviceDiscovery', function () {
it('should reject after timeout without devices found', function (done) {
const failTimeout = setTimeout(function () {
assert(false, 'Event never fired')
done()
}, 100)
var deviceDiscovery = new SONOS.AsyncDeviceDiscovery()
deviceDiscovery.discover({ timeout: 10 }).then((device, model) => {
// Also fine if we found a device....
clearTimeout(failTimeout)
assert(true)
done()
}).catch(err => { // eslint-disable-line handle-callback-err
clearTimeout(failTimeout)
assert(true)
done()
})
})
})
describe('Sonos - Device', function () {
let sonos
before(function () {
if (!process.env.SONOS_HOST) {
this.skip()
} else {
sonos = new Sonos(process.env.SONOS_HOST, 1400)
}
})
it('should getMuted()', function () {
return sonos.getMuted().then(muted => {
assert(typeof muted === 'boolean', 'muted is a boolean')
})
})
it('should getCurrentState()', function () {
return sonos.getCurrentState().then(state => {
assert(typeof state === 'string', 'state is a string')
const values = ['stopped', 'playing', 'paused', 'transitioning', 'no_media']
assert(values.indexOf(state) > -1, 'state is one of the allowed values')
})
})
it('should getVolume()', function () {
return sonos.getVolume().then(volume => {
assert(typeof volume === 'number', 'volume is a number')
assert((volume >= 0 && volume <= 100), 'volume is between 0 and 100')
})
})
it('should getPlayMode()', function () {
return sonos.getPlayMode().then(playmode => {
assert(typeof playmode === 'string', 'playmode is a string')
const values = ['NORMAL', 'REPEAT_ONE', 'REPEAT_ALL', 'SHUFFLE', 'SHUFFLE_NOREPEAT', 'SHUFFLE_REPEAT_ONE']
assert(values.indexOf(playmode) > -1, 'playmode is one of the allowed values')
})
})
it('should getFavorites()', function () {
return sonos.getFavorites().then(function (favs) {
assert(favs.items, 'should have items')
})
})
it('should getMusicLibrary("sonos_playlists")', function () {
return sonos.getMusicLibrary('sonos_playlists').then(function (playlists) {
assert(playlists.items, 'should have items')
if (playlists.items.length > 0) {
assert('id' in playlists.items[0], 'item should have id in object')
assert('parentID' in playlists.items[0], 'item should have parentID in object')
assert('uri' in playlists.items[0], 'item should have uri in object')
assert('title' in playlists.items[0], 'item should have title in object')
}
})
})
it('should getPlaylist()', function () {
return sonos.getPlaylist('1').then(function (playlist) {
assert(playlist.items, 'should have items')
})
})
it('should getQueue()', function () {
return sonos.getQueue().then(function (queue) {
assert(queue.items, 'should have items')
})
})
// There seem to be some kind of error here.... Needs attention.
it('should getFavoritesRadioStations()', function () {
return sonos.getFavoritesRadioStations().then(function (radio) {
assert(radio.items, 'should have items')
})
})
it('should getAllGroups()', function () {
return sonos.getAllGroups().then(function (groups) {
assert(Array.isArray(groups), 'should return an array')
})
})
it('playNotification()', function () {
return sonos.playNotification({
uri: 'https://www.zapsplat.com/wp-content/uploads/2015/sound-effects-the-sound-pack-tree/tspt_pull_bell_02_065.mp3?_=1',
volume: 10
}).then(result => {
assert(result, 'Played notification')
})
})
it('playNotification() -> No notification when not playing', async function () {
const state = await sonos.getCurrentState()
if ((state === 'playing' || state === 'transitioning')) {
this.skip('Is playing cannot test')
}
return sonos.playNotification({
uri: 'https://www.zapsplat.com/wp-content/uploads/2015/sound-effects-the-sound-pack-tree/tspt_pull_bell_02_065.mp3?_=1',
volume: 10,
onlyWhenPlaying: true
}).then(result => {
assert(result === false, 'Shouldn\'t start when not playing')
})
})
it('should return Spotify Conenct Info', function () {
return sonos.getSpotifyConnectInfo()
.then(data => {
assert(true)
})
})
describe('AlarmClockService()', function () {
it('should list alarms', function () {
return sonos.alarmClockService()
.ListAlarms().then(function (result) {
assert(Array.isArray(result.Alarms), '.Alarms should be an array')
assert(typeof (result.CurrentAlarmListVersion) === 'string', '.CurrentAlarmListVersion should be a string')
})
})
it('should throw an error on update with not string', function () {
return sonos.alarmClockService().SetAlarm(1, false).catch(err => {
assert(err, 'Got error')
})
})
it('should toggle the first alarm', function () {
return sonos.alarmClockService()
.ListAlarms().then(function (result) {
if (result.Alarms.length === 0) {
assert(true)
} else {
const alarm = result.Alarms[0]
const toggleTo = alarm.Enabled === '0'
return sonos.alarmClockService().SetAlarm(alarm.ID, toggleTo).then(function (result) {
// Revert back the change, or you'll get a bad morning after testing this library....
return sonos.alarmClockService().SetAlarm(alarm.ID, !toggleTo).then(function (result) {
assert(true)
})
})
}
})
})
})
})