Skip to content

Commit

Permalink
- fix some missing objects errors
Browse files Browse the repository at this point in the history
- sanitize more playernames in syncgroups
- add sendTo Command "cmdGeneral"
  • Loading branch information
oweitman committed Nov 27, 2024
1 parent feeb469 commit e9980ee
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
50 changes: 50 additions & 0 deletions lib/iosbserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e9980ee

Please sign in to comment.