Skip to content

Commit 0d2b722

Browse files
chore(deps): bump tmp and standard (#559)
* chore(deps): bump tmp and standard Removes [tmp](https://github.com/raszi/node-tmp). It's no longer used after updating ancestor dependency [standard](https://github.com/standard/standard). These dependencies need to be updated together. Removes `tmp` Updates `standard` from 13.1.0 to 17.1.2 - [Release notes](https://github.com/standard/standard/releases) - [Changelog](https://github.com/standard/standard/blob/master/CHANGELOG.md) - [Commits](standard/standard@v13.1.0...v17.1.2) --- updated-dependencies: - dependency-name: tmp dependency-version: dependency-type: indirect - dependency-name: standard dependency-version: 17.1.2 dependency-type: direct:development ... Signed-off-by: dependabot[bot] <support@github.com> * chore: fix standard style lint errors --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ben Evans <ben@bluechimp.io>
1 parent 8cc1b7d commit 0d2b722

File tree

15 files changed

+2887
-1607
lines changed

15 files changed

+2887
-1607
lines changed

examples/nowplayingwebsite.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
var http = require('http')
2-
var Sonos = require('../').Sonos
1+
const http = require('http')
2+
const Sonos = require('../').Sonos
33

4-
var sonos = new Sonos(process.env.SONOS_HOST || '192.168.2.11')
4+
const sonos = new Sonos(process.env.SONOS_HOST || '192.168.2.11')
55

6-
var server = http.createServer(async function (req, res) {
7-
var track = await sonos.currentTrack()
6+
const server = http.createServer(async function (req, res) {
7+
const track = await sonos.currentTrack()
88
res.writeHead(200, {
99
'Content-Type': 'text/html'
1010
})
1111

12-
var rows = []
12+
const rows = []
1313

14-
for (var key in track) {
14+
for (const key in track) {
1515
if (key === 'albumArtURL') {
1616
rows.push('<tr><th>' + key + '</th><td><img src="' + track[key] + '"/></td></tr>')
1717
} else {

examples/playSpotifyMusic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ sonos.setSpotifyRegion(Regions.EU)
2424
// your Sonos system.
2525

2626
// var spotifyUri = 'spotify:artistTopTracks:72qVrKXRp9GeFQOesj0Pmv'
27-
var spotifyUri = 'spotify:track:6sYJuVcEu4gFHmeTLdHzRz'
27+
const spotifyUri = 'spotify:track:6sYJuVcEu4gFHmeTLdHzRz'
2828

2929
sonos.play(spotifyUri)
3030
.then(success => {

examples/searchinfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
var sonos = require('../index')
1+
const sonos = require('../index')
22

33
console.log('\nSearching for Sonos devices on network...')
44

55
sonos.DeviceDiscovery(function (device, model) {
6-
var devInfo = '\n'
6+
let devInfo = '\n'
77
devInfo += 'Device \t' + JSON.stringify(device) + ' (' + model + ')\n'
88
device.getZoneAttrs(function (err, attrs) {
99
if (err) devInfo += '`- failed to retrieve zone attributes\n'

examples/switchToLineIn.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const sonos = new Sonos(process.env.SONOS_HOST || '192.168.96.223')
44
sonos.getZoneInfo().then(data => {
55
// console.log('Got zone info %j', data)
66
// The mac is needed for switch to a different channel
7-
var macCleaned = data.MACAddress.replace(/:/g, '')
7+
const macCleaned = data.MACAddress.replace(/:/g, '')
88
console.log('Cleaned mac %j', macCleaned)
99

1010
// To switch on a playbar do the following
11-
var uri = 'x-sonos-htastream:RINCON_' + macCleaned + '01400:spdif'
11+
const uri = 'x-sonos-htastream:RINCON_' + macCleaned + '01400:spdif'
1212

1313
// To switch on a Play:5 and Connect do the following
1414
// var uri = 'x-rincon-stream:RINCON_' + macCleaned + '01400'

lib/deviceDiscovery.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ const Sonos = require('./sonos').Sonos
1616
* @class DeviceDiscovery
1717
* @emits 'DeviceAvailable' on a Sonos Component Discovery
1818
*/
19-
var DeviceDiscovery = function DeviceDiscovery (options) {
20-
var self = this
19+
const DeviceDiscovery = function DeviceDiscovery (options) {
20+
const self = this
2121
self.foundSonosDevices = {}
2222
self.onTimeout = function () {
2323
clearTimeout(self.pollTimer)
2424
}
25-
var PLAYER_SEARCH = Buffer.from(['M-SEARCH * HTTP/1.1',
25+
const PLAYER_SEARCH = Buffer.from(['M-SEARCH * HTTP/1.1',
2626
'HOST: 239.255.255.250:1900',
2727
'MAN: ssdp:discover',
2828
'MX: 1',
2929
'ST: urn:schemas-upnp-org:device:ZonePlayer:1'].join('\r\n'))
30-
var sendDiscover = function () {
31-
['239.255.255.250', '255.255.255.255'].map(function (addr) {
30+
const sendDiscover = function () {
31+
['239.255.255.250', '255.255.255.255'].forEach(function (addr) {
3232
self.socket.send(PLAYER_SEARCH, 0, PLAYER_SEARCH.length, 1900, addr)
3333
})
3434
// Periodically send discover packet to find newly added devices
@@ -40,11 +40,11 @@ var DeviceDiscovery = function DeviceDiscovery (options) {
4040
this.socket = dgram.createSocket('udp4', function (buffer, rinfo) {
4141
buffer = buffer.toString()
4242
if (buffer.match(/.+Sonos.+/)) {
43-
var modelCheck = buffer.match(/SERVER.*\((.*)\)/)
44-
var model = (modelCheck.length > 1 ? modelCheck[1] : null)
45-
var addr = rinfo.address
43+
const modelCheck = buffer.match(/SERVER.*\((.*)\)/)
44+
const model = (modelCheck.length > 1 ? modelCheck[1] : null)
45+
const addr = rinfo.address
4646
if (!(addr in self.foundSonosDevices)) {
47-
var sonos = self.foundSonosDevices[addr] = new Sonos(addr)
47+
const sonos = self.foundSonosDevices[addr] = new Sonos(addr)
4848
self.emit('DeviceAvailable', sonos, model)
4949
}
5050
}
@@ -92,14 +92,14 @@ DeviceDiscovery.prototype.destroy = function (callback) {
9292
* @param {Function} listener Optional 'DeviceAvailable' listener (sonos)
9393
* @return {DeviceDiscovery}
9494
*/
95-
var deviceDiscovery = function (options, listener) {
95+
const deviceDiscovery = function (options, listener) {
9696
if (typeof options === 'function') {
9797
listener = options
9898
options = null
9999
}
100100
options = options || {}
101101
listener = listener || null
102-
var search = new DeviceDiscovery(options)
102+
const search = new DeviceDiscovery(options)
103103
if (listener !== null) {
104104
search.on('DeviceAvailable', listener)
105105
}

lib/events/adv-listener.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class SonosListener extends EventEmitter {
8181
const cancel = function (s) {
8282
return s.cancelAllSubscriptions()
8383
}
84-
var cancelAll = this._deviceSubscriptions.map(cancel)
84+
const cancelAll = this._deviceSubscriptions.map(cancel)
8585
return Promise.all(cancelAll)
8686
} else {
8787
return new Promise((resolve, reject) => { reject(new Error('Not listening')) })
@@ -218,7 +218,7 @@ class DeviceSubscription {
218218
const sid = resp.headers.sid
219219
debug('Got %s for %s', sid, endpoint)
220220
this._startTimer()
221-
this.subscriptions[sid] = { endpoint: endpoint, renew_at: this.headerToDateTime(resp.headers.timeout) }
221+
this.subscriptions[sid] = { endpoint, renew_at: this.headerToDateTime(resp.headers.timeout) }
222222
return sid
223223
})
224224
}
@@ -329,7 +329,7 @@ class DeviceSubscription {
329329
url: 'http://' + this.device.host + ':' + this.device.port + this.subscriptions[sid].endpoint,
330330
method: 'UNSUBSCRIBE',
331331
headers: {
332-
sid: sid
332+
sid
333333
}
334334
}).then(result => {
335335
debug('Cancelled subscription %s for %s', sid, this.device.host)
@@ -342,7 +342,7 @@ class DeviceSubscription {
342342
* @param {String} timeout TimeOut header
343343
*/
344344
headerToDateTime (timeout) {
345-
var seconds
345+
let seconds
346346

347347
if ((!!timeout) && (timeout.indexOf('Second-') === 0)) timeout = timeout.substr(7)
348348
seconds = (((!!timeout) && (!isNaN(timeout))) ? parseInt(timeout, 10) : 3600) - 15

lib/events/eventParser.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
const Helpers = require('../helpers')
32
const debug = require('debug')('sonos-listener')
43
const SonosGroup = require('../sonosGroup')
@@ -97,7 +96,7 @@ EventParser._parseRenderingControlEvent = async function (body, device) {
9796
}
9897

9998
EventParser._genericEvent = function (endpoint, body, device) {
100-
const event = { name: 'UnknownEvent', endpoint: endpoint, eventBody: body }
99+
const event = { name: 'UnknownEvent', endpoint, eventBody: body }
101100
if (device) {
102101
device.emit(event.name, event)
103102
}

lib/helpers.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const parseString = require('xml2js').parseString
1212
* Helper class
1313
* @class Helpers
1414
*/
15-
var Helpers = {}
15+
const Helpers = {}
1616

1717
/**
1818
* Wrap in UPnP Envelope
@@ -87,15 +87,15 @@ Helpers.GenerateCustomMetadata = function (streamUrl, itemId, duration = '00:00:
8787
* @return {Object} { uri: uri, metadata: metadata }
8888
*/
8989
Helpers.GenerateLocalMetadata = function (uri, artUri = '') {
90-
var title = ''
91-
var match = /.*\/(.*)$/g.exec(uri.replace(/\.[a-zA-Z0-9]{3}$/, ''))
90+
let title = ''
91+
const match = /.*\/(.*)$/g.exec(uri.replace(/\.[a-zA-Z0-9]{3}$/, ''))
9292
if (match) {
9393
title = match[1]
9494
}
95-
var meta = '<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="##ITEMID##" parentID="##PARENTID##" restricted="true"><dc:title>##RESOURCETITLE##</dc:title><upnp:class>##UPNPCLASS##</upnp:class><upnp:albumArtURI>##ARTURI##</upnp:albumArtURI><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">##REGION##</desc></item></DIDL-Lite>'
95+
const meta = '<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="##ITEMID##" parentID="##PARENTID##" restricted="true"><dc:title>##RESOURCETITLE##</dc:title><upnp:class>##UPNPCLASS##</upnp:class><upnp:albumArtURI>##ARTURI##</upnp:albumArtURI><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">##REGION##</desc></item></DIDL-Lite>'
9696
if (uri.startsWith('x-file-cifs')) {
9797
return {
98-
uri: uri,
98+
uri,
9999
metadata: meta.replace('##ITEMID##', uri.replace('x-file-cifs', 'S').replace(/\s/g, '%20'))
100100
.replace('##RESOURCETITLE##', title.replace('%20', ' '))
101101
.replace('##UPNPCLASS##', Helpers.GetUpnpClass('A:TRACKS'))
@@ -105,11 +105,11 @@ Helpers.GenerateLocalMetadata = function (uri, artUri = '') {
105105
}
106106
}
107107
if (uri.startsWith('x-rincon-playlist')) {
108-
var parentMatch = /.*#(.*)\/.*/g.exec(uri)
109-
var parentID = parentMatch[1]
108+
const parentMatch = /.*#(.*)\/.*/g.exec(uri)
109+
const parentID = parentMatch[1]
110110

111111
return {
112-
uri: uri,
112+
uri,
113113
metadata: meta.replace('##ITEMID##', `${parentID}/${title.replace(/\s/g, '%20')}`)
114114
.replace('##RESOURCETITLE##', title.replace('%20', ' '))
115115
.replace('##UPNPCLASS##', Helpers.GetUpnpClass(parentID))
@@ -118,7 +118,7 @@ Helpers.GenerateLocalMetadata = function (uri, artUri = '') {
118118
.replace('##REGION##', 'RINCON_AssociatedZPUDN')
119119
}
120120
}
121-
return { uri: uri, metadata: '' }
121+
return { uri, metadata: '' }
122122
}
123123

124124
/**
@@ -129,15 +129,15 @@ Helpers.GenerateLocalMetadata = function (uri, artUri = '') {
129129
* @return {Object} options {uri: Spotify uri, metadata: metadata}
130130
*/
131131
Helpers.GenerateMetadata = function (uri, title = '', region = '3079') {
132-
var parts = uri.split(':')
132+
const parts = uri.split(':')
133133
if (!((parts.length === 2 && (parts[0] === 'radio' || parts[0] === 'x-sonosapi-stream' || parts[0] === 'x-rincon-cpcontainer')) || (parts.length >= 3 && parts[0] === 'spotify'))) {
134134
debug('Returning string because it isn\'t recognized')
135135
return Helpers.GenerateLocalMetadata(uri)
136136
}
137-
var meta = '<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="##SPOTIFYURI##" ##PARENTID##restricted="true"><dc:title>##RESOURCETITLE##</dc:title><upnp:class>##SPOTIFYTYPE##</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">##REGION##</desc></item></DIDL-Lite>'
137+
let meta = '<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="##SPOTIFYURI##" ##PARENTID##restricted="true"><dc:title>##RESOURCETITLE##</dc:title><upnp:class>##SPOTIFYTYPE##</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">##REGION##</desc></item></DIDL-Lite>'
138138

139139
if (parts[0] === 'radio' || parts[0] === 'x-sonosapi-stream') {
140-
var radioTitle = title || 'TuneIn Radio'
140+
const radioTitle = title || 'TuneIn Radio'
141141
if (parts[0] === 'radio') {
142142
return {
143143
uri: 'x-sonosapi-stream:' + parts[1] + '?sid=254&flags=8224&sn=0',
@@ -150,7 +150,7 @@ Helpers.GenerateMetadata = function (uri, title = '', region = '3079') {
150150
} else {
151151
const itemId = parts[1].split('?')[0]
152152
return {
153-
uri: uri,
153+
uri,
154154
metadata: meta.replace('##SPOTIFYURI##', 'F00092020' + itemId)
155155
.replace('##RESOURCETITLE##', radioTitle)
156156
.replace('##SPOTIFYTYPE##', 'object.item.audioItem.audioBroadcast')
@@ -161,7 +161,7 @@ Helpers.GenerateMetadata = function (uri, title = '', region = '3079') {
161161
} else {
162162
meta = meta.replace('##REGION##', 'SA_RINCON' + region + '_X_#Svc' + region + '-0-Token')
163163
}
164-
var spotifyUri = uri.replace(/:/g, '%3a')
164+
const spotifyUri = uri.replace(/:/g, '%3a')
165165

166166
if (uri.startsWith('spotify:track:')) { // Just one track
167167
return {
@@ -204,8 +204,8 @@ Helpers.GenerateMetadata = function (uri, title = '', region = '3079') {
204204
.replace('##PARENTID##', 'parentID="10082664playlists" ')
205205
}
206206
} else if (uri.startsWith('spotify:artistRadio:')) { // Artist radio
207-
var spotifyTitle = title || 'Artist Radio'
208-
var parentId = spotifyUri.replace('artistRadio', 'artist')
207+
const spotifyTitle = title || 'Artist Radio'
208+
const parentId = spotifyUri.replace('artistRadio', 'artist')
209209
return {
210210
uri: 'x-sonosapi-radio:' + spotifyUri + '?sid=12&flags=8300&sn=5',
211211
metadata: meta.replace('##SPOTIFYURI##', '100c206c' + spotifyUri)
@@ -226,7 +226,7 @@ Helpers.GenerateMetadata = function (uri, title = '', region = '3079') {
226226
} else if (uri.startsWith('x-rincon-cpcontainer:100d206cuser-fav')) { // Sound Cloud likes
227227
const id = uri.replace('x-rincon-cpcontainer:', '')
228228
return {
229-
uri: uri,
229+
uri,
230230
metadata: meta.replace('##SPOTIFYURI##', id)
231231
.replace('##RESOURCETITLE##', title || 'Sound Cloud Likes')
232232
.replace('##SPOTIFYTYPE##', 'object.container.albumList')
@@ -236,15 +236,15 @@ Helpers.GenerateMetadata = function (uri, title = '', region = '3079') {
236236
} else if (uri.startsWith('x-rincon-cpcontainer:1006206cplaylist')) { // Sound Cloud playlists
237237
const [id] = uri.replace('x-rincon-cpcontainer:', '').split('?')
238238
return {
239-
uri: uri,
239+
uri,
240240
metadata: meta.replace('##SPOTIFYURI##', id)
241241
.replace('##RESOURCETITLE##', title || 'Sound Cloud Playlist')
242242
.replace('##SPOTIFYTYPE##', 'object.container.playlistContainer')
243243
.replace('##PARENTID##', '')
244244
.replace(`SA_RINCON${region}_X_#Svc${region}-0-Token`, 'SA_RINCON40967_X_#Svc40967-0-Token')
245245
}
246246
} else {
247-
return { uri: uri, metadata: '' }
247+
return { uri, metadata: '' }
248248
}
249249
}
250250

lib/services/AVTransport.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,20 @@ class AVTransport extends Service {
192192
const trackUri = result.TrackURI || null
193193
const queuePosition = parseInt(result.Track)
194194
if (result.TrackMetaData && result.TrackMetaData !== 'NOT_IMPLEMENTED') { // There is some metadata, lets parse it.
195-
var metadata = await Helpers.ParseXml(result.TrackMetaData)
195+
const metadata = await Helpers.ParseXml(result.TrackMetaData)
196196
const track = Helpers.ParseDIDL(metadata)
197197
track.position = position
198198
track.duration = duration
199-
track.albumArtURL = !track.albumArtURI ? null
200-
: track.albumArtURI.startsWith('http') ? track.albumArtURI
199+
track.albumArtURL = !track.albumArtURI
200+
? null
201+
: track.albumArtURI.startsWith('http')
202+
? track.albumArtURI
201203
: 'http://' + this.host + ':' + this.port + track.albumArtURI
202204
if (trackUri) track.uri = trackUri
203205
track.queuePosition = queuePosition
204206
return track
205207
} else { // No metadata.
206-
return { position: position, duration: duration, queuePosition: queuePosition, uri: trackUri }
208+
return { position, duration, queuePosition, uri: trackUri }
207209
}
208210
})
209211
}

lib/services/ContentDirectory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ContentDirectory extends Service {
5858
returned: data.NumberReturned,
5959
total: data.TotalMatches,
6060
updateID: data.UpdateID,
61-
items: items
61+
items
6262
}
6363
})
6464
}

0 commit comments

Comments
 (0)