From e9980ee23d9a02a9067c57097d0fa1a9f8b69fac Mon Sep 17 00:00:00 2001 From: oweitman Date: Thu, 28 Nov 2024 00:41:53 +0100 Subject: [PATCH] - fix some missing objects errors - sanitize more playernames in syncgroups - add sendTo Command "cmdGeneral" --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++ lib/iosbserver.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/README.md b/README.md index cedbcd8..e459089 100644 --- a/README.md +++ b/README.md @@ -438,6 +438,48 @@ you must connect the button to the player widget. | Comma as separator | Advanced settings | A comma is used to separate the decimal places. | | Thousands separator | Advanced settings | For large numbers, a separator is inserted every 3 places. | +## SendTo-Befehle + +### cmdGeneral + +Mit diesem Befehl können beliebige Befehle an den LMS-Server gesendet werden, +um eine Rückmeldung zu erhalten. + +Beispiel: + +_Alle Playlists:_ + +```js +async function main() { + let data = await sendToAsync("squeezeboxrpc.0", "cdmGeneral", { + playerid: "", + cmdArray: ["playlists", "0", "999", "tags:us"], + }); + console.log(JSON.stringify(data)); +} +main(); +``` + +_Alle Favoriten:_ + +Dieser Befehl wird vom Adapter intern verwendet, um die Favoriten zu laden. + +```js +async function main() { + let data = await sendToAsync("squeezeboxrpc.0", "cdmGeneral", { + playerid: "", + cmdArray: ["favorites", "items", "0", "999", "want_url:1", "item_id:"], + }); + console.log(JSON.stringify(data)); +} +main(); +``` + +Weitere Möglichkeiten und Detailbeschreibung über die Parameter sind in +der folgenden CLI-Dokumentation enthalten: + +[CLI-Documentation](#further-api-documentation) + ## Todo - more testing/fixing @@ -471,6 +513,7 @@ you must connect the button to the player widget. - fix some missing objects errors - sanitize more playernames in syncgroups +- add sendTo Command "cmdGeneral" ### 1.4.0-alpha.4 (2024-11-26) diff --git a/lib/iosbserver.js b/lib/iosbserver.js index 0439ba0..b13bba8 100755 --- a/lib/iosbserver.js +++ b/lib/iosbserver.js @@ -245,6 +245,34 @@ function IoSbServer(adapter) { this.logdebug("send discoverlms"); this.discoverLMS(msg); } + if (msg.command === "cdmGeneral") { + this.logdebug("send cdmGeneral"); + this.sendCmdGeneral(msg); + } + }; + this.sendCmdGeneral = async (msg) => { + this.logdebug("sendCmdGeneral " + JSON.stringify(msg)); + let error = ""; + if (typeof msg.message === "object") { + let data; + const playerid = msg.message.playerid || ""; + const command = msg.message.cmdArray; + if (!Array.isArray(command)) { + error += "cmdArray is not an array"; + } + if (error == "") { + try { + data = await this.requestAsync(playerid, command); + } catch { + error = "Problem with Server request"; + } + } + if (msg.callback && error == "") { + this.adapter.sendTo(msg.from, msg.command, data, msg.callback); + } else { + this.adapter.sendTo(msg.from, msg.command, `error: ${error}`, msg.callback); + } + } }; this.sanitizePlayername = (playername) => playername.replace(this.FORBIDDEN_CHARS, "_"); this.discoverLMS = function (msg) { @@ -662,6 +690,28 @@ function IoSbServer(adapter) { } }.bind(this, callback)); }; + this.requestAsync = async (playerid, params) => { + this.logsilly("requestAsync"); + return new Promise((resolve, reject) => { + this.sbServer.request(playerid, params, (result) => { + if (result.ok) { + this.connected = 1; + this.errcnt = -1; + this.firstStart = false; + resolve(result); + } else { + if (this.firstStart) this.disconnect(); + if (this.errcnt == -1) this.errcnt = this.errmax; + this.errcnt--; + if (this.errcnt == 0) { + this.errcnt = -1; + this.disconnect(); + } + reject(); + } + }); + }); + }; this.disconnect = () => { this.logdebug("Server disconnect"); this.firstStart = false;