iobroker.squeezeboxrpc 2.0.2 → 3.0.0

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.
@@ -1,480 +0,0 @@
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
- function SqueezePlayer(playerId, name, address, port, username, password) {
36
- this.playerId = playerId;
37
- this.name = name;
38
-
39
- SqueezePlayer.super_.apply(this, [address, port, username, password]);
40
-
41
- /**
42
- * @function callMethod
43
- *
44
- * You can use this function to call any available method in the Logitech
45
- * Media Server API. The documentation for the API can be found here -
46
- * `http://<your-server-ip>:9000/html/docs/help.html`
47
- *
48
- * ...then click on "Technical Information"
49
- * ...then click on "The Logitech Media Server Command Line Interface"
50
- *
51
- * (God, they don't make it easy...)
52
- *
53
- * You can then use `callMethod` for anything, like so,
54
- * @example
55
- * squeezePlayer.callMethod({
56
- * playerId: myPlayerId,
57
- * method: 'mixer',
58
- * params: ['volume', '?'],
59
- * callback: myCallbackFunction
60
- * });
61
- *
62
- * While `callMethod` can be used to execute any of the LMS API methods, the additional
63
- * functions below (e.g `play`, `clearPlayList`, etc) may be more convenient and easier
64
- * to remember. Use whichever you prefer. `callMethod` is designed to provide flexibility
65
- * for calling methods that have not been explicitly defined on the SqueezePlayer
66
- * object. Plus, it supports promises! 🙀
67
- * @param Object opts - The options object for the request.
68
- * @param string opts.method - The method name. Required.
69
- * @param array opts.params - The additional parameters for the request. Required.
70
- * @param function [opts.callback] - The callback function. Optional. If you don't
71
- * provide a callback, a promise will be returned.
72
- * @throws {Error} Throws an error if opts.method is empty.
73
- * @returns Promise|Undefined
74
- */
75
-
76
- this.callMethod = function (opts) {
77
- if (_.isUndefined(opts.method)) {
78
- throw Error('Method name missing.');
79
- }
80
-
81
- var params = _.flatten([_.get(opts, 'method'), _.get(opts, 'params')]);
82
-
83
- var cb = _.get(opts, 'callback');
84
-
85
- if (cb) {
86
- this.request(this.playerId, params, cb);
87
- } else {
88
- return new Promise(
89
- _.bind(function (resolve, reject) {
90
- this.request(this.playerId, params, function (result) {
91
- if (!result.ok) {
92
- reject(result);
93
- } else {
94
- resolve(result);
95
- }
96
- });
97
- }, this),
98
- );
99
- }
100
- };
101
-
102
- /**
103
- * Clear the playlist for this player.
104
- *
105
- * @param callback The function to call with the result
106
- */
107
-
108
- this.clearPlayList = function (callback) {
109
- this.request(playerId, ['playlist', 'clear'], callback);
110
- };
111
-
112
- /**
113
- * Get the current state of the player. i.e. playing, paused or stopped.
114
- *
115
- * @param callback The function to call with the result
116
- */
117
-
118
- this.getMode = function (callback) {
119
- this.request(playerId, ['mode', '?'], callback);
120
- };
121
-
122
- /**
123
- * Set the name of the player.
124
- *
125
- * @param name The new name for the player
126
- * @param callback The function to call with the result
127
- */
128
-
129
- this.setName = function (name, callback) {
130
- this.request(playerId, ['name', name], callback);
131
- };
132
-
133
- /**
134
- * Get the name of the player.
135
- *
136
- * @param callback The function to call with the result
137
- */
138
-
139
- this.getName = function (callback) {
140
- this.request(playerId, ['name', '?'], callback);
141
- };
142
-
143
- /**
144
- * Get the title of the current song playing.
145
- *
146
- * @param callback The function to call with the result
147
- */
148
-
149
- this.getCurrentTitle = function (callback) {
150
- this.request(playerId, ['current_title', '?'], function (reply) {
151
- if (reply.ok) {
152
- reply.result = reply.result._current_title;
153
- }
154
- callback(reply);
155
- });
156
- };
157
-
158
- /**
159
- * Get the artist of the current song playing.
160
- *
161
- * @param callback The function to call with the result
162
- */
163
-
164
- this.getArtist = function (callback) {
165
- this.request(playerId, ['artist', '?'], function (reply) {
166
- if (reply.ok) {
167
- reply.result = reply.result._artist;
168
- }
169
- callback(reply);
170
- });
171
- };
172
-
173
- /**
174
- * Get the album of the current song playing.
175
- *
176
- * @param callback The function to call with the result
177
- */
178
-
179
- this.getAlbum = function (callback) {
180
- this.request(playerId, ['album', '?'], function (reply) {
181
- if (reply.ok) {
182
- reply.result = reply.result._album;
183
- }
184
- callback(reply);
185
- });
186
- };
187
-
188
- /**
189
- * Get the remoteMeta part of the status of the player.
190
- *
191
- * @param callback The function to call with the result
192
- */
193
-
194
- this.getCurrentRemoteMeta = function (callback) {
195
- this.request(playerId, ['status'], function (reply) {
196
- if (reply.ok) {
197
- reply.result = reply.result.remoteMeta;
198
- }
199
- callback(reply);
200
- });
201
- };
202
-
203
- /**
204
- * Get the complete status of the player.
205
- *
206
- * @param callback The function to call with the result
207
- */
208
-
209
- this.getStatus = function (callback) {
210
- this.request(playerId, ['status'], callback);
211
- };
212
-
213
- /**
214
- * Get the status with part of the current playlist.
215
- *
216
- * @param from The place in the playlist to start getting information
217
- * @param to The place in the playlist to get information up to
218
- * @param callback The function to call with the result
219
- */
220
-
221
- this.getStatusWithPlaylist = function (from, to, callback) {
222
- this.request(playerId, ['status', from, to], function (reply) {
223
- /* if (reply.ok) {
224
- reply.result = reply.result;
225
- } */
226
- callback(reply);
227
- });
228
- };
229
-
230
- /**
231
- * Get a portion of the playlist.
232
- *
233
- * @param from The place in the playlist to start getting information
234
- * @param to The place in the playlist to get information up to
235
- * @param callback The function to call with the result
236
- */
237
-
238
- this.getPlaylist = function (from, to, callback) {
239
- this.request(playerId, ['status', from, to], function (reply) {
240
- if (reply.ok) {
241
- reply.result = reply.result.playlist_loop;
242
- }
243
- callback(reply);
244
- });
245
- };
246
-
247
- /**
248
- * Start the player playing.
249
- *
250
- * @param callback The function to call with the result
251
- */
252
-
253
- this.play = function (callback) {
254
- this.request(playerId, ['play'], callback);
255
- };
256
-
257
- /**
258
- * Play a specific song in the playlist.
259
- *
260
- * @param index The index of the song to play.
261
- * @param callback The function to call with the result
262
- */
263
-
264
- this.playIndex = function (index, callback) {
265
- this.request(playerId, ['playlist', 'index', index], callback);
266
- };
267
-
268
- /**
269
- * Pause or unpause the player.
270
- *
271
- * @param state 1 to pause, 0 to unpause
272
- * @param callback The function to call with the result
273
- */
274
-
275
- this.pause = function (state, callback) {
276
- this.request(playerId, ['pause', state ? '1' : '0'], callback);
277
- };
278
-
279
- /**
280
- * Toggle the pause state of the player.
281
- *
282
- * @param callback The function to call with the result
283
- */
284
-
285
- this.togglepause = function (callback) {
286
- this.request(playerId, ['pause'], callback);
287
- };
288
-
289
- /**
290
- * Move the player to the previous song in the playlist.
291
- *
292
- * @param callback The function to call with the result
293
- */
294
-
295
- this.previous = function (callback) {
296
- this.request(playerId, ['button', 'jump_rew'], callback);
297
- };
298
-
299
- /**
300
- * Move the player to the next song in the playlist.
301
- *
302
- * @param callback The function to call with the result
303
- */
304
-
305
- this.next = function (callback) {
306
- this.request(playerId, ['button', 'jump_fwd'], callback);
307
- };
308
-
309
- /**
310
- * Delete a song from the playlist.
311
- *
312
- * @param index The index of the song to delete
313
- * @param callback The function to call with the result
314
- */
315
-
316
- this.playlistDelete = function (index, callback) {
317
- this.request(playerId, ['playlist', 'delete', index], callback);
318
- };
319
-
320
- /**
321
- * Move a song in the playlist.
322
- *
323
- * @param fromIndex The index to move the song from
324
- * @param toIndex The index to move the song to
325
- * @param callback The function to call with the result
326
- */
327
-
328
- this.playlistMove = function (fromIndex, toIndex, callback) {
329
- this.request(playerId, ['playlist', 'move', fromIndex, toIndex], callback);
330
- };
331
-
332
- /**
333
- * Save the current playlist.
334
- *
335
- * @param playlistName The name to save the playlist as.
336
- * @param callback The function to call with the result
337
- */
338
-
339
- this.playlistSave = function (playlistName, callback) {
340
- this.request(playerId, ['playlist', 'save', playlistName], callback);
341
- };
342
-
343
- /**
344
- * Sync the current player to another.
345
- *
346
- * @param syncTo The index or playerId to sync to
347
- * @param callback The function to call with the result
348
- */
349
-
350
- this.sync = function (syncTo, callback) {
351
- this.request(playerId, ['sync', syncTo], callback);
352
- };
353
-
354
- /**
355
- * Unsync the current player.
356
- *
357
- * @param callback The function to call with the result
358
- */
359
-
360
- this.unSync = function (callback) {
361
- this.request(playerId, ['sync', '-'], callback);
362
- };
363
-
364
- /**
365
- * Move the playback of the current song to a specific point.
366
- *
367
- * @param seconds The time in the song to move to
368
- * @param callback The function to call with the result
369
- */
370
-
371
- this.seek = function (seconds, callback) {
372
- this.request(playerId, ['time', seconds], callback);
373
- };
374
-
375
- /**
376
- * Set the volume of the player.
377
- *
378
- * @param volume The volume to set to between 0 and 100
379
- * @param callback The function to call with the result
380
- */
381
-
382
- this.setVolume = function (volume, callback) {
383
- this.request(playerId, ['mixer', 'volume', volume], callback);
384
- };
385
-
386
- /**
387
- * Get the current volume of the player.
388
- *
389
- * @param callback The function to call with the result
390
- */
391
-
392
- this.getVolume = function (callback) {
393
- this.request(playerId, ['mixer', 'volume', '?'], function (reply) {
394
- if (reply.ok) {
395
- reply.result = reply.result._volume;
396
- }
397
- callback(reply);
398
- });
399
- };
400
-
401
- /**
402
- * Create and play a random list.
403
- *
404
- * @param target The type of list to generate, e.g. tracks, albums, contributors, year
405
- * @param callback The function to call with the result
406
- */
407
-
408
- this.randomPlay = function (target, callback) {
409
- this.request(playerId, ['randomplay', target], callback);
410
- };
411
-
412
- /**
413
- * Turn on or off the player.
414
- *
415
- * @param state 0 to turn the player off, 0 to turn it on
416
- * @param callback The function to call with the result
417
- */
418
-
419
- this.power = function (state, callback) {
420
- this.request(playerId, ['power', state ? '1' : '0'], callback);
421
- };
422
-
423
- /**
424
- * Play a favourite
425
- *
426
- * @param favorite The ID of the item to play
427
- * @param callback The function to call with the result
428
- */
429
-
430
- this.playFavorite = function (favorite, callback) {
431
- this.request(playerId, ['favorites', 'playlist', 'play', `item_id:${favorite}`], callback);
432
- };
433
-
434
- /**
435
- * Add an item to the playlist.
436
- *
437
- * @param item The item to add to the playlist
438
- * @param callback The function to call with the result
439
- */
440
-
441
- this.addToPlaylist = function (item, callback) {
442
- this.request(playerId, ['playlist', 'add', item], callback);
443
- };
444
-
445
- /**
446
- * Insert an item into the playlist to be played immediately.
447
- *
448
- * @param item The item to insert
449
- * @param callback The function to call with the result
450
- */
451
-
452
- this.insertToPlaylist = function (item, callback) {
453
- this.request(playerId, ['playlist', 'insert', item], callback);
454
- };
455
-
456
- /**
457
- * Set the shuffle state of the current playlist.
458
- *
459
- * @param state The state to set the list to, 0 no shuffle, 1 to shuffle
460
- * @param callback The function to call with the result
461
- */
462
-
463
- this.shuffle = function (state, callback) {
464
- this.request(playerId, ['playlist', 'shuffle', state ? '1' : '0'], callback);
465
- };
466
-
467
- /**
468
- * Function to set Linein mode on Squeezebox Boom
469
- *
470
- * @param callback The function to call with the result
471
- */
472
-
473
- this.setLinein = function (callback) {
474
- this.request(playerId, ['setlinein', 'linein'], callback);
475
- };
476
- }
477
-
478
- inherits(SqueezePlayer, SqueezeRequest);
479
-
480
- module.exports = SqueezePlayer;