iobroker.squeezeboxrpc 1.3.11 → 1.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 oweitman <oweitman@gmx.de>
3
+ Copyright (c) 2019-2024 oweitman <oweitman@gmx.de>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -201,6 +201,12 @@ For more information visit the CLI-documentation:
201
201
  Placeholder for the next version (at the beginning of the line):
202
202
  ### **WORK IN PROGRESS**
203
203
  -->
204
+ ### 1.3.12 (2024-08-05)
205
+
206
+ - improve cmdGoto handling by kairauer, close PR #74
207
+ - fix issues from adapter checker
208
+ - integrate squeezenode lib
209
+
204
210
  ### 1.3.11 (2024-08-05)
205
211
 
206
212
  - update adapter structure and switch to jsonconfig
package/io-package.json CHANGED
@@ -1,8 +1,21 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "squeezeboxrpc",
4
- "version": "1.3.11",
4
+ "version": "1.3.12",
5
5
  "news": {
6
+ "1.3.12": {
7
+ "en": "improve cmdGoto handling by kairauer, close PR #74\nfix issues from adapter checker\nintegrate squeezenode lib",
8
+ "de": "verbessern cmd Goto Handling von kairauer, close PR #74\nprobleme von adapter checker beheben\npressnode lib integrieren",
9
+ "ru": "улучшить смс Goto handling by kairauer, close PR #74\nпроблемы с адаптером\nинтегрировать сжимнод lib",
10
+ "pt": "melhorar cm Goto manipulação por kairauer, close PR #74\ncorrigir problemas do verificador do adaptador\nintegrar o espremido lib",
11
+ "nl": "verbetering cmd Ga naar behandeling door Kairauer, sluit PR #74\nproblemen oplossen van adaptercontrole\nintegreer crownode lib",
12
+ "fr": "améliorer cmd Goto manipulation par kairauer, fermer PR #74\ncorrection des problèmes de l'adaptateur checker\nintégrer la lib de pressingnode",
13
+ "it": "migliorare cmd Goto handling by kairauer, close PR #74\nrisolvere problemi da adattatore checker\nintegrare compressione lib",
14
+ "es": "mejorar cmd Goto manejo por kairauer, cerrar PR #74\nsolucionar problemas desde el control de adaptador\nintegrar el exprimido lib",
15
+ "pl": "poprawić cmd Goto handling by kairauer, close PR # 74\nnaprawianie problemów z sprawdzaczem adaptera\nzintegrować lib wyciskacza",
16
+ "uk": "поліпшення cmd Goto обслуговування за допомогою kairauer, Закрити PR #74\nвиправити проблеми з перевіркою адаптера\nінтегрувати squeezenode lib",
17
+ "zh-cn": "改进 cmd 由Kairauer处理\n从适配器检查器中校正问题\n集成压缩节点 lib"
18
+ },
6
19
  "1.3.11": {
7
20
  "en": "update adapter structure and switch to jsonconfig",
8
21
  "de": "adapterstruktur aktualisieren und auf jsonconfig wechseln",
@@ -80,22 +93,8 @@
80
93
  "pl": "* naprawiono tworzenie obiektów w stanach",
81
94
  "uk": "* виправити створення об'єктів станів",
82
95
  "zh-cn": "* 修复状态的对象创建"
83
- },
84
- "1.3.5": {
85
- "en": "* fix object creation for favorites",
86
- "de": "* Objekterstellung für Favoriten korrigiert",
87
- "ru": "* исправлено создание объектов для избранного",
88
- "pt": "* corrigir a criação de objetos para favoritos",
89
- "nl": "* probleem met het maken van objecten voor favorieten",
90
- "fr": "* correction de la création d'objets pour les favoris",
91
- "it": "* corretta la creazione di oggetti per i preferiti",
92
- "es": "* arreglar la creación de objetos para favoritos",
93
- "pl": "* naprawiono tworzenie obiektów dla ulubionych",
94
- "uk": "* виправлено створення об'єктів для обраних",
95
- "zh-cn": "* 修复收藏夹的对象创建"
96
96
  }
97
97
  },
98
- "title": "SqueezeboxRPC: Controller for Logitech media Server over RPC-protokol",
99
98
  "titleLang": {
100
99
  "en": "SqueezeboxRPC: Controller for Logitech media Server over RPC-protokol",
101
100
  "de": "SqueezeboxRPC: Controller für Logitech Media Server über RPC-Protokoll",
@@ -126,17 +125,16 @@
126
125
  "oweitman <oweitman@gmx.de>"
127
126
  ],
128
127
  "keywords": [
129
- "ioBroker",
130
- "template",
131
- "Smart Home",
132
- "home automation"
128
+ "squeezebox",
129
+ "LMS",
130
+ "Logitech Media Server",
131
+ "music server"
133
132
  ],
134
133
  "licenseInformation": {
135
134
  "type": "free",
136
135
  "license": "MIT"
137
136
  },
138
137
  "platform": "Javascript/Node.js",
139
- "main": "squeezeboxrpc.js",
140
138
  "icon": "squeezeboxrpc.png",
141
139
  "enabled": true,
142
140
  "extIcon": "https://raw.githubusercontent.com/oweitman/ioBroker.squeezeboxrpc/main/admin/squeezeboxrpc.png",
@@ -157,7 +155,7 @@
157
155
  },
158
156
  "dependencies": [
159
157
  {
160
- "js-controller": ">=3.3.22"
158
+ "js-controller": ">=5.0.19"
161
159
  }
162
160
  ],
163
161
  "globalDependencies": [
@@ -166,6 +164,12 @@
166
164
  }
167
165
  ]
168
166
  },
167
+ "encryptedNative": [
168
+ "password"
169
+ ],
170
+ "protectedNative": [
171
+ "password"
172
+ ],
169
173
  "native": {
170
174
  "server": "0.0.0.0",
171
175
  "port": 9000,
package/lib/iosbplayer.js CHANGED
@@ -752,6 +752,12 @@ function ioSBPlayer(server, playerdata) {
752
752
  }
753
753
  }
754
754
  if (idParts[0] == "cmdGoTime") {
755
+ // state.val needs to be a string, although the time is set in seconds
756
+ // when settings cmdGoTime via ioBroker.simple-api its not possible to submit a number as string
757
+ // if we receive a number, we need to cast this to a string
758
+ if (typeof state.val === "number") {
759
+ state.val = state.val.toString();
760
+ }
755
761
  if (state.val.trim() !== "" && !isNaN(state.val.trim())) {
756
762
  this.request(this.playerid, ["time", state.val.trim()]);
757
763
  this.setState(idParts[0], " ", this.statePath, this.playername, false);
package/lib/iosbserver.js CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  //const utils = require('@iobroker/adapter-core');
5
5
  const dgram = require('dgram');
6
- const SqueezeServer = require('squeezenode-oweitman');
6
+ const SqueezeServerNew = require(__dirname + '/squeezenode/squeezeserver');
7
7
  const ioSBPlayer = require(__dirname + '/iosbplayer');
8
8
 
9
9
  function IoSbServer(adapter) {
@@ -212,7 +212,7 @@ function IoSbServer(adapter) {
212
212
  this.adapter.setState('info.connection', false, true);
213
213
  this.adapter.subscribeStates('*');
214
214
 
215
- this.sbServer = (adapter.config.username != "") ? new SqueezeServer('http://' + this.adapter.config.server, Number.parseInt(this.adapter.config.port), adapter.config.username, adapter.config.password) : new SqueezeServer('http://' + this.adapter.config.server, Number.parseInt(this.adapter.config.port));
215
+ this.sbServer = (adapter.config.username != "") ? new SqueezeServerNew('http://' + this.adapter.config.server, Number.parseInt(this.adapter.config.port), adapter.config.username, adapter.config.password) : new SqueezeServerNew('http://' + this.adapter.config.server, Number.parseInt(this.adapter.config.port));
216
216
 
217
217
  this.log = {};
218
218
  this.islogsilly = this.adapter.config.outputserversilly;
@@ -0,0 +1,483 @@
1
+ /*
2
+ The MIT License (MIT)
3
+ Copyright (c) 2013-2015 Piotr Raczynski, pio[dot]raczynski[at]gmail[dot]com
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18
+ SOFTWARE.
19
+ */
20
+
21
+ var _ = require('lodash');
22
+ var inherits = require('super');
23
+ var SqueezeRequest = require('./squeezerequest');
24
+
25
+ /**
26
+ * Create a SqueezePlayer object
27
+ *
28
+ * @param playerId The ID of the player
29
+ * @param name The name of the player
30
+ * @param address The URL of the server
31
+ * @param port The port that the server listens on
32
+ * @param username The username for authentication
33
+ * @param password The password for authentication
34
+ */
35
+
36
+ function SqueezePlayer(playerId, name, address, port, username, password) {
37
+
38
+ this.playerId = playerId;
39
+ this.name = name;
40
+
41
+ SqueezePlayer.super_.apply(this, [address, port, username, password]);
42
+
43
+ /**
44
+ * @method callMethod
45
+ *
46
+ * You can use this function to call any available method in the Logitech
47
+ * Media Server API. The documentation for the API can be found here -
48
+ * `http://<your-server-ip>:9000/html/docs/help.html`
49
+ *
50
+ * ...then click on "Technical Information"
51
+ * ...then click on "The Logitech Media Server Command Line Interface"
52
+ *
53
+ * (God, they don't make it easy...)
54
+ *
55
+ * You can then use `callMethod` for anything, like so,
56
+ * @example
57
+ * squeezePlayer.callMethod({
58
+ * playerId: myPlayerId,
59
+ * method: 'mixer',
60
+ * params: ['volume', '?'],
61
+ * callback: myCallbackFunction
62
+ * });
63
+ *
64
+ * While `callMethod` can be used to execute any of the LMS API methods, the additional
65
+ * functions below (e.g `play`, `clearPlayList`, etc) may be more convenient and easier
66
+ * to remember. Use whichever you prefer. `callMethod` is designed to provide flexibility
67
+ * for calling methods that have not been explicitly defined on the SqueezePlayer
68
+ * object. Plus, it supports promises! 🙀
69
+ *
70
+ * @param Object opts - The options object for the request.
71
+ * @param string opts.method - The method name. Required.
72
+ * @param array opts.params - The additional parameters for the request. Required.
73
+ * @param function [opts.callback] - The callback function. Optional. If you don't
74
+ * provide a callback, a promise will be returned.
75
+ * @throws Throws an error is opts.method is empty.
76
+ * @returns Promise|Undefined
77
+ *
78
+ */
79
+
80
+ this.callMethod = function (opts) {
81
+
82
+ if (_.isUndefined(opts.method)) {
83
+ throw Error('Method name missing.');
84
+ }
85
+
86
+ var params = _.flatten([
87
+ _.get(opts, 'method'),
88
+ _.get(opts, 'params'),
89
+ ]);
90
+
91
+ var cb = _.get(opts, 'callback');
92
+
93
+ if (cb) {
94
+ this.request(this.playerId, params, cb);
95
+ } else {
96
+ return new Promise(_.bind(function (resolve, reject) {
97
+ this.request(
98
+ this.playerId,
99
+ params,
100
+ function (result) {
101
+ if (!result.ok) {
102
+ reject(result);
103
+ } else {
104
+ resolve(result);
105
+ }
106
+ }
107
+ );
108
+ }, this));
109
+ }
110
+ };
111
+
112
+ /**
113
+ * Clear the playlist for this player.
114
+ *
115
+ * @param callback The function to call with the result
116
+ */
117
+
118
+ this.clearPlayList = function (callback) {
119
+ this.request(playerId, ["playlist", "clear"], callback);
120
+ };
121
+
122
+ /**
123
+ * Get the current state of the player. i.e. playing, paused or stopped.
124
+ *
125
+ * @param callback The function to call with the result
126
+ */
127
+
128
+ this.getMode = function (callback) {
129
+ this.request(playerId, ["mode", "?"], callback);
130
+ };
131
+
132
+ /**
133
+ * Set the name of the player.
134
+ *
135
+ * @param name The new name for the player
136
+ * @param callback The function to call with the result
137
+ */
138
+
139
+ this.setName = function (name, callback) {
140
+ this.request(playerId, ["name", name], callback);
141
+ };
142
+
143
+ /**
144
+ * Get the name of the player.
145
+ *
146
+ * @param callback The function to call with the result
147
+ */
148
+
149
+ this.getName = function (callback) {
150
+ this.request(playerId, ["name", "?"], callback);
151
+ };
152
+
153
+ /**
154
+ * Get the title of the current song playing.
155
+ *
156
+ * @param callback The function to call with the result
157
+ */
158
+
159
+ this.getCurrentTitle = function (callback) {
160
+ this.request(playerId, ["current_title", "?"], function (reply) {
161
+ if (reply.ok)
162
+ reply.result = reply.result._current_title;
163
+ callback(reply);
164
+ });
165
+ };
166
+
167
+ /**
168
+ * Get the artist of the current song playing.
169
+ *
170
+ * @param callback The function to call with the result
171
+ */
172
+
173
+ this.getArtist = function (callback) {
174
+ this.request(playerId, ["artist", "?"], function (reply) {
175
+ if (reply.ok)
176
+ reply.result = reply.result._artist;
177
+ callback(reply);
178
+ });
179
+ };
180
+
181
+ /**
182
+ * Get the album of the current song playing.
183
+ *
184
+ * @param callback The function to call with the result
185
+ */
186
+
187
+ this.getAlbum = function (callback) {
188
+ this.request(playerId, ["album", "?"], function (reply) {
189
+ if (reply.ok)
190
+ reply.result = reply.result._album;
191
+ callback(reply);
192
+ });
193
+ };
194
+
195
+ /**
196
+ * Get the remoteMeta part of the status of the player.
197
+ *
198
+ * @param callback The function to call with the result
199
+ */
200
+
201
+ this.getCurrentRemoteMeta = function (callback) {
202
+ this.request(playerId, ["status"], function (reply) {
203
+ if (reply.ok)
204
+ reply.result = reply.result.remoteMeta;
205
+ callback(reply);
206
+ });
207
+ };
208
+
209
+ /**
210
+ * Get the complete status of the player.
211
+ *
212
+ * @param callback The function to call with the result
213
+ */
214
+
215
+ this.getStatus = function (callback) {
216
+ this.request(playerId, ["status"], callback);
217
+ };
218
+
219
+ /**
220
+ * Get the status with part of the current playlist.
221
+ *
222
+ * @param from The place in the playlist to start getting information
223
+ * @param to The place in the playlist to get information up to
224
+ * @param callback The function to call with the result
225
+ */
226
+
227
+ this.getStatusWithPlaylist = function (from, to, callback) {
228
+ this.request(playerId, ["status", from, to], function (reply) {
229
+ if (reply.ok)
230
+ reply.result = reply.result;
231
+ callback(reply);
232
+ });
233
+ };
234
+
235
+ /**
236
+ * Get a portion of the playlist.
237
+ *
238
+ * @param from The place in the playlist to start getting information
239
+ * @param to The place in the playlist to get information up to
240
+ * @param callback The function to call with the result
241
+ */
242
+
243
+ this.getPlaylist = function (from, to, callback) {
244
+ this.request(playerId, ["status", from, to], function (reply) {
245
+ if (reply.ok)
246
+ reply.result = reply.result.playlist_loop;
247
+ callback(reply);
248
+ });
249
+ };
250
+
251
+ /**
252
+ * Start the player playing.
253
+ *
254
+ * @param callback The function to call with the result
255
+ */
256
+
257
+ this.play = function (callback) {
258
+ this.request(playerId, ["play"], callback);
259
+ };
260
+
261
+ /**
262
+ * Play a specific song in the playlist.
263
+ *
264
+ * @param index The index of the song to play.
265
+ * @param callback The function to call with the result
266
+ */
267
+
268
+ this.playIndex = function (index, callback) {
269
+ this.request(playerId, ["playlist", "index", index], callback);
270
+ };
271
+
272
+ /**
273
+ * Pause or unpause the player.
274
+ *
275
+ * @param state 1 to pause, 0 to unpause
276
+ * @param callback The function to call with the result
277
+ */
278
+
279
+ this.pause = function (state, callback) {
280
+ this.request(playerId, ["pause", state ? "1" : "0"], callback);
281
+ };
282
+
283
+ /**
284
+ * Toggle the pause state of the player.
285
+ *
286
+ * @param callback The function to call with the result
287
+ */
288
+
289
+ this.togglepause = function (callback) {
290
+ this.request(playerId, ["pause"], callback);
291
+ };
292
+
293
+ /**
294
+ * Move the player to the previous song in the playlist.
295
+ *
296
+ * @param callback The function to call with the result
297
+ */
298
+
299
+ this.previous = function (callback) {
300
+ this.request(playerId, ["button", "jump_rew"], callback);
301
+ };
302
+
303
+ /**
304
+ * Move the player to the next song in the playlist.
305
+ *
306
+ * @param callback The function to call with the result
307
+ */
308
+
309
+ this.next = function (callback) {
310
+ this.request(playerId, ["button", "jump_fwd"], callback);
311
+ };
312
+
313
+ /**
314
+ * Delete a song from the playlist.
315
+ *
316
+ * @param index The index of the song to delete
317
+ * @param callback The function to call with the result
318
+ */
319
+
320
+ this.playlistDelete = function (index, callback) {
321
+ this.request(playerId, ["playlist", "delete", index], callback);
322
+ };
323
+
324
+ /**
325
+ * Move a song in the playlist.
326
+ *
327
+ * @param fromIndex The index to move the song from
328
+ * @param toIndex The index to move the song to
329
+ * @param callback The function to call with the result
330
+ */
331
+
332
+ this.playlistMove = function (fromIndex, toIndex, callback) {
333
+ this.request(playerId, ["playlist", "move", fromIndex, toIndex], callback);
334
+ };
335
+
336
+ /**
337
+ * Save the current playlist.
338
+ *
339
+ * @param playlistName The name to save the playlist as.
340
+ * @param callback The function to call with the result
341
+ */
342
+
343
+ this.playlistSave = function (playlistName, callback) {
344
+ this.request(playerId, ["playlist", "save", playlistName], callback);
345
+ };
346
+
347
+ /**
348
+ * Sync the current player to another.
349
+ *
350
+ * @param syncTo The index or playerId to sync to
351
+ * @param callback The function to call with the result
352
+ */
353
+
354
+ this.sync = function (syncTo, callback) {
355
+ this.request(playerId, ["sync", syncTo], callback);
356
+ };
357
+
358
+ /**
359
+ * Unsync the current player.
360
+ *
361
+ * @param callback The function to call with the result
362
+ */
363
+
364
+ this.unSync = function (callback) {
365
+ this.request(playerId, ["sync", "-"], callback);
366
+ };
367
+
368
+ /**
369
+ * Move the playback of the current song to a specific point.
370
+ *
371
+ * @param seconds The time in the song to move to
372
+ * @param callback The function to call with the result
373
+ */
374
+
375
+ this.seek = function (seconds, callback) {
376
+ this.request(playerId, ["time", seconds], callback);
377
+ };
378
+
379
+ /**
380
+ * Set the volume of the player.
381
+ *
382
+ * @param volume The volume to set to between 0 and 100
383
+ * @param callback The function to call with the result
384
+ */
385
+
386
+ this.setVolume = function (volume, callback) {
387
+ this.request(playerId, ["mixer", "volume", volume], callback);
388
+ };
389
+
390
+ /**
391
+ * Get the current volume of the player.
392
+ *
393
+ * @param callback The function to call with the result
394
+ */
395
+
396
+ this.getVolume = function (callback) {
397
+ this.request(playerId, ["mixer", "volume", "?"], function (reply) {
398
+ if (reply.ok)
399
+ reply.result = reply.result._volume;
400
+ callback(reply);
401
+ });
402
+ };
403
+
404
+ /**
405
+ * Create and play a random list.
406
+ *
407
+ * @param target The type of list to generate, e.g. tracks, albums, contributors, year
408
+ * @param callback The function to call with the result
409
+ */
410
+
411
+ this.randomPlay = function (target, callback) {
412
+ this.request(playerId, ["randomplay", target], callback);
413
+ };
414
+
415
+ /**
416
+ * Turn on or off the player.
417
+ *
418
+ * @param state 0 to turn the player off, 0 to turn it on
419
+ * @param callback The function to call with the result
420
+ */
421
+
422
+ this.power = function (state, callback) {
423
+ this.request(playerId, ["power", state ? "1" : "0"], callback);
424
+ };
425
+
426
+ /**
427
+ * Play a favourite
428
+ *
429
+ * @param favorite The ID of the item to play
430
+ * @param callback The function to call with the result
431
+ */
432
+
433
+ this.playFavorite = function (favorite, callback) {
434
+ this.request(playerId, ["favorites", "playlist", "play", "item_id:" + favorite], callback);
435
+ };
436
+
437
+ /**
438
+ * Add an item to the playlist.
439
+ *
440
+ * @param item The item to add to the playlist
441
+ * @param callback The function to call with the result
442
+ */
443
+
444
+ this.addToPlaylist = function (item, callback) {
445
+ this.request(playerId, ["playlist", "add", item], callback);
446
+ };
447
+
448
+ /**
449
+ * Insert an item into the playlist to be played immediately.
450
+ *
451
+ * @param item The item to insert
452
+ * @param callback The function to call with the result
453
+ */
454
+
455
+ this.insertToPlaylist = function (item, callback) {
456
+ this.request(playerId, ["playlist", "insert", item], callback);
457
+ };
458
+
459
+ /**
460
+ * Set the shuffle state of the current playlist.
461
+ *
462
+ * @param state The state to set the list to, 0 no shuffle, 1 to shuffle
463
+ * @param callback The function to call with the result
464
+ */
465
+
466
+ this.shuffle = function (state, callback) {
467
+ this.request(playerId, ["playlist", "shuffle", state ? "1" : "0"], callback);
468
+ };
469
+
470
+ /**
471
+ * Function to set Linein mode on Squeezebox Boom
472
+ *
473
+ * @param callback The function to call with the result
474
+ */
475
+
476
+ this.setLinein = function (callback) {
477
+ this.request(playerId, ["setlinein", "linein"], callback);
478
+ };
479
+ }
480
+
481
+ inherits(SqueezePlayer, SqueezeRequest);
482
+
483
+ module.exports = SqueezePlayer;
@@ -0,0 +1,265 @@
1
+ /*
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2013-2015 Piotr Raczynski, pio[dot]raczynski[at]gmail[dot]com
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
25
+ const jayson = require("jayson");
26
+ const inherits = require("super");
27
+ let AWS;
28
+
29
+
30
+ // address "<http|https>://|hostbame[:port]"
31
+ // transport "<[0-9]*|sqs[://region]|ssh://password:username@hostname:port"
32
+ // sqs password = {send: "Queue URL, recv "Queue URL" }
33
+
34
+ function SqueezeRequest(address, port, username, password) {
35
+ // FIXME URI
36
+ this.address = (typeof address !== "string") ? "localhost" : address;
37
+ this.port = (port !== undefined) ? port : 9000;
38
+ this.username = username;
39
+ this.password = password;
40
+ this.id = "squeezenode." + process.pid;// FIXME lamba seems to be 1 always add instance?
41
+ this.queue = [];
42
+ const that = this;
43
+
44
+ /**
45
+ * Function to handle responses
46
+ *
47
+ * @param err An error message
48
+ * @param reply The reply
49
+ * @param callback The function to call with the result
50
+ */
51
+ function handle(err, reply, callback) {
52
+ let result = {};
53
+ if (err) {
54
+ result = err;
55
+ result.ok = false;
56
+ } else {
57
+ result = reply;
58
+ result.ok = true;
59
+ }
60
+
61
+ if (callback)
62
+ callback(result);
63
+ }
64
+
65
+ // Set up to use an AWS SQS queue URL to communicate
66
+ if (typeof port === "string" && port.substr(0, 3) === "ssh") {
67
+ const { URL } = require("url");
68
+ const turl = new URL(this.port);
69
+ const surl = new URL(this.address);
70
+ const fp = 9192;
71
+ const Tunnel = require("tunnel-ssh");
72
+ const tunnel_config = {
73
+ // transport url
74
+ host: turl.hostname,
75
+ port: (turl.port) ? turl.port : 22,
76
+ username: turl.username,
77
+ // server url
78
+ dstPort: (surl.port) ? surl.port : 9000,
79
+ dstHost: surl.hostname,
80
+ // forward url?
81
+ localPort: fp,
82
+ //localHost: ,
83
+ keepAlive: true,
84
+ };
85
+ const tp = decodeURIComponent(turl.password);
86
+ console.log(tp);
87
+ if (tp.substr(0, 7) === "file://") {
88
+ tunnel_config["privateKey"] = require("fs").readFileSync(tp.substr(7));
89
+ } else {
90
+ tunnel_config["password"] = turl.password;
91
+ }
92
+ console.log(tunnel_config);
93
+ this.ssh_tunnel = Tunnel(tunnel_config, function (error, server) {
94
+ if (error) {
95
+ console.log(error);
96
+ }
97
+ });
98
+
99
+ // Use a listener to handle errors outside the callback
100
+ this.ssh_tunnel.on("error", function (err) {
101
+ console.error("SSH Tunnel:", err);
102
+ console.log("Tunnel error");
103
+ });
104
+ this.address = surl.protocol + "//localhost";
105
+ this.port = fp;
106
+ console.log(surl);
107
+ }
108
+
109
+ if (typeof this.port === "string" && this.port.substr(0, 6) === "awssqs") {
110
+ AWS = require("aws-sdk");
111
+ this.request = request_sqs;
112
+ // FIXME decode region from url
113
+ this.sqs = new AWS.SQS({ region: "us-west-2" });
114
+ this.sendq = { QueueUrl: password.send, MessageGroupId: this.id };
115
+ this.recvq = { QueueUrl: password.recv, WaitTimeSeconds: 0, MaxNumberOfMessages: 10 };
116
+ this.reciving = true;
117
+ this.sqs.receiveMessage(that.recvq, function (err, reply) {
118
+ that.recvq.MaxNumberOfMessages = 1;
119
+ that.recvq.WaitTimeSeconds = 20;
120
+ if (reply.Messages) {
121
+ let msg = reply.Messages.pop();
122
+ while (msg) {
123
+ const deleteParams = {
124
+ QueueUrl: that.recvq.QueueUrl,
125
+ ReceiptHandle: msg.ReceiptHandle
126
+ };
127
+ that.sqs.deleteMessage(deleteParams, function (err, data) {
128
+ //
129
+ });
130
+ msg = reply.Messages.pop();
131
+ }
132
+ }
133
+ request_sqs_dispatch_queue();
134
+ }); //Drain Q.
135
+
136
+ } else {
137
+ // Use JSON RPC to communicate
138
+ this.request = request_rpc;
139
+
140
+ const jsonrpc = (typeof this.port === "number") ? this.address + ":" + this.port + "/jsonrpc.js" : this.address + "/jsonrpc.js";
141
+ client = (this.address.substr(0, 5) === "https") ? jayson.client.https(jsonrpc) : client = jayson.client.http(jsonrpc);
142
+ client.options.version = 1;
143
+
144
+ // FIXME URL
145
+ // Add a header for basic authentication if a username and password are given
146
+ if (username && password) {
147
+ if (!client.options.headers)
148
+ client.options.headers = {};
149
+ client.options.headers["Authorization"] = formatBasicHeader(username, password);
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Request function for JSON RPC
155
+ *
156
+ * @param player The target player
157
+ * @param params Request parameters
158
+ * @param callback The function to call with the result
159
+ */
160
+
161
+ function request_rpc(player, params, callback) {
162
+
163
+ client.request("slim.request", [player, params], that.id, function (err, reply) {
164
+ handle(err, reply, callback);
165
+ });
166
+ }
167
+
168
+ /**
169
+ * Request function to use AWS SQS
170
+ *
171
+ * @param player The target player
172
+ * @param params Request parameters
173
+ * @param callback The function to call with the result
174
+ */
175
+
176
+ function request_sqs_dispatch(player, params, callback) {
177
+
178
+ that.sendq["MessageBody"] = JSON.stringify({
179
+ "params": [player, params],
180
+ "id": that.id + process.hrtime(),
181
+ "version": "1.0",
182
+ "method": "slim.request"
183
+ }); // FIXME id not on pid but an uuid? for instrance from env?
184
+ that.sendq["MessageDeduplicationId"] = that.sendq.MessageGroupId + process.hrtime();
185
+ //console.log("send ",that.sendq['MessageBody']);
186
+ that.sqs.sendMessage(that.sendq, function (err, data) {
187
+ if (err) {
188
+ handle(err, data, callback);
189
+ console.error("Send Error ", err);
190
+ } else {
191
+ // successful response - callback for reply
192
+ that.reciving = true;
193
+ that.sqs.receiveMessage(that.recvq, function (err, reply) {
194
+ //console.log("reply data ",reply);
195
+ let message_data = {};
196
+ if (reply.Messages) {
197
+
198
+ //id check?
199
+
200
+ message_data = reply.Messages.pop();
201
+
202
+ //delete and drain?
203
+
204
+ let msg = message_data;
205
+ message_data = JSON.parse(message_data.Body);
206
+ //console.log("reply ",message_data);
207
+ while (msg) {
208
+ const deleteParams = {
209
+ QueueUrl: that.recvq.QueueUrl,
210
+ ReceiptHandle: msg.ReceiptHandle
211
+ };
212
+ // FIXME delete error
213
+ that.sqs.deleteMessage(deleteParams, function (err, data) {
214
+ if (err) {
215
+ console.error("Delete Error", err);
216
+ } else {
217
+ //console.log("Message Deleted", data);
218
+ }
219
+ });
220
+ msg = reply.Messages.pop();
221
+ }
222
+
223
+ } else {
224
+ console.warn("no msgs ", err);
225
+ err = "No reply message recvied";
226
+ }
227
+
228
+ handle(err, message_data, callback);
229
+ request_sqs_dispatch_queue();
230
+ });
231
+ }
232
+ });
233
+ }
234
+
235
+ // We need to serialise requests and responces for queue use
236
+
237
+ function request_sqs(player, params, callback) {
238
+ if (that.reciving) {
239
+ that.queue.push([player, params, callback]);
240
+ } else {
241
+ request_sqs_dispatch(player, params, callback);
242
+ }
243
+ }
244
+
245
+ function request_sqs_dispatch_queue() {
246
+ const args = that.queue.pop();
247
+ if (args) {
248
+ request_sqs_dispatch.apply(null, args);
249
+ } else {
250
+ that.reciving = false;
251
+ }
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Function to format the header for basic authentication.
257
+ */
258
+
259
+ function formatBasicHeader(username, password) {
260
+ const tok = username + ":" + password;
261
+ const hash = new Buffer.from(tok).toString("base64");
262
+ return "Basic " + hash;
263
+ }
264
+
265
+ module.exports = SqueezeRequest;
@@ -0,0 +1,346 @@
1
+ /*
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2013 Piotr Raczynski, pio[dot]raczynski[at]gmail[dot]com
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
25
+ const inherits = require("super");
26
+ const fs = require("fs");
27
+ const SqueezeRequest = require(__dirname + "/squeezerequest");
28
+ const SqueezePlayer = require(__dirname + "/squeezeplayer");
29
+
30
+ /**
31
+ * Create a SqueezeServer object
32
+ *
33
+ * @param address The URL of the server
34
+ * @param port The port that the server listens on
35
+ * @param username The username for authentication
36
+ * @param password The password for authentication
37
+ * @param sa A flag to skip apps
38
+ */
39
+
40
+ function SqueezeServer(address, port, username, password, sa, sp) {
41
+
42
+ SqueezeServer.super_.apply(this, arguments);
43
+ const defaultPlayer = "00:00:00:00:00:00";
44
+ const self = this;
45
+ this.players = [];
46
+ this.apps = [];
47
+ const subs = {};
48
+
49
+ /**
50
+ * Subscribe to an event on a channel
51
+ *
52
+ * @param channel The channel that received the event
53
+ * @param sub The callback for the event
54
+ */
55
+
56
+ this.on = function (channel, sub) {
57
+
58
+ subs[channel] = subs[channel] || [];
59
+ subs[channel].push(sub);
60
+ };
61
+
62
+ /**
63
+ * Send an event.
64
+ *
65
+ * @param channel The even channel
66
+ */
67
+
68
+ this.emit = function (channel) {
69
+
70
+ const args = [].slice.call(arguments, 1);
71
+ for (const sub in subs[channel]) {
72
+ subs[channel][sub].apply(void 0, args);
73
+ }
74
+ };
75
+
76
+ /**
77
+ * Method to the the number of players.
78
+ *
79
+ * @param callback The function to call with the result.
80
+ */
81
+
82
+ this.getPlayerCount = function (callback) {
83
+ this.request(defaultPlayer, ["player", "count", "?"], callback);
84
+ };
85
+
86
+ /**
87
+ * Method to get the ID of a player given it's index
88
+ *
89
+ * @param index The index of the player to get the ID for
90
+ * @param callback The function to call with the result.
91
+ */
92
+
93
+ this.getPlayerId = function (index, callback) {
94
+ this.request(defaultPlayer, ["player", "id", index, "?"], callback);
95
+ };
96
+
97
+ /**
98
+ * Method to get the IP address of a player
99
+ *
100
+ * @param playerId The ID or index of the player
101
+ * @param callback The function to call with the result.
102
+ */
103
+
104
+ this.getPlayerIp = function (playerId, callback) {
105
+ this.request(defaultPlayer, ["player", "ip", playerId, "?"], callback);
106
+ };
107
+
108
+ /**
109
+ * Method to get the name of a player.
110
+ *
111
+ * @param playerId The ID or index of the player
112
+ * @param callback The function to call with the result.
113
+ */
114
+
115
+ this.getPlayerName = function (playerId, callback) {
116
+ this.request(defaultPlayer, ["player", "name", playerId, "?"], callback);
117
+ };
118
+
119
+ /**
120
+ * Get a list of the synchronization group members
121
+ *
122
+ * @param callback The function to call with the result.
123
+ */
124
+
125
+ this.getSyncGroups = function (callback) {
126
+ this.request(defaultPlayer, ["syncgroups", "?"], callback);
127
+ };
128
+
129
+ /**
130
+ * Get a list of the apps installed in the server
131
+ *
132
+ * @param callback The function to call with the result.
133
+ */
134
+
135
+ this.getApps = function (callback) {
136
+ this.request(defaultPlayer, ["apps", 0, 100], callback);
137
+ };
138
+
139
+ //
140
+
141
+ /**
142
+ * Get the content of a music folder.
143
+ *
144
+ * @param folderId The ID of the folder to get. Pass 0 or empty string "" to display root of music folder
145
+ * @param callback The function to call with the result.
146
+ */
147
+
148
+ this.musicfolder = function (folderId, callback) {
149
+ this.request(defaultPlayer, ["musicfolder", 0, 100, "folder_id:" + folderId], callback);
150
+ };
151
+
152
+ /**
153
+ * Get a information about the players.
154
+ *
155
+ * @param callback The function to call with the result.
156
+ */
157
+
158
+ this.getPlayers = function (callback) {
159
+
160
+ self.request(defaultPlayer, ["players", 0, 100], function (reply) {
161
+ if (reply.ok)
162
+ reply.result = reply.result.players_loop;
163
+ callback(reply);
164
+ });
165
+ };
166
+
167
+ /**
168
+ * Get a list of the artists from the server
169
+ *
170
+ * @param callback The callback to call with the result
171
+ * @param limit The maximum number of results
172
+ */
173
+
174
+ this.getArtists = function (callback, limit) {
175
+
176
+ self.request(defaultPlayer, ["artists", 0, limit], function (reply) {
177
+ if (reply.ok)
178
+ reply.result = reply.result.artists_loop;
179
+ callback(reply);
180
+ });
181
+ };
182
+
183
+ /**
184
+ * Get a list of the albums from the server
185
+ *
186
+ * @param callback The callback to call with the result
187
+ * @param limit The maximum number of results
188
+ */
189
+
190
+ this.getAlbums = function (callback, limit) {
191
+
192
+ self.request(defaultPlayer, ["albums", 0, limit], function (reply) {
193
+ if (reply.ok)
194
+ reply.result = reply.result.albums_loop;
195
+ callback(reply);
196
+ });
197
+ };
198
+
199
+ /**
200
+ * Get a list of the genre's from the server
201
+ *
202
+ * @param callback The callback to call with the result
203
+ * @param limit The maximum number of results
204
+ */
205
+
206
+ this.getGenres = function (callback, limit) {
207
+
208
+ self.request(defaultPlayer, ["genres", 0, limit], function (reply) {
209
+ if (reply.ok)
210
+ reply.result = reply.result.genres_loop;
211
+ callback(reply);
212
+ });
213
+ };
214
+
215
+ /**
216
+ * Get a 'info' list from the server
217
+ *
218
+ * @param callback The callback to call with the result
219
+ * @param limit The maximum number of results
220
+ * @param slot The query to make to the server [genres, albums, artists, playlists ]
221
+ */
222
+
223
+ this.getInfo = function (callback, limit, slot) {
224
+
225
+ self.request(defaultPlayer, [slot, 0, limit], function (reply) {
226
+ if (reply.ok)
227
+ reply.result = reply.result[slot + "_loop"];
228
+ callback(reply);
229
+ });
230
+ };
231
+
232
+ this.registerPlayers = function (players) {
233
+ for (const pl in players) {
234
+ if (!self.players[players[pl].playerid]) { // player not on the list
235
+ self.players[players[pl].playerid] = new SqueezePlayer(players[pl].playerid, players[pl].name, self.address, self.port, self.username, self.password);
236
+ }
237
+ }
238
+ };
239
+
240
+ /**
241
+ * Get Player oject for name, needs the players registred and normisles names with a lc search removeving puntuation
242
+ *
243
+ * @param name string
244
+ * @param only reten the one player if only one
245
+ */
246
+ this.findPlayerObjectByName = function (name, only) {
247
+ name = this.normalizePlayer(name);
248
+
249
+ // Look for the player in the players list that matches the given name. Then return the corresponding player object
250
+ // from the squeezeserver stored by the player's id
251
+
252
+ for (const id in this.players) {
253
+ if (
254
+ this.normalizePlayer(this.players[id].name) === name || // name matches the requested player
255
+ (name === "" && (only && this.players.length === 1)) // name is undefined and there's only one player,
256
+ // so assume that's the one we want.
257
+ ) {
258
+ return this.players[id];
259
+ }
260
+ }
261
+ return undefined;
262
+ };
263
+
264
+ /**
265
+ * Do any necessary clean up of player names
266
+ *
267
+ * @param playerName The name of the player to clean up
268
+ * @param filter optional fn(str) returns str
269
+ * @returns The normalized player name
270
+ */
271
+
272
+ this.normalizePlayer = function (playerName) {
273
+
274
+ playerName || (playerName = ""); // protect against `playerName` being undefined
275
+ playerName = playerName.replace("-", " ");
276
+ playerName = playerName.replace(" ", " ");
277
+ playerName = playerName.replace(" ", " ");
278
+ playerName = playerName.toLowerCase(playerName);
279
+
280
+ return playerName;
281
+ };
282
+
283
+ /**
284
+ * Find out if we can contact the server and get some basic information
285
+ *
286
+ * @param skipApps A flag to skip getting information about the apps
287
+ */
288
+
289
+ function register(skipApps, skipPlayers) {
290
+
291
+ if (!skipPlayers) {
292
+ // Get the list of players from the server
293
+ self.getPlayers(function (reply) {
294
+ // Process the player information and create Player objects for each one
295
+ if (reply.ok)
296
+ self.registerPlayers(reply.result);
297
+
298
+ // Send a signal that we are done
299
+ if (skipApps) {
300
+ self.emit("register", reply, undefined);
301
+ } else {
302
+ self.emit("registerPlayers", reply);
303
+ }
304
+ });
305
+ }
306
+
307
+ if (!skipApps) {
308
+ // Once the players have been obtained, request a list of the apps
309
+ self.on("registerPlayers", function (reply) {
310
+
311
+ self.getApps(function (areply) {
312
+
313
+ if (areply.ok) {
314
+
315
+ const apps = areply.result.appss_loop;
316
+ const dir = __dirname + "/";
317
+ fs.readdir(dir, function (err, files) {
318
+ files.forEach(function (file) {
319
+
320
+ const fil = file.substr(0, file.lastIndexOf("."));
321
+ for (const pl in apps) {
322
+ if (fil === apps[pl].cmd) {
323
+ const app = require(dir + file);
324
+ self.apps[apps[pl].cmd] = new app(defaultPlayer, apps[pl].name, apps[pl].cmd, self.address, self.port, self.username, self.password);
325
+ /* workaround, app needs existing player id so first is used here */
326
+ }
327
+ }
328
+ });
329
+
330
+ self.emit("register", reply, areply);
331
+ });
332
+
333
+ } else {
334
+ self.emit("register", reply, areply);
335
+ }
336
+ });
337
+ });
338
+ }
339
+ }
340
+
341
+ register(sa, sp);
342
+ }
343
+
344
+ inherits(SqueezeServer, SqueezeRequest);
345
+
346
+ module.exports = SqueezeServer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.squeezeboxrpc",
3
- "version": "1.3.11",
3
+ "version": "1.3.12",
4
4
  "description": "ioBroker Logitech Squeezebox Adapter over JSON/RPC-Protocol",
5
5
  "author": {
6
6
  "name": "oweitman",
@@ -10,8 +10,10 @@
10
10
  "license": "MIT",
11
11
  "keywords": [
12
12
  "ioBroker",
13
- "Smart Home",
14
- "home automation"
13
+ "squeezebox",
14
+ "LMS",
15
+ "Logitech Media Server",
16
+ "music server"
15
17
  ],
16
18
  "repository": {
17
19
  "type": "git",
@@ -22,7 +24,10 @@
22
24
  },
23
25
  "dependencies": {
24
26
  "@iobroker/adapter-core": "^3.1.6",
25
- "squeezenode-oweitman": "https://github.com/oweitman/squeezenode/tarball/master"
27
+ "jayson": "^3.2.0",
28
+ "lodash": "^4.17.4",
29
+ "request": "^2.88.0",
30
+ "super": "^0.2.3"
26
31
  },
27
32
  "devDependencies": {
28
33
  "@alcalzone/release-script": "^3.8.0",
@@ -40,8 +45,8 @@
40
45
  "@types/proxyquire": "^1.3.31",
41
46
  "@types/sinon": "^17.0.3",
42
47
  "@types/sinon-chai": "^3.2.12",
48
+ "axios": "^0.28.0",
43
49
  "chai": "^4.4.1",
44
- "axios": "^0.21.1",
45
50
  "chai-as-promised": "^7.1.2",
46
51
  "eslint": "^8.57.0",
47
52
  "eslint-config-prettier": "^9.1.0",