lms-squeeze-rpc-x
Version:
A very basic API to interact with a Logitech Media Server via JSON-RPC
60 lines (59 loc) • 2.83 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SqueezePlayer = void 0;
class SqueezePlayer {
constructor(stub, playerInfo) {
this._stub = stub;
if (typeof (playerInfo) === "string") {
this._id = playerInfo;
}
else {
this._id = playerInfo.playerid;
}
}
getStatusAsync() {
return __awaiter(this, void 0, void 0, function* () {
let status = yield this._stub.requestAsync([this._id, ["status", "-", 1, "tags:cgABbehldiqtyrSuoKLNJ"]]);
if (!status) {
return undefined;
}
let cur_playlist_item;
if (status.playlist_cur_index != null && Array.isArray(status.playlist_loop)) {
status.playlist_loop.some((item) => {
if (+item["playlist index"] === +status.playlist_cur_index) {
cur_playlist_item = item;
return true;
}
});
}
return {
playerid: this._id,
name: status.player_name,
power: status.power == 1,
volume: status["mixer volume"],
playing: status.mode == "play",
repeat: status["playlist repeat"] == 1,
title: (cur_playlist_item === null || cur_playlist_item === void 0 ? void 0 : cur_playlist_item.title) || "",
album: (cur_playlist_item === null || cur_playlist_item === void 0 ? void 0 : cur_playlist_item.album) || "",
artist: (cur_playlist_item === null || cur_playlist_item === void 0 ? void 0 : cur_playlist_item.artist) || "",
duration: (cur_playlist_item === null || cur_playlist_item === void 0 ? void 0 : cur_playlist_item.duration) || 0,
time: status.time
};
});
}
setVolumeAsync(volume) {
return __awaiter(this, void 0, void 0, function* () {
yield this._stub.requestAsync([this._id, ["mixer", "volume", volume]]);
});
}
}
exports.SqueezePlayer = SqueezePlayer;